'Insufficient privileges' on plone python script - plone

I have this python script designed to rebuild the catalog for a particular content type, however when I visit it's url in the browser I get 'insufficient privileges' even when logged in as admin. How can I run something like this?
import plone.api
catalog = plone.api.portal.get_tool(name='portal_catalog') for brain in catalog(portal_type='Resource'):
obj = brain.getObject()
catalog.catalog_object(obj)

You don't need plone.api for this. Thus remove plone.api import and do:
catalog = context.portal_catalog

ScriptPython is restricted Python, that means that you can not import every Python module you want. That could the reason that you can't use plone.api in ScriptPython. But you can import getToolByName in that Script and get tools like the portal_catalog with it.
from Products.CMFCore.utils import getToolByName
catalog = getToolByName('portal_catalog')

If create your script in filesystem, you ca run.
bin/instace run your_script
But in your case, you don't need import plone.api
Plone in ZMI have many restrictions for import something.
See more informations about portal_catalog in official plone site
Documentation Query

Related

How do you import 'process' in Meteor?

Meteor currently advises to import everything. Like import Meteor from 'meteor/meteor';.
So if I want to do something like console.log(process.env.MONGO_URL), what should I import?
Bonus question: I can't find the documentation for process, where is it?
process is a global object (so no need for import) and only available on the server. It is part of the node environment.
See https://nodejs.org/docs/latest-v8.x/api/process.html

Bulk import tool for alfresco

I want to integrate the functionnality of Bulk import tool into my Java code Client CMIS using openCMIS library, is there any way to do so ? The goal is to do an import to alfresco automatically and without using the bulk import tool UI I found this code :
Streaming
UserTransaction txn = transactionService.getUserTransaction();
txn.begin();
AuthenticationUtil.setRunAsUser('admin');
StreamingNodeImporterFactory streamingNodeImporterFactory = (StreamingNodeImporterFactory)ctx.getBean('streamingNodeImporterFactory');
NodeImporter nodeImporter = streamingNodeImporterFactory.getNodeImporter(new File('importdirectory'));
BulkImportParameters bulkImportParameters = new BulkImportParameters();
bulkImportParameters.setTarget(folderNode);
bulkImportParameters.setReplaceExisting(true);
bulkImportParameters.setBatchSize(40);
bulkImportParameters.setNumThreads(4);
bulkImporter.bulkImport(bulkImportParameters, nodeImporter);
txn.commit();
But I didn't found any library that provides classes implemented in this code, so I can use them in my code.
If someone please can help me. Thanks a lot.
The code you are showing that invokes the Bulk File System Import Tool is running in the same process as Alfresco. It leverages the foundational Java API to make all of the calls.
You are asking about a client based on OpenCMIS. CMIS is a standard for working with all kinds of repositories. There is nothing in the spec or in the OpenCMIS implementation that knows anything about the Alfresco-specific Bulk File System Import Tool. Therefore, you cannot initiate a BFSIT import via CMIS.
To do imports, you can use the BFSIT or you can use CMIS, but combining the two does not make much sense.

Alfresco data export and import

we have to export alfresco data and import into another repository, and not necessarily backup/restore process. we are aiming for script which can be run and extract data on some conditions, set of files, with all its metedata.
i have got below link, which talks about same, but it is old , and things cant be done like versions of the file, condition based extract.
https://www.ibm.com/developerworks/cn/xml/x-cmis2/index.html
i would like to know any approaches available for extract and import of the alfresco data into other repositories..
There is nothing out-of-the-box that will do this. The replication sub-system is not suitable for frequent replication of more than a small handful of nodes.
So, you will have to write a custom solution or look at third-party solutions that can do this. Simflofy is one example. Another example is the Parashift Alfstream module.
If you would like to develop this yourself, I suggest you do something like:
Write code to export one or more files to the file system. This should be storage that is shared between the source and all target repositories.
Alongside each file, write a "manifest" file that descries the file's metadata, including custom properties and property values. You should use the same format that the Bulk File System Import Tool expects when doing an import.
Add a message to a queue that describes where the exported data is sitting and where it needs to be imported.
In the target repository, write a listener that is subscribe to the queue.
When the listener gets a message it can initiate a Bulk File System Import in the target system. The BFSIT will import the files and set the metadata as described in the manifest file you generated in Step 2.
Optionally, the target system can place another message on the queue acknowledging that the import has been performed, which the source repo can then pick up to complete the task.
Some people have been successful using Apache Camel for this, but it is not strictly necessary.

Export everything from Alfresco

I need to export everything (sites, dashboard, users, groups ecc...) is under my Alfresco ed import all to another Alfresco installation.
I discovered this usefull tool https://github.com/atolcd/alfresco-share-import-export but seems to me that it is good to create an .acp of a site for example but it's not enought for others stuff expecially users.
Please, what's an easy way to export everything from Alfresco ? And then how to import ? Thank you.
I used this Pynthon scripts github.com/wabson/share-import-export but no way an error on the python script execution : C:\Users\xxx\Desktop\Nuova cartella>python export-users.py file.json --username=xxx --password=xxx --url=localhost:8080/share/page/site/xxx/dashboard File "export-users.py", line 5 ^ SyntaxError: invalid syntax
I have Alfresco 5.1 and Pynthon 2.7.12
screenshot
Your url param is incorrect. Use the below one.
python export-users.py file.json --username=admin --password=admin --url=http://localhost:8080/share
This should work for you.
The Share URL should be, http://<IP or systemname>:<portnumber/share, but you've mentioned the one site dashboard url. Please change that.
You can also use alfresco OOTB replication service and replicate all the data from one alfresco instance to second one.

import com.google.android.gms.ads.reward cannot be resolved

I am trying to deploy in my App the RewardedVideoAd of Admob, but when I put the import of the library I get this error:
import com.google.android.gms.ads.reward cannot be resolved
Someone knows why this happen?
It took 5 days to get it. I did receive no answer from here... but thinking in all those people that will face this problem in the future, I want to say my solution, and this is: create a complete new project from a .metada from 0, and import the new version of google play service lib (very easy to get here in stackOverflow) , import it. If you have a facebook project, remove it, and import from 0 as well. When you have finished to import all your libraries, create a new project, the yours, and copy, file per file, everything. This will work for sure.

Resources