Alfresco error: Model '{custom.model}custommodel' does not exist - alfresco

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)

Related

Issues in setting secondary properties to a document using cmis 1.1

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.

getting CmisInvalidArgumentException: Extensions tree too wide! while using apache chemistry opencmis

I am a newbie to Apache Chemistry openCMIS.
I am trying to pull a PDF document from the Alfresco repository using its Id.
The id is something similar to workspace://SpacesStore/b91dc42c-1644-4246-b3x9-bxx6f0be4wf3
CmisObject object = getSession().getObject(Id);
I am getting the below exception while execute the above line.
org.apache.chemistry.opencmis.commons.exceptions.CmisConnectionException: Parsing exception!
The Exception object does not contain the stackTrace and it contains the cause as below.
org.apache.chemistry.opencmis.commons.exceptions.CmisInvalidArgumentException: Extensions tree too wide!
But, I dont understand what I am missing. I have another drupal application, that pulls the same PDF without any issue. But this issue happens when I do it thru my java program.
Can anyone please help me out find what I am doing wrong?
UPDATE (ATTACHING THE CODE)
SessionFactory sessionFactory = SessionFactoryImpl.newInstance();
Map<String, String> parameter = new HashMap<String, String>();
parameter.put(SessionParameter.USER, "admin");
parameter.put(SessionParameter.PASSWORD, "admin");
parameter.put(SessionParameter.ATOMPUB_URL, "http://192.168.64.130:8080/alfresco/service/cmis");
parameter.put(SessionParameter.BINDING_TYPE, BindingType.ATOMPUB.value());
parameter.put(SessionParameter.LOCALE_ISO3166_COUNTRY, "us");
parameter.put(SessionParameter.LOCALE_ISO639_LANGUAGE, "en");
parameter.put(SessionParameter.LOCALE_VARIANT, "");
Repository soleRepository = (Repository)sessionFactory.getRepositories(parameter).get(0);
Session session = soleRepository.createSession();
String Id = "workspace://SpacesStore/c271a8b1-9fe6-4c43-8b9d-c09935248d18";
CmisObject object = session.getObject(Id);
System.out.println(object);
Look at the following discussion: jeff potts on alfresco forum

unable to update properties of aspect using alfresco-opencmis-extension

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.

XML validation error when updating Keyword metadata

Following on from my earlier question about creating Address Books (many thanks Peter!), I have a small throw-away console application doing just that and working great - but in addition I'm trying to update the metadata of a Keyword with the Item Id of the created Address Book.
Slightly shortened snippet ...
StaticAddressBook ab = new StaticAddressBook();
ab.Title = title;
ab.Key = key;
ab.Save();
// id is a correct Keyword TCM ID
Keyword k = tdse.GetObject(id, EnumOpenMode.OpenModeEdit);
if (k != null)
{
k.MetadataFields["addressbookid"].value[0] = ab.Id.ItemId;
k.Save(true);
}
I keep getting the following error on Save():
XML validation error. Reason: The element 'Metadata' in namespace
'uuid:2065d525-a365-4b45-b68e-bf45f0fba188' has invalid child element
'addressbookid' in namespace
'uuid:2065d525-a365-4b45-b68e-bf45f0fba188'. List of possible elements
expected: 'contact_us_email' in namespace
'uuid:2065d525-a365-4b45-b68e-bf45f0fba188'
But I know the Keyword has the correct Metadata assigned, (thats why I don't bother checking!). Shortened Tridion XML from a current keyword in question:
<tcm:Keyword>
<tcm:Data>
<tcm:MetadataSchemaxlink:type="simple"xlink:title="IP.Location.Metadata" xlink:href="tcm:49-2142-8" />
<tcm:Metadata>
<Metadata xmlns="uuid:2065d525-a365-4b45-b68e-bf45f0fba188">
<email>...</email>
<addressbookid>3</addressbookid>
<contact_us_email>...</contact_us_email>
<request_a_sample_email>...</request_a_sample_email>
<webinar_feedback_email>....</webinar_feedback_email>
</Metadata>
</tcm:Metadata>
<tcm:IsRoot>true</tcm:IsRoot>
</tcm:Data>
</tcm:Keyword>
Have I missed something can Keyword metadata not be updated in this way?
I guess I could look at the Core Service to update Keywords, but it seemed to to make sense to do everything within this application.
UPDATE
Order was key here, strangely!
The following code works:
ItemFields fields = k.MetadataFields;
System.Diagnostics.Debug.WriteLine(fields.Count);
string email = fields[1].value[1];
string contact = fields[3].value[1];
string request = fields[4].value[1];
string webinar = fields[5].value[1];
fields[1].value[1] = email;
fields[2].value[1] = ab.Id.ItemId;
fields[3].value[1] = contact;
fields[4].value[1] = request;
fields[5].value[1] = webinar;
k.Save(true);
Got caught out by the non-0-based index when getting/setting values and had to reassign existing fields back, in order.
Cheers
It seems that the order of the fields has changed in the Schema since that Component was created. At least the Schema expects contact_us_email in the position where you current have addressbookid.
There may be other changes, so I'd verify the order of fields in the Schema and make sure the Component(s) match, before you run your tool.

"Unexpected list type" exception when invoking ISessionAwareCoreService.GetList()

I am invoking the Tridion 2011 SP1 core service via the shipped client assembly. When I attempt to list the contents of a publication, I get an exception.
The code (simplified) looks like this:
ItemsFilterData filter = new Tridion.ContentManager.CoreService
.Client.RepositoryItemsFilterData.RepositoryItemsFilterData();
filter.ItemTypes = new ItemType[] {
ItemType.Folder,
ItemType.StructureGroup
};
filter.Recursive = false;
IEnumerable<IdentifiableObjectData> childItems = core.GetList("tcm:0-15-1", filter);
Note: the variable "core" refers to an ISessionAwareCoreService which I can successfully use to call, for example core.GetSystemWideList()
When .GetList is invoked, I get the following exception:
System.ServiceModel.FaultException`1 was unhandled
Message=Unexpected list type:
Tridion.ContentManager.Data.ContentManagement.RepositoryItemsFilterData.
What are the possible causes of this problem? Can you suggest a good general approach for interpreting this kind of message?
You can't get the direct children of a Publication using GetList. Instead you should just load the PublicationData with a client.Read and then access the RootFolder and RootStructureGroup on that.
PublicationData pub = (PublicationData)core.Read("tcm:0-1-1", new ReadOptions());
string rootFolder = pub.RootFolder.IdRef;
string rootSG = pub.RootStructureGroup.IdRef;
Alternatively you can call GetListXml with your RepositoryItemsFilterData and extract the items from the XML yourself.
XElement listResult = core.GetListXml(parent.ID, filter);

Resources