As we transition to the new Hyland Community, some post links may be temporarily disrupted as we finalize redirects. We apologize for the inconvenience and are working to resolve this as quickly as possible. Details.
ScriptNode createPerson(String username) Create a Person (cm:person) with the given user name. Returns the person node created or null if the user name already exists.
var newUserName = "newUser"; var newUserPassword = "password"; var newUser = people.createPerson(newUserName,"firstName", "lastName","myEmail@somedomain.com", newUserPassword ,true); newUser.properties["cm:homeFolder"]=companyhome.createFolder(newUserName); newUser.save();
var newUserName = "usuario"; var newUserPassword = "password"; var newUser = people.createPerson(newUserName,"nombre", "apellido","email@correo.com", newUserPassword ,true); newUser.save(); var myfolder1 = userhome.createFolder("Memoria"); var myfolder2 = userhome.createFolder("Anteproyecto"); var myfolder3 = userhome.createFolder("Otros");
//Crea usuario var newUserName = "usuario"; var newUserPassword = "password"; var newUser = people.createPerson(newUserName,"nombre", "apellido","email@correo.com", newUserPassword ,true); newUser.save(); //Nodo que representa al usuario var persona = people.getPerson("usuario"); //Nodo que representa el espacio de inicio del usuario var espacioInicio = persona.properties["{http://www.alfresco.org/model/content/1.0}homeFolder"]; //Crea Carpetas var myfolder1 = espacioInicio.createFolder("Memoria"); var myfolder2 = espacioInicio.createFolder("Anteproyecto"); var myfolder3 = espacioInicio.createFolder("Otros");
package ec.com.uniseguros.util; import java.io.ByteArrayInputStream; import java.io.IOException; import java.util.HashMap; import java.util.List; import java.util.Map; import org.apache.chemistry.opencmis.client.api.CmisObject; import org.apache.chemistry.opencmis.client.api.Document; import org.apache.chemistry.opencmis.client.api.Folder; import org.apache.chemistry.opencmis.client.api.ObjectId; import org.apache.chemistry.opencmis.client.api.Repository; import org.apache.chemistry.opencmis.client.api.Session; import org.apache.chemistry.opencmis.client.api.SessionFactory; import org.apache.chemistry.opencmis.client.runtime.DocumentImpl; import org.apache.chemistry.opencmis.client.runtime.SessionFactoryImpl; import org.apache.chemistry.opencmis.client.util.FileUtils; import org.apache.chemistry.opencmis.commons.PropertyIds; import org.apache.chemistry.opencmis.commons.SessionParameter; import org.apache.chemistry.opencmis.commons.data.ContentStream; import org.apache.chemistry.opencmis.commons.enums.BaseTypeId; import org.apache.chemistry.opencmis.commons.enums.BindingType; import org.apache.chemistry.opencmis.commons.enums.VersioningState; import org.apache.chemistry.opencmis.commons.impl.dataobjects.ContentStreamImpl; import org.apache.log4j.Logger; import org.apache.poi.util.IOUtils; import ec.com.uniseguros.exception.AlfrescoException; /** * @author chan * */ public class AlfrescoUtils { private static final Logger log = Logger.getLogger(AlfrescoUtils.class); public static void endSession(final Session session) { session.clear(); } public static Session getSession(final String username, final String password, final String url) throws AlfrescoException { SessionFactory factory = SessionFactoryImpl.newInstance(); Map<String, String> parameter = new HashMap<String, String>(); // user credentials parameter.put(SessionParameter.USER, username); parameter.put(SessionParameter.PASSWORD, password); // connection settings parameter.put(SessionParameter.ATOMPUB_URL, url); parameter.put(SessionParameter.BINDING_TYPE, BindingType.ATOMPUB.value()); // create session List<Repository> repositories = factory.getRepositories(parameter); Session session = null; if (repositories != null && !repositories.isEmpty()) { session = repositories.get(0).createSession(); } else { log.debug("No se encontro repositorio"); throw new AlfrescoException("No se encuentra repositorio"); } return session; } public static Folder createChildFolder(final Folder parentFolder, final String folderName) throws AlfrescoException { try { return FileUtils.createFolder(parentFolder, folderName, "cmis:folder"); } catch (Exception e) { log.debug("no se creo folder hijo"); throw new AlfrescoException(e); } } public static Folder createRootFolder(final Session session, final String folderName) throws AlfrescoException { // FileUtils.getFolder(pathOrIdOfObject, session); try { Folder root = session.getRootFolder(); ObjectId parentId = session.createObjectId(root.getId()); // try to create the folder "test" which fails. createMainFolder(session, parentId, folderName); // Assuming we were able to create the folder (Done by using an // existing folder and skipping the above creation) CmisObject folderObj = null; for (CmisObject childrens : root.getChildren()) { if (childrens.getName().equals(folderName)) { folderObj = childrens; break; } } Folder folder = (Folder) folderObj; return folder; } catch (Exception e) { log.debug("no se creo carpeta root"); throw new AlfrescoException(e); } } private static ObjectId createMainFolder(final Session session, final ObjectId parentId, final String rootFolder) throws AlfrescoException { ObjectId mainFolderID = null; Map<String, Object> properties = new HashMap<String, Object>(); properties.put(PropertyIds.OBJECT_TYPE_ID, BaseTypeId.CMIS_FOLDER.value()); properties.put(PropertyIds.NAME, rootFolder); try { mainFolderID = session.createFolder(properties, parentId); } catch (Exception e) { throw new AlfrescoException("No se pudo crear folder principal"); } return mainFolderID; } public static String uploadDocument(final Folder folder, final byte[] bytes, final String fileName, final String contentType) { Map<String, String> newDocProps = new HashMap<String, String>(); newDocProps.put(PropertyIds.OBJECT_TYPE_ID, "cmis:document"); newDocProps.put(PropertyIds.NAME, fileName); ContentStream contentStream = new ContentStreamImpl(fileName, null, contentType, new ByteArrayInputStream(bytes)); org.apache.chemistry.opencmis.client.api.Document doc = folder .createDocument(newDocProps, contentStream, VersioningState.NONE); return doc.getId(); } public static void deleteDocument(final Session session, final String documentId) throws AlfrescoException { CmisObject object = session.getObject(documentId); if (object instanceof DocumentImpl) { Document doc = (DocumentImpl) object; doc.deleteAllVersions(); } else { log.debug("No se encuentra documento para borrar"); throw new AlfrescoException("Documento no se encuentra"); } } public static ArchivoWrapper obtainByteArrayFromDocument( final Session session, final String documentId) throws AlfrescoException { try { CmisObject object = session.getObject(documentId); if (object instanceof DocumentImpl) { Document doc = (DocumentImpl) object; ContentStream contentStream = doc.getContentStream(); ArchivoWrapper archivo = new ArchivoWrapper(); archivo.setArchivo(IOUtils.toByteArray(contentStream .getStream())); archivo.setNombre(contentStream.getFileName()); archivo.setContentType(contentStream.getMimeType()); return archivo; } else { throw new AlfrescoException("Documento no se encuentra"); } } catch (IOException e) { e.printStackTrace(); throw new AlfrescoException(e); } } }