How to delete generated bitstreams in DSpace 6x? - postgresql

I would like to delete all the bitstreams generated by filter-media but only with a specific description "IM Thumbnail".
I am aware that I can just regenerate the thumbnail by using the -f flag to force it to regenerate the thumbnail. I am testing some settings in my setup and I would just like to delete the generated thumbnails with this specific description first.
I've tried tinkering the database via PgAdmin but I can only go as far as selecting the bitstreams. I don't even know how to group or order the returned results and not really sure if I've selected the correct tables.
SELECT
*
FROM
public.bitstream,
public.bundle,
public.bundle2bitstream,
public.metadatavalue,
public.item2bundle
WHERE
bitstream.uuid = metadatavalue.dspace_object_id AND
bitstream.uuid = bundle2bitstream.bitstream_id AND
bundle.uuid = item2bundle.bundle_id AND
bundle2bitstream.bundle_id = bundle.uuid AND
metadatavalue.text_value = 'IM Thumbnail';
Any advice on how to do this via database manipulation or any other means would be greatly appreciated. Applying the SQL deletion within a specific community or collection would be a really nice bonus too!
Thanks in advance!

Although the question was tagged with postgresql, I found the answer from DSpace Community Mailing List using Jython. Thanks for Joan Caparros for the original code. The message thread can be found here: Removing Thumbnails in DSpace 5. I also posted a similar query in the DSpace Technical Support Mailing List which can be found here: Batch delete bitstreams in the Bundle: THUMBNAIL where Joan posted a modified version of his code for my specific needs which is deleting only the thumbnails if it contains the description "IM Thumbnail". Below is the full code that achieved my goals:
from org.dspace.curate import ScriptedTask
from org.dspace.curate import Curator
from org.dspace.content.service import DSpaceObjectService
from org.dspace.content.factory import ContentServiceFactory
#from org.dspace.content.service import BitstreamService
class Main(ScriptedTask):
def init(self, curator, taskName):
print "initializing with Jython"
def performDso(self, dso):
#print "perform on dso "
if dso.getType()==2:
print "Item '" + dso.getName() + "' ("+dso.getHandle()+")"
myBundles = dso.itemService.getBundles(dso,"THUMBNAIL")
totalbundles = len(myBundles)
for i in myBundles:
myBitstreams = i.getBitstreams()
total = len(myBitstreams)
if len(myBitstreams)==0:
print "- DELETING EMPTY BUNDLE"
dso.itemService.removeBundle(Curator.curationContext(),dso,myBundles[0])
if len(myBitstreams)>0:
for k in range(0,len(myBitstreams)):
if myBitstreams[k].getDescription() == 'IM Thumbnail':
print "DELETE "+myBitstreams[0].getDescription()
bitstreamService = ContentServiceFactory.getInstance().getBitstreamService()
bitstreamService.delete(Curator.curationContext(),myBitstreams[0])
print "- DELETING BUNDLE"
dso.itemService.removeBundle(Curator.curationContext(),dso,myBundles[0])
return 0
def performId(self, context, id):
print "perform on id %s" % (id)
return 0
Please note that the code above was made as a curation task using Jython so the documentation on how to set up and use can be found here: Curation tasks in Jython.

Related

i want to mass follow twitter accounts but i got error that said i've requested to follow

So i want to mass follow people on Twitter with my account
but im kinda confused because i don't know how to fix the error, like i've requested to follow the "user", so what i want to do is skip the user if ive requested to follow them, but i dont know how to fix it, here's the code
`
following = api.get_friend_ids(screen_name = "2Wild2Crazy")
friends = api.get_friends(screen_name = "2Wild2Crazy", count = 200)
for i in range(len(friends)):
print(""" " """, friends[i].screen_name, """ " """)
#mass follow the people who follow 2Wild2Crazy
for i in range(len(friends)):
api.create_friendship(screen_name = friends[i].screen_name)
`
Just do
#mass follow the people who follow 2Wild2Crazy
for i in range(len(friends)):
try:
api.create_friendship(screen_name = friends[i].screen_name)
except tweepy.errors.Forbidden:
print("Already following user: {}, skipping.".format(friends[i].screen_name))
Might have to import tweepy to be able to except the error. If you don't like the print command you can replace it with pass that will tell python to just ignore that specific error.

How to install GSDML file via Siemens TIA openness API into TIA project?

