How to get Aspect specific properties using Open CMIS - alfresco

I am doing content migration activity. in that i am able to migrate actual content from one repository to other. but i also want to migrate meta-date for same.
I have some aspect's associated with my content and every aspect is having some properties. So i want to get those aspect specific properties from old repository. but i am not finding any useful code to get aspect properties. I am able to add aspect and properties in new repository.
AlfrescoDocument alfDoc = (AlfrescoDocument) dc;
alfDoc.addAspect("P:test:publishDate");
if (alfDoc.hasAspect("P:test:publishDate")) {
Map<String, GregorianCalendar> properties1 = new HashMap<String, GregorianCalendar>();
properties1.put("test:pubDate", dc.getCreationDate());
alfDoc.updateProperties(properties1);
}
But in same way i want to fetch aspect specific properties from old repository. Can anyone please help me.
Thanks in Advance.

There is an answer here, this might relate to your question?
https://community.alfresco.com/thread/201527-not-able-to-read-aspect-properties-using-cmis
Basically, make sure to use the proper CMIS 1.1 service URL http://localhost:8080/alfresco/api/-default-/public/cmis/versions/1.1/browser
Then something like this:
ItemIterable<QueryResult> queryResults = cmisSession.query(cmisQuery, false);
for (QueryResult queryResult:queryResults) {
PropertyData<?> abcProperty = queryResult.getPropertyById("abc");
String abcValue = abcProperty.getFirstValue().toString()
//…
}

Related

alfresco - how to add a nodeRef as the new version of another node using java?

