Issues in setting secondary properties to a document using cmis 1.1 - alfresco

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.

Related

POST method to upload file to Azure storage - what to return

I am creating an app where
user can upload the text file and then
find most used word and change that word in text and
show the changed text to the user.
if it is possible, I would like to
get the file’s text content before uploading when Post method is being called and save that content
so I add the “DownloadTextAsync()” method inside of the POST method, but it seems like I am calling this method to the wrong subject?
[HttpPost("UploadText")]
public async Task<IActionResult> Post(List<IFormFile> files)
{
string connectionString = Environment.GetEnvironmentVariable("mykeystringhere");
// Create a BlobServiceClient object which will be used to create a container client
BlobServiceClient blobServiceClient = new BlobServiceClient(connectionString);
//Create a unique name for the container
string containerName = "textdata" + Guid.NewGuid().ToString();
// Create the container and return a container client object
BlobContainerClient containerClient = await blobServiceClient.CreateBlobContainerAsync(containerName);
// Create a local file in the ./data/ directory for uploading and downloading
string localPath = "./data/";
string fileName = "textfiledata" + Guid.NewGuid().ToString() + ".txt";
string localFilePath = Path.Combine(localPath, fileName);
// Get a reference to a blob
BlobClient blobClient = containerClient.GetBlobClient(fileName);
// Open the file and upload its data
using FileStream uploadFileStream = System.IO.File.OpenRead(localFilePath);
await blobClient.UploadAsync(uploadFileStream, true);
uploadFileStream.Close();
string downloadFilePath = localFilePath.Replace(".txt", "DOWNLOAD.txt");
// Get the blob file as text
string contents = blobClient.DownloadTextAsync().Result;
//return the string
return contents;
//if (uploadSuccess)
// return View("UploadSuccess");
//else
// return View("UploadError");
}
The issues I am having are
I understood that ‘blobClient’ is the reference to the blob, where I can get the file’s data but this must be wrong?
Also it seems like I cannot use “CloudBlobContainer” nor the “CloudBlockBlob blob”. Is it because inside of the POST method, the blob has been just initialized and does not exist when these twos are executed?
Also when I test the POST method, the console throws “Refused to load the font '' because it violates the following Content Security Policy directive: "default-src 'none'". Note that 'font-src' was not explicitly set, so 'default-src' is used as a fallback.” which I googled but have no idea what it means?
I have tried different ways but keep getting CANNOT POST/“ But could not really find the solid anwers. Could this be related to my POST method?
I understood that ‘blobClient’ is the reference to the blob, where I
can get the file’s data but this must be wrong?
That's correct in a sense that you can use blobClient to perform operations on blob like upload/download etc. I am not sure why you say but this must be wrong.
Also it seems like I cannot use “CloudBlobContainer” nor the
“CloudBlockBlob blob”. Is it because inside of the POST method, the
blob has been just initialized and does not exist when these twos are
executed?
No, this is happening because you're using a newer version of SDK (version 12.x.x) and CloudBlobContainer and CloudBlockBlob are available in the older version of the SDK.
Also when I test the POST method, the console throws “Refused to load
the font '' because it violates the following Content Security Policy
directive: "default-src 'none'". Note that 'font-src' was not
explicitly set, so 'default-src' is used as a fallback.” which I
googled but have no idea what it means? I have tried different ways
but keep getting CANNOT POST/“ But could not really find the solid
anwers. Could this be related to my POST method?
Not sure why this is happening. You may want to ask a separate question for this and when you do, please include the HTML portion of your code as well.

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.

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

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)

How to get Tridion item ID after created using Core Service

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.

How to ignore comments when parsing xml in asp.net

Seems like this should be easy, but I'm not finding a simple configuration setting. Basically I have a page that will be parsing xml files that may have some comment tags in them. I'm loading it as an xml doc and looping through a particular node of the document and I'm running into problems because it's counting the comment as a child node. Any way to tell asp.net not to look at comments other than writing my own check for <!-- ?
If you use XmlNode, then that has a NodeType property. Ignore the nodes where that has a value of "Comment".
An XNode has the same property.
Use XmlReaderSettings.IgnoreComments:
XmlReaderSettings readerSettings = new XmlReaderSettings();
readerSettings.IgnoreComments = true;
using (XmlReader reader = XmlReader.Create("input.xml", readerSettings))
{
XmlDocument myData = new XmlDocument();
myData.Load(reader);
// etc...
}

Resources