Skip to content

Instantly share code, notes, and snippets.

@felipebizz
Last active Aug 29, 2015
Embed
What would you like to do?
Update Properties Cmis
package br.com.arizona.visto.system.dam.repository.cmis;
import org.apache.chemistry.opencmis.client.api.*;
import org.apache.chemistry.opencmis.client.runtime.SessionFactoryImpl;
import org.apache.chemistry.opencmis.commons.SessionParameter;
import org.apache.chemistry.opencmis.commons.data.PropertyData;
import org.apache.chemistry.opencmis.commons.enums.BindingType;
import java.util.*;
/**
* Created by felipe on 06/05/15.
*/
public class ExecuteScript {
private static final String BUSINESS_FILE_WITHOUT_APPROVAL_DATE =
"SELECT cmis:creationDate, arizonaBusiness:approvalDate FROM arizona:file:business F " +
"WHERE F.nuxeo:isVersion = false AND arizonaBusiness:approvalDate is null";
public static void main(String args[]) {
SessionFactory factory = SessionFactoryImpl.newInstance();
Map<String, String> sessionParameters = new HashMap<String, String>();
sessionParameters.put(SessionParameter.ATOMPUB_URL, "http://54.207.87.151:8080/nuxeo/atom/cmis");
sessionParameters.put(SessionParameter.USER, "Administrator");
sessionParameters.put(SessionParameter.PASSWORD, "Administrator");
sessionParameters.put(SessionParameter.BINDING_TYPE, BindingType.ATOMPUB.value());
sessionParameters.put(SessionParameter.REPOSITORY_ID, "boticario");
Session session = factory.createSession(sessionParameters);
ItemIterable<QueryResult> items = session.query(BUSINESS_FILE_WITHOUT_APPROVAL_DATE, true);
int cont = 1;
for (QueryResult result : items) {
PropertyData propertyCreationDate = result.getPropertyById("cmis:creationDate");
PropertyData propertyObjectId = result.getPropertyById("cmis:objectId");
List<?> propertyValues = propertyCreationDate.getValues();
final Map<String, Object> updateProperties = new HashMap<>();
for(Object gc : propertyValues){
GregorianCalendar calendar = (GregorianCalendar)gc;
System.out.println("\n "+ cont + " -- data :" + calendar.getTime()+" ID: " +propertyObjectId.getValues().get(0).toString());
updateProperties.put("arizonaBusiness:approvalDate", calendar.getTime());
final CmisObject object = session.getObject(propertyObjectId.getValues().get(0).toString());
object.updateProperties(updateProperties);
cont++;
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment