I have an aspect with name "alfrescoDocs:uploadedfrom" and it has single property with name "alfrescoDocs:uploadSource". I am using alfresco-opencmis-extension to attached this aspect with document on creation and set some value in its property. I am using code below.
Map<String, Object> properties = new HashMap<String, Object>();
properties.put(PropertyIds.NAME, "test12");
properties.put(PropertyIds.OBJECT_TYPE_ID, "cmis:document,P:cm:titled,P:alfrescoDocs:uploadedfrom");
properties.put("cmis:description", "AliNawab");
properties.put("alfrescoDocs:uploadSource", "SugarCRM");
Document doc = session.getRootFolder().createDocument(properties, null, null);
This code successfully attaches the aspect with newly created document. But the value of property "alfrescoDocs:uploadSource" is not updating.
I am using: http://localhost:8080/alfresco/api/-default-/public/cmis/versions/1.1/atom url for connection.
Also I need to do exactly the same in php.
It worked for me when I used http://localhost:8080/alfresco/api/-default-/public/cmis/versions/1.0/atom.
seems
http://localhost:8080/alfresco/api/-default-/public/cmis/versions/1.1/atom has some changes around aspect props.
Related
I am trying to add the secondary properties (title,description) programmatically to a document in Alfresco using CMIS 1.1.
code snippet:
properties.put(PropertyIds.NAME, fileName);
properties.put(PropertyIds.OBJECT_TYPE_ID, "cmis:document,P:cm:titled");
properties.put(PropertyIds.SECONDARY_OBJECT_TYPE_IDS, "P:cm:titled");
properties.put("cm:title", "test title");
properties.put("cm:description", "description of document");
The code results in successful upload of the document to the Alfresco site without any issues,but the title and description are empty in Alfresco UI.
I also tried setting the tags to a document as well. Tags were also empty in alfresco site.
The code snippet
document = parentFolder.createDocument(properties, contentStream, null);
AlfrescoDocument alfDoc = (AlfrescoDocument) document;
Map<String, Object> properties1 = new HashMap<String, Object>();
List<String> tags = new ArrayList<String>();
tags.add("cmisTag");
tags.add("testTag");
properties1.put("cm:taggable",tags);
alfDoc.updateProperties(properties1);
On first look I thought it might be that you are setting your secondary object type IDs property to a single value instead of an array, but then I looked at my gist on this and I am also using a String instead of an array of Strings.
Now I notice that you are using AlfrescoDocument which means you are using the OpenCMIS Extension. If you are using CMIS 1.1 you do NOT want to use the OpenCMIS extension. Just use the regular OpenCMIS library without it. Use Document instead of AlfrescoDocument.
Using Alfresco 5.0 community edition.
When trying to deploy the custom model provided in the answer to another question,
but using the dynamic deployment approach as specified at [http://docs.alfresco.com/5.0/tasks/deploy-dynamic.html]
Although the GUI says the model is "activated", I get the following WARN in the alfresco.log:
21:24:30,587 WARN [org.alfresco.repo.dictionary.DictionaryDAO] [ajp-apr-8009-exec-4]
org.alfresco.service.cmr.dictionary.DictionaryException:
00140008 Model '{custom.model}custommodel' does not exist
When I try to use it with CMIS 1.1, I'm getting an error back from the web service:
Type 'P:cmod:customDoc' is unknown!
Here is the relevant bit of the code which uses opencmis java api:
Map<String, Object> props = new HashMap<String, Object>();
props.put("cmis:objectTypeId", "cmis:document");
props.put("cmis:secondaryObjectTypeIds", Arrays.asList(new String[] {"P:cm:titled", "P:cmod:customDoc"}));
props.put("cmis:name", "myName");
props.put("cmod:property1", "value1");
ObjectId id = folder.createDocument(props, contentStream, VersioningState.MAJOR);
Am I specifying the namespace and aspect correctly (P:cmod:customDoc)? I've also tried cmod:aspectBase and other combinations, getting the same error.
My goal is to make a simple model where I can add a few extra fields to document objects (extending the default ContentModel).
It seems the warning is just that, it can be ignored.
But using CMIS 1.1, I have to do two steps to add in the extra properties from the custom aspect. (Trying to do it in one step gives the error "Type 'P:cmod:customDoc' is unknown!")
First createDocument() with the cmis:secondaryObjectTypeIds including the custom namespace, BUT don't add any custom properties.
Second, add the custom properties to the resulting document, and then updateProperties(). This will add in the custom property values to the document.
Map<String, Object> props = new HashMap<String, Object>();
props.put("cmis:objectTypeId", "cmis:document");
props.put("cmis:secondaryObjectTypeIds",
Arrays.asList(new String[] {"P:cm:titled", "P:cmod:customDoc"}));
props.put("cmis:name", "myName");
Document document = folder.createDocument(props, contentStream, VersioningState.MAJOR);
props = new HashMap<String, Object>();
props.put("cmod:property1", "value1"); //here is where you add the custom properties
document = (Document) document.updateProperties(properties);
(note: you need to reassign the document from the updateProperties result, otherwise it will be missing some information, such as parents)
I was experimenting with 'datastore' on my machine. Using this code.
Key parentKey = KeyFactory.createKey("parent", "parentId");
try {
// Entity parent = new Entity("parent", "parentId");
// parent.setUnindexedProperty("property1", "value1");
// ds.put(parent);
Entity savedParent = ds.get(parentKey);
// savedParent.setUnindexedProperty("property1", "value3");
// ds.put(savedParent);
// Entity child = new Entity("child", "childId", savedParent.getKey());
Entity child = ds.get(KeyFactory.createKey(savedParent.getKey(), "child", "childId"));
child.setUnindexedProperty("property1", "val2");
ds.put(child);
// logger.info("Saved child.");
} catch (EntityNotFoundException e) {
throw new RuntimeException(e);
}
First I saved parent entity and set property on it to "value2" then I added a child entity with property val1. Then I updated parent property to value3. Then I updated property on child to val2.
Then I found out in the admin console, that value of the property on the parent is back to value2. I repeated it again with the same result. Am I missing something? Or is this some kind of bug?
I suppose, this is manifestation of eventual consistency, right? I run each step in a new JVM instance, thinking that values must have been stored at the time I switched it off:-. Contradicting common sense, but correct in terms of emulation of eventual consistency....
I am creating a new item using the Core Service in this post. However, the URI of the newly created item is tcm:0-0-0 instead of the actual TCM URI. the Title property is correct (and not New Component) but the WebDav path returns 'New Component' while .
What is the best way to get the URI of my newly created item?
client.Create(newComponent, null);
string newItemUri = newComponent.Id; // returns tcm:0-0-0
string webDavUrl = newComponent.LocationInfo.WebDavUrl; // returns New%20Component
string title = newComponent.Title; // correct
Second parameter of Create method are ReadOptions. They are used to specify how the item will be read back. In your example you have it set to null, meaning you will not read it back. What you should do is set ReadOptions and assign item read back to a variable, like this:
newComponent = (ComponentData) client.Create(newComponent, new ReadOptions());
Check out Ryan's code at http://blog.building-blocks.com/uploading-images-using-the-core-service-in-sdl-tridion-2011. He uses client.Save to get the saved Component, from which he's able to access the ID.
I have a script that parses some complex XML. When the XML element is of a certain type, it generates a comboBox using the XML element's children to populate the box. I then want to check all of the values of the all the generated ComboBoxes against their correct answers (which is also info stored in the XML file). When creating the ComboBoxes, I added an "id" property. However, it seems that I cannot them use:
dynamicQuestion.id.selectedItem.labelField
to check the answers. However, I am able to get the labelField if I know the variable name used to create the ComboBox.
dynamicQuestion.selectedItem.labelField
This indicates (to me) that I need to dynamically generate the variable name as I'm creating new instances of the ComboBox. But how do I dynamically generate a variable name? If I use
var thisBox:String = "box"+boxCount;
var newBox:ComboBox = thisBox as ComboBox;
I get an implicit coercion error. I also tried changing the creation statement to a function that accepted an argument, "thisBox," but this didn't work either. Conceptually, this seems quite simple, but I'm having a hard time putting it to practice. It seems that the comboBox's id is what is generated by created the box using script (e.g., var thisBox). How do I dynamically generate this name?
Use an array as Stefan suggested. If you must use string identifiers, you can create an object and use it as an associative array.
var combos:Object = {};
var boxCount:Number = 1;
var thisBox:String = "box"+boxCount;
//you can store comboboxes in the object using the following syntax
combos[thisBox] = new ComboBox();
//or
combos.box2 = new ComboBox();
//or
combos["box3"] = new ComboBox();
trace(combos.box1.selectedItem.labelField);
trace(combos.box2.selectedItem.labelField);
trace(combos.box3.selectedItem.labelField);
Why don't you store all your dynamically created combo boxes in an array? When you want to evaluate them you iterate over the array and access selectedItem.labelField.