Updating with very useful info using guidance from mrsargent
I am trying to automate following steps in C# (Visual Studio) with following steps:
run and connect to TIA portal
create project
install GSDML device files
add PLC and single device as per GSDML
design application relationship between product and PLC (cpu)
I tried to use OpenNess Demo Application for the same but I am unable to step through the code and there is no option in the Demo GUI to install GSDML files in the same.
I tried to write the following code as per documentation for CAX import of GSDML file but faced errors as described below:
Code:
using
(TiaPortal tiaPortal = new TiaPortal(TiaPortalMode.WithoutUserInterface))
{
Console.WriteLine("TIA Portal has started");
ProjectComposition projects = tiaPortal.Projects;
Console.WriteLine("Opening Project...");
DirectoryInfo dinfo = new DirectoryInfo(#"C:\projects\TestProjects\");
string unixTimestamp = Convert.ToString((int)DateTime.Now.Subtract(new DateTime(1970, 1, 1)).TotalSeconds);
string prj_name = "Prj_" + unixTimestamp;
Project project = null;
try
{
project = projects.Create(dinfo, prj_name);
}
catch (Exception)
{
Console.WriteLine(String.Format("Could not open project {0}", projectPath.FullName));
Console.WriteLine("Demo complete hit enter to exit");
Console.ReadLine();
return;
}
CaxProvider caxProvider = project.GetService<CaxProvider>();
if (caxProvider != null)
{
// GETTING ERROR OVER HERE
// {"Error when calling method 'Import' of type 'Siemens.Engineering.Cax.CaxProvider'.\r\n\r\nThe path of the import file 'C:\\Gaurav\\GSDML-xxxxxxxx.xml' with the extension '.xml' is invalid.\r\n"}
caxProvider.Import(
new FileInfo(#"C:\GSDML-xxxx.xml"),
new FileInfo(#"C:\ProjectImport_Log.log"),
CaxImportOptions.MoveToParkingLot
);
}
Console.WriteLine(String.Format("Project {0} is open", project.Path.FullName));
// IterateThroughDevices(project);
project.Close();
Console.WriteLine("Demo complete hit enter to exit");
Console.ReadLine();
}
Following error is observed:
{"Error when calling method 'Import' of type 'Siemens.Engineering.Cax.CaxProvider'.\r\n\r\nThe path of the import file 'C:\GSDML-xxx.xml' with the extension '.xml' is invalid.\r\n"}
Yes this is a difficult thing to do. However it is possible. First you need proper documentation that is a little difficult to find. The manual is very detailed and good found here
You need the import the GSD file as a CAx that is found page 939 of the documentation.
//Access the CaxProvider service
Project project = tiaPortal.Projects.Open(...);
CaxProvider caxProvider = project.GetService<CaxProvider>();
if(caxProvider != null)
{
// Perform Cax export and import operation
}
To create this CAx (an xml document) you need to look starting at page 988 of this manual. It will tell you how to configure. It is far too much to explain and list in this forum but the documentation does a good job of explaining after you read it 5 times ;)
It is probably best to read this entire import/export section in order to get a full understanding of how to do this. Hope this helps!

github3.py doesn't return file content for gist

I use github3.py library in order to create and update Gist on github.com
I can access an existing gist and get all information except content of the file:
for g in gh.iter_gists():
if g.id == content[0]:
f = g.iter_files().next()
print g.files #1
print f.raw_url
old_content = f.content #Returns None
Any hint why does it return None in the last line?
It looks as though GitHub's API no longer returns the contents of the gist file as part of the response:
{u'size': 12, u'raw_url': u'https://gist.githubusercontent.com/testgh3/eb911d34ec732e4b7f24/raw/e041e7dc6236db21062c11b2929a72e656bbc40e/fileA.txt', u'type': u'text/plain', u'language': u'Text', u'filename': u'fileA.txt'}
This means that github3.py needs to add functionality to the GistFile class that you're trying to use here. (I've already created an issue for this. If you'd like to help do the work, I'm happy to help you with that and I'd love to merge a pull request with this functionality.)

GreenDAO really simple query

I want to create a very simple query to look up a sqlite db using greendao. 2 fields, one is the ID and the other 'affirmation'.
i am sorry to be such a beginner, but i am not sure how to use greendao including what to import etc.. All i have been able to do so far is add the greendao libraries but i cant find a good tutorial to just do a query. Basically i want it to be a random ID that calls up a random affirmation and return it to my main activity.. Once again i am sorry but i am really trying and getting nowhere..
Greendao is a ORM-framework. If you don't know what this means you should look up this first.
Greendao generally works as follows:
You create a java-project that generates your sourcecode for your real app. You have to include DaoCore and DaoGenerator in this project.
You add the generated sourcecode to your android-project and include DaoCore in it. DaoGemerator is not neccessary.
For examples how to generate the code and define your entities the greendao-website is a good place to go.
According to your description you need an entity with id-property and a string-property (affirmation).
In your android-project you then use the DevOpenHelper to get a session and from the session you can get the dao (Data Access Object) for your entity. The dao includes the very basic query to load data by id (load ()).
Please notice that the DevOpenHelper is only meant for development process. For your final release you should extend OpenHelper and costumize your actions to be taken on DB-schema update.
Here is some example code I have in my application.
DaoHelper.getInstance().getDaoSession().clear();
OperationDao dao = DaoHelper.getInstance().getDaoSession().getOperationDao();
String userId = "some id"
WhereCondition wc1 = new WhereCondition.PropertyCondition(OperationDao.Properties.UserId,
" = " + userId);
WhereCondition wc2 = new WhereCondition.PropertyCondition(OperationDao.Properties.Priority,
" > " + 4);
// Uncached is important if your data may have changed recently.
List<Operation> answer = dao.queryBuilder().where(wc1, wc2).listLazyUncached();
This is a decent tutorial on how to learn greendao. Make sure you follow the links to the further parts.
You can use:
daoMaster = new DaoMaster(db);
daoSession = daoMaster.newSession();
yourDao = daoSession.getYourDao();
Random() random = new Random();
List<YourObject> objects = yourDao.loadAll();
YourObject yourObject = objects.get(random.nextInt(objects.size());

Problem importing ZEXP files programmatically

I'm developing a Plone Product that needs to import objects programmatically previously exported to ZEXP files. It's working perfectly, except the navigation bar. When one object is imported, it does so correctly, but the navication bar is not updated. The object can be accessed through it's URL and it's parent container contents tab.
Bellow is the code I used to import the objects. It's based on zope's ObjectManager._importObjectFromFile implementation.
def importDocument( app, fileName, container ):
app._p_jar.sync()
owner = 1
connection = container._p_jar
ob = connection.importFile( config.REMOTE_DIR + fileName, customImporters={ magic: importXML, } )
id = ob.id
if hasattr(id, 'im_func'): id = id()
try:
container._setObject( id, ob, set_owner = owner, suppress_events=False )
except AttributeError:
print "AttributeError"
# Try to make ownership implicit if possible in the context
# that the object was imported into
ob = container._getOb( id )
ob.manage_changeOwnershipType( explicit = 0 )
transaction.commit()
return True
I've noticed that the _setObject implementation fires an ObjectAddedEvent event in it's code, and it's after that event that the menu gets updated when I use the ZMI interface to import an object, so I figure something is listening to this event and handling the menu, but oddly, it doesn't happen when using my code.
Generally speaking, importing zexp objects is not supported (in part due to cases like this where unexpected or unintended results may occur). If it works, great. If it doesn't, you are "on your own" and probably better off copying the Data.fs file to a new software stack.
That said, I'm not sure I understand why clear and rebuild the catalog (ZMI -> portal_catalog -> tab 'advance' -> 'clear & rebuild') is not the answer here. According to its description its job is to "walk the entire portal looking for content objects which should be indexed in the catalog and index them".
Unless I misunderstand, you've just described a situation where newly imported content "should be indexed" because it hasn't been indexed yet.
If you are worried about the length of time required to clear and rebuild, try running it from the command line with something like this:
http://svn.plone.org/svn/plone/plone.org/Products.PloneOrg/trunk/scripts/catalog_rebuild.py
If you are worried about crawling the whole site, then call indexObject() on each object (http://dev.plone.org/plone/browser/plone.org/Products.PloneOrg/trunk/scripts/catalog_rebuild.py#L109)
Maybe try manually rebuilding the whole catalog after the import is complete? It might give you more hints to what is wrong ...
ZMI -> portal_catalog -> tab 'advance' -> 'clear & rebuild'.
You may need to "publish" the object after import to make it visible.
Use the manage_importObject method instead.