Hi I am new to alfresco so i appreciate your help.
I am trying to add a new node ref as the new version of a document while editing his properties.
My scenario
i can create a PDF file with his properties as the content,after updating his properties, I am doing this with behavior/policies NodeServicePolicies.OnUpdateNodePolicy .
example: when i edit the name I can see it inside the PDF file
But this new file needs to be the new version of the file edited, i cant figure how to fix this.
i appreciate yours answer.
thanks in advance.
https://docs.alfresco.com/4.0/concepts/versioning.html
You're looking for versioning.
Like Curtis mentioned, using API is an option, but Alfresco will do this for you automatically if you set it up that way. Also, creating a new version will not change node's nodeRef.
See the createVersion method from the VersionService API here
My fix:
i just added get the content of the new file and set as the new content of the previous node. like this
void updateVersionWithNewNodeContent(nodeA){ // nodeB is the new version of the file. NodeRef nodeB; nodeService.setProperty(nodeA, ContentModel.PROP_CONTENT,nodeService.getProperty(nodeB, ContentModel.PROP_CONTENT)); }

Unable to Unlock Alfresco Document using CMIS

I'm using CMIS to make changes to alfresco document, I need to add new aspect to document, but I'm facing:
org.apache.chemistry.opencmis.commons.exceptions.CmisUpdateConflictException: Update conflict: 06160811 Cannot perform operation since the node (id:88289ea7-16b7-40ff-938b-b2888ef5bca5) is locked.
Below is the code I'm trying to unlock the document, but it's not successful. kindly suggest other alternatives to unlock a locked document using CMIS
for (QueryResult result : results) {
String objectId = result.getPropertyValueByQueryName(PropertyIds.OBJECT_ID);
AlfrescoDocument document = (AlfrescoDocument) session.getObject(session.createObjectId(objectId));
if (document != null) {
if(document.hasAspect("P:cm:lockable")) {
System.out.println(document.getName());
document.removeAspect("P:cm:lockable");
}
} else {
System.out.println("Document is null");
}
}
What version of Alfresco and CMIS are you using? It looks like you might be using the Alfresco CMIS extension JAR, but you should not be using that at all if you are using Alfresco 5.2 (or higher) and CMIS 1.1.
If you are using CMIS 1.1, the way to remove an aspect is to remove the name of the aspect from the array of values in the cmis:secondaryObjectTypeIds array, then update the properties with the trimmed list of aspects.
With all of that said, that would just remove the lockable aspect from the document. You are trying to actually unlock the document, not remove its ability to be locked/unlocked. So instead of trying to directly manipulate the aspect, you should just call cancelCheckout() if you want to unlock the document, like:
Document doc = (Document) getSession().getObjectByPath(filePath);
doc.cancelCheckOut();
Obviously you'll need to use credentials of someone who has the permissions to do this.
Use LockService.
lockService.unlock("nodeRef of the node to unlock")

EF 4.3 Code First Migrations - Uncompress __MigrationHistory Model

How can I uncompress/read the compressed models stored in the EF 4.3 Code First Migrations __MigrationHistory table?
I found a hint in this comment, that I can uncompress it using zip/gzip, but I don't know how exactly I should do this.
The problem is that I have changed something in my ef model classes, but when I call "add-migration" an empty migration ist generated. I think that is because the changes of my model classes are already assigned to an existing migration :(
(this may be a good starting point - won't work in your case)
I think you may find this useful - you 'just' need to work it out in the opposite direction, I think (I'm just hinting here as to what might be the direction, you'll have to check it out, test yourself)...
http://brice-lambson.blogspot.com/2012/05/using-entity-framework-code-first-with.html
It uses the following code...
private byte[] GetModel(TContext context)
{
using (var memoryStream = new MemoryStream())
{
using (var gzipStream = new GZipStream(
memoryStream,
CompressionMode.Compress))
using (var xmlWriter = XmlWriter.Create(
gzipStream,
new XmlWriterSettings { Indent = true }))
{
EdmxWriter.WriteEdmx(context, xmlWriter);
}
return memoryStream.ToArray();
}
}
to serialize the model.
However, as I understand (if I understand it properly) you need it in the other direction...
Quick search didn't show the equivalent reader - you can download the latest EF6 code - or also find EF5 one (I'll link in later if needed).
Reader:
Actually this may be closer to what you want:
http://edmxdom.codeplex.com/
(I haven't tried it out but was linked from MS)
http://social.msdn.microsoft.com/Forums/en-US/adodotnetentityframework/thread/1546548f-9f90-4cc2-b1b2-28cf7e9d1cb5/
And check the response about using MetadataWorkspace
If you need more info on the MetadataWorkspace I'll post some posts I made on that subject. You can get most info out - you'll need to sort 'reverse' what EdmxWriter is doing.
Essentially, you're looking for entity framework Edmx reader.
EdmxDOM:
I just checked it out fast - and it seems to be doing the Edmx format management you need.
It's a 'VB' project - but you can work through that
There is what seems to be a 'reader' (again, not sure, just went through this, as I know about the writer - but never worked w/ this part, direction)...
Public Sub LoadFile(ByVal fileName As String)
In the Edmx.vb

Display data from taxonomy using Ektron CMS with ASP.Net

I am trying display the content from taxonomy by using Ektron CMS with ASP .Net
By using the taxonomy path i got the id and trying to display the content.
But i am getting content as null.
Please let me know the possible solutions to solve this.
Waiting for experts answers.
Thanks,
In my development environment, I have the following taxonomy:
const string eventsTaxonomyPath = "\\Upcoming Events";
const long eventsTaxonomyId = 89;
It sounds like you already found this method (or something like it) in what I like to call the "Legacy API":
var taxonomyApi = new Ektron.Cms.API.Content.Taxonomy();
var taxonomyId = taxonomyApi.GetTaxonomyIdByPath(eventsTaxonomyPath);
Without any info on what version you're on, I'll assume it's a recent (8.5+) version. The Framework API makes it really easy to get the content from a given taxonomy. Below are a couple of ways that work on v9.0 and will most likely work in anything 8.5+ -- in the developer briefing webcast the only major change for the Framework API in v9 was the inclusion of the e-commerce namespace.
Getting the full taxonomy tree via the TaxonomyManager:
var taxonomyItemManager = new Ektron.Cms.Framework.Organization.TaxonomyManager();
var taxData = taxonomyItemManager.GetTree(eventsTaxonomyId, includeItems: true);
Getting all the content recursively from a given taxonomy folder via the ContentManager:
var contentManager = new Ektron.Cms.Framework.Content.ContentManager();
var criteria = new ContentTaxonomyCriteria();
criteria.AddFilter(eventsTaxonomyPath, true);
criteria.ReturnMetadata = true;
var content = contentManager.GetList(criteria);
The potential downside to the ContentManager way is that you lose the hierarchical taxonomy structure. The upside to using the ContentManager is that you can tell it to include all the metadata for each content block. That's not possible with the TaxonomyManager or TaxonomyItemManager.
My guess is that the "Get Content By Taxonomy" function you are using by default does not fetch the content. You can either-
a) Use the ID to get the content via the content manager API
b) Investigate if the function you are using has an override to include content.

Where do I put Pluralization rules in asp.net mvc3

I want to add specialized Pluralization rules to my project as I have names in my database like FAS and other things that end with "s" and I want those to be FAS and FASs but the default pluralization wants to make it FASes or something similar which I dont want. I am then trying to use this guide http://blogs.msdn.com/b/efdesign/archive/2008/12/02/pluralization.aspx but I have a hard time figuring out where to put this code? How do I make sure this code is run at startup of my project (I suppose it has to run at startup?)
So where do I put this code?
PluralizationService pluralizationService =
PluralizationService.CreateService(
new CultureInfo("en-US"));
ICustomPluralizationMapping mapping =
pluralizationService as ICustomPluralizationMapping;
if (mapping != null) // it shouldn't be but just checking
{
//Specifying the child pluralizes as children
mapping.Add("FAS", "FASs");
}
The answer is in the tutorial: you have to use it with the schema generator to create the schema using the pluralization service:
EntityModelSchemaGenerator generator =
new EntityModelSchemaGenerator(
storageModel,
"MyNamespace",
"MyContainer",
pluralizationService);
//Generate CSDL and MSL (in memory)
generator.GenerateMetadata();
When do you need to get the names of the entities pluralized?
I may be way wrong, but it seems to me that you could simply add the tables to the model and just rename them in the designer.
Am I overlooking some information?

Resources