11-26-2008 07:58 AM
public String writeContentInSpace(String contentName, String spaceName, String mimeType, String encoding, byte[] content) throws AlfrescoAdapterException {
try {
// Start the session
AuthenticationUtils.startSession(username, password);
} catch (AuthenticationFault fault) {
System.out.println("fallo startSession en writeContentInSpace");
fault.printStackTrace();
return null;
}
try {
// Searching for the space UUID
// Get a reference to the respository web service
RepositoryServiceSoapBindingStub repositoryService;
if (isLocalService)
repositoryService = WebServiceFactory.getRepositoryService();
else
repositoryService = WebServiceFactory.getRepositoryService(serviceURL);
// Get a reference to the space we have named
Store storeRef = new Store(Constants.WORKSPACE_STORE, "SpacesStore");
Node[] nodes = null;
Reference reference = null;
Predicate predicate =null;
try {
reference = new Reference(storeRef, null, "/app:company_home/app:user_homes/cm:" + spaceName);
predicate = new Predicate(new Reference[] { reference }, null, null);
nodes = repositoryService.get(predicate);
} catch (Exception ex) {
System.out.println("fallo en repositoryService.get()");
System.out.println("excepcion es = " + ex.getMessage());
ex.printStackTrace();
return null;
}
// Searching for the UUID out of the result
String spaceUUID = "";
if (nodes[0] != null) {
NamedValue[] properties = nodes[0].getProperties();
SpaceNode sn = new SpaceNode();
for (int j = 0; j < properties.length; j++) {
NamedValue nv = properties[j];
sn.getNodeInformation().put(nv.getName(), nv.getValue());
}
spaceUUID = sn.getNodeUUID();
} else
throw new AlfrescoAdapterException(true, "No space '" + spaceName + "' found!", "No space '" + spaceName + "' found!", null);
// Create a reference to the parent where we want to insert content
Reference referenceWrite = new Reference(storeRef, spaceUUID, null);
ParentReference parentReference = new ParentReference(referenceWrite.getStore(), referenceWrite.getUuid(), null, Constants.ASSOC_CONTAINS, Constants.ASSOC_CONTAINS);
// Create content
NamedValue[] newProperties = new NamedValue[] { Utils.createNamedValue(Constants.PROP_NAME, contentName)};
CMLCreate create = new CMLCreate("1", parentReference, null, null, null, Constants.TYPE_CONTENT, newProperties);
CMLAddAspect addAspect = new CMLAddAspect();
addAspect.setAspect(Constants.ASPECT_VERSIONABLE);
addAspect.setProperty(newProperties);
addAspect.setWhere(new Predicate(new Reference[] { referenceWrite }, null, null));
addAspect.setWhere_id("1");
CML cml = new CML();
cml.setCreate(new CMLCreate[] { create });
cml.setAddAspect(new CMLAddAspect[]{addAspect});
// update
UpdateResult[] results;
if (isLocalService)
results = WebServiceFactory.getRepositoryService().update(cml);
else
results = WebServiceFactory.getRepositoryService(serviceURL).update(cml);
// Set content
ContentFormat format = new ContentFormat(mimeType.toString(), encoding);
Content newContent;
if (isLocalService)
newContent = WebServiceFactory.getContentService().write(results[0].getDestination(), Constants.PROP_CONTENT, content, format);
else
newContent = WebServiceFactory.getContentService(serviceURL).write(results[0].getDestination(), Constants.PROP_CONTENT, content, format);
return newContent.getNode().getUuid();
} catch (Exception e) {
System.out.println(e.getMessage());
System.out.println(e.getClass().getName());
e.printStackTrace();
throw new AlfrescoAdapterException(true, "Exception occurred during \"writeContentInSpace\"", "Exception occurred during \"writeContentInSpace\"", e);
} finally {
// End the session
AuthenticationUtils.endSession();
}
}
11-26-2008 10:55 AM
// update
UpdateResult[] results;
if (isLocalService)
results = WebServiceFactory.getRepositoryService().update(cml);
else
results = WebServiceFactory.getRepositoryService(serviceURL).update(cml);
11-26-2008 03:58 PM
public void makeVersionableContent(String destinationNodeUuid)
throws AlfrescoAdapterException {
try {
// Iniciar sesion
AuthenticationUtils.startSession(username, password);
// Obtener repositorio
RepositoryServiceSoapBindingStub repositoryService;
if (isLocalService)
repositoryService = WebServiceFactory.getRepositoryService();
else
repositoryService = WebServiceFactory
.getRepositoryService(serviceURL);
// Obtener referencia al nodo
Store storeRef = new Store(Constants.WORKSPACE_STORE, "SpacesStore");
Reference referenceVersion = new Reference(storeRef,
destinationNodeUuid, null);
Predicate predicateVersion = new Predicate(
new Reference[] { referenceVersion }, null, null);
// Crear aspecto versionable
CMLAddAspect addVersionableAspect = new CMLAddAspect();
addVersionableAspect.setAspect(Constants.ASPECT_VERSIONABLE);
addVersionableAspect.setWhere(predicateVersion);
// Crear bloque CML
CML cml = new CML();
cml.setAddAspect(new CMLAddAspect[] { addVersionableAspect });
// Actualizar repositorio
UpdateResult[] results = repositoryService.update(cml);
} catch (Exception e) {
System.out.println(e.getMessage());
System.out.println(e.getClass().getName());
e.printStackTrace();
throw new AlfrescoAdapterException(true,
"Exception occurred during \"makeVersionableContent\"",
"Exception occurred during \"makeVersionableContent\"", e);
} finally {
// Terminar sesion
AuthenticationUtils.endSession();
}
}
Tags
Find what you came for
We want to make your experience in Hyland Connect as valuable as possible, so we put together some helpful links.