How to delete a record from a dictionary? - alfresco

I have an invalid dictionary in Alfresco database, I need to delete some records from that dictionary. How to do that programmatically? Manually?
Thank you!
(this was custom dictionary which was filled up from the file programmatically, now it is one of Alfresco's nodes )

I agree with Gagravarr that you can just delete the nodes you no longer want.
If you want to remove the content model from the data dictionary, you'll need to first delete all of the nodes that are instances of types that are in the model and remove any aspects defined in the model from existing nodes, then you can remove the content model from your system.
A good way to find nodes that are instances of a certain type is to use the node browser and the TYPE:"sc:someType" syntax. Similarly, you can use ASPECT:"sc:someAspect" to find nodes that have a certain aspect applied.
Hopefully, your custom content model was added and packaged in an AMP. If so, you just need to find the model XML file and delete it, then delete the reference from the model context file. Then, you can re-package the AMP and deploy it to your system.
In an Alfresco SDK project structure, the model is typically in a directory like some-project/some-project-platform-jar/src/main/resources/alfresco/module/some-project-platform-jar/model/content-model.xml.
The model context file is usually something like: some-project/some-project-platform-jar/src/main/resources/alfresco/module/some-project-platform-jar/context/bootstrap-context.xml.

Related

What happens when 2 content models in Alfresco overlap?

When trying to update a Custom Content Model in Alfresco I decided to upload and activate a new copy and delete the old one. I found out this doesn't work.
So my question is what will happen now and how can I fix this?
What will happen where the two content models are the same?
What will happen where the two content models define the same aspect, but differently?
Does one take precedent over the other?
Would editing the 2 in the properties to be identical get around the problem?
Starting from scratch with this repository is an undesirable option at this time. I'm looking for the simplest solution possible.
It's not simple as that. If you already have some documents or folder associated with a model, you can't delete it without breaking your datas.
Also, Alfresco doesn't support multiple declarations of a model or type or aspect. If it's the case it doesn't start.
The only way you have to upload a new version of your model is by uploading a version containing ONLY added properties, types or aspects. If your new model's version contains modificated or deleted properties, types or aspects, you will have to migrate each node programaticaly.

How to transfer a structure from one Plone to another

I have a Plone instance which contains some structures which I need to copy to a new Plone instance (but much more which should not be copied). Those structures are document trees ("books" of Archetypes folders and documents) which use resources (e.g. images and animations, by UID) outside those trees (in a separate structure which of course contains lots of resources not needed by the ones which need to be copied).
I tried already to copy the whole data and delete the unneeded parts, but this takes very (!) long, so I'm looking for a better way.
Thus, the idea is to traverse my little forest of document trees and transfer them and the resources they need (sparsely rebuilding that separate structure) to the new Plone instance. I have full access to both of them.
Is there a suggested way to accomplish this? Or should I export all of them, including the resources structure, and delete all unneeded stuff afterwards?
I found out that each time that I make this type of migration by hand, I make mistakes that force me to do it again.
OTOH, if migration is automated, I can run it, find out what I did wrong, fix the migration, and do it all over again until I am satisfied.
In this context, to automate your migration, I advise you to look at collective.transmogrifrier.
I recommend jsonmigrator - which is a twist on collective.transmogrifier mentioned by Godefroid. See my blog on it here
You can even use it to migrate from Archetypes to Dexterity types (you just need matching fieldnames (and matching types roughly speaking).
Trying to select the resources to import will be tricky though. Perhaps you can find a way to iterate through your document trees & "touch" (in a unix sense) any resource that you are using. Then copy across only resources whose "timestamp" indicates that they have been touched.

JGit bare commit / tree construction

I'm trying to commit a single blob directly to a repository using jgit. I know how to insert the blob and get its sha1, however I'm having difficulties constructing a tree for this scenario. I can't seem to figure out how to correctly use jgit's tree abstractions (TreeWalk and the like) to recursively construct a tree, almost identical to the previous commits', with only different parent trees of the blob.
What is the idiomatic way to do this in JGit?
The reason I ask, is because I'm writing a program that's a kind of editor for documents living in git repositories. In my case, the whole point of using git is to be able to have multiple versions of the documents (aka branches) at the same time. Since it's an editor I have to be able to commit changes, however since I want to see multiple versions of the document at the same time, checking out, modifying a file and committing using JGit porcelain API is not possible, it has to work directly with git objects.
The low-level API you can use for this is TreeFormatter together with CommitBuilder.
An example of using this can be seen here. In this case, it constructs one new tree object with multiple subtrees.
In your case, you probably have to recursively walk the tree and create the new tree objects on the path to the changed file and insert them bottom up. For the rest of the tree, you can use the existing tree IDs and don't have to descend into them. I recommend looking into TreeWalk#setRecursive and TreeWalk#setPostOrderTraversal.
Another option would be to create an in-core DirCache, fill it with DirCacheEntries from the commit and your updated entry, and then call DirCache#writeTree.

Alfresco nested collections

Is it possible to have nested collections within Alfresco? I'm on Community Edition 3.4. I'd like to have a collection that contains other collections.
Is there something I need to do while defining the collection in the content model XML?
tl;dr: it's not supported out of the box
The data list model defines dl:dataListItem as a child type of cm:content, therefore you can't nest data lists the same way you nest documents into folders.
What you could do is to create a custom peer association between data lists, in order to create your own nesting logic. This would require refactoring the Share UI components that handle list to let them get knowledge of such a custom model, and show nested lists appropriately.
What you could do is define your own custom constraint.
Instead of using the predefined LIST constraint, you could refer to a Java class.
Here is a link to the Wiki
So you could define a nested collection. But to present this in either Explorer or Share, you'd have to write new renderers/generators(explorer) or new share template for that specific field.

Creating Drupal CCK content programmatically/ via API

I am working with a Drupal 6.x system to create exercise / personal training programmes, and am using the CCK with content types of Exercise and Programme, where Programme contains a few header fields and a list of node references to the exercises it consists of. This works great and I can manually create programmes which work fine. I now wish to create a module which can generate these programs automatically based on a number of algorithms I have developed, the process will look like:
Load all exercises into array
Load users personal info (entered previously)
Establish best suited exercises
Create new programme content type
Save programme
An Exercise has a number of related attributes and although I could do all of the above using SQL directly into the tables it would be quite complex and doesn't feel right. I would like in step 1 to load the exercises as an array of Exercise objects (node_load?), and then create a programme object and save. Is this OO type approach possible or do I have to resort to manipulating the data directly?
The best way to tackle this problem would be to write your own module to do this.
Step 1 you can do node_load($nid) on all the excercies
Step 2 you can use user_load($uid)
Step 3 you'll need to iterate through the user object and match up to the appropriate excercies.
Step 4/5 I'd create a new $node = stdClass(); object and populate the attributes with the correct data then perfrom a node_save($node); this will assign it a $node->id etc.
If your unsure on what attributes are in your training program node, then do a print_r($node); on one you've created already.
Phil
Drupal doesn't provide any "cascading" save mechanism to save a hierarchy of nodes in one swoop. You'll need to build each node in code and call node_save() on it explicitly as described by Phil Carter.
The Node Export module can generate sample code for creating a node (complete with CCK fields) programatically.
There are a ton of modules that try to do the import thing right. Take a look at a comparison of them http://groups.drupal.org/node/21338
If you need strategies or examples of importing stuff into nodes, those are a great resource.
I don't think "creating" these programs is even necessary.
Why not just display a list of exercises that match your requirements and share 'characteristics' with the user.
I'd accomplish this by making the 'characteristics' be taxonomy. Then attached to users either with a profile, or taxonomy flag. Then display a list (perhaps even a view at first) and those with the same characteristic tags within exercises.
This would be dynamic and user specific and note require pre-loading a bunch of programmes.
A thought.

Resources