Search in sources :

Example 1 with CMLCreate

use of org.alfresco.webservice.types.CMLCreate in project trainning by fernandotomasio.

the class AlfrescoContentDAO method createFolderWithUUIDParent.

@Override
public String createFolderWithUUIDParent(FolderDTO folder, String uuidParent) {
    try {
        AuthenticationUtils.startSession(USERNAME, PASSWORD);
        ParentReference parentReference = new ParentReference(STORE, uuidParent, null, Constants.ASSOC_CONTAINS, null);
        parentReference.setChildName("{" + Constants.NAMESPACE_CONTENT_MODEL + "}" + folder.getName());
        // Construct CML statement to create content node
        // Note: Assign "1" as a local id, so we can refer to it in
        // subsequent
        // CML statements within the same CML block
        NamedValue[] contentProps = new NamedValue[1];
        contentProps[0] = Utils.createNamedValue(Constants.PROP_NAME, folder.getName());
        CMLCreate create = new CMLCreate("1", parentReference, null, null, null, Constants.TYPE_FOLDER, contentProps);
        // Construct CML statement to add titled aspect
        NamedValue[] titledProps = new NamedValue[2];
        titledProps[0] = Utils.createNamedValue(Constants.PROP_TITLE, folder.getTitle());
        titledProps[1] = Utils.createNamedValue(Constants.PROP_DESCRIPTION, folder.getDescription());
        CMLAddAspect addAspect = new CMLAddAspect(Constants.ASPECT_TITLED, titledProps, null, "1");
        // Construct CML Block
        CML cml = new CML();
        cml.setCreate(new CMLCreate[] { create });
        cml.setAddAspect(new CMLAddAspect[] { addAspect });
        // Issue CML statement via Repository Web Service and retrieve
        // result
        // Note: Batching of multiple statements into a single web call
        UpdateResult[] result = WebServiceFactory.getRepositoryService().update(cml);
        Reference content = result[0].getDestination();
        return content.getUuid();
    } catch (AuthenticationFault e) {
        Logger.getLogger(AlfrescoContentDAO.class.getName()).log(Level.SEVERE, "Erro de Autenticação");
        return null;
    } catch (RepositoryFault e) {
        Logger.getLogger(AlfrescoContentDAO.class.getName()).log(Level.INFO, "Conteúdo não disponível");
        return null;
    } catch (RemoteException e) {
        Logger.getLogger(AlfrescoContentDAO.class.getName()).log(Level.SEVERE, "Erro de Acesso a Serviço Web");
        return null;
    } finally {
        // End the session
        AuthenticationUtils.endSession();
    }
}
Also used : ParentReference(org.alfresco.webservice.types.ParentReference) CML(org.alfresco.webservice.types.CML) ParentReference(org.alfresco.webservice.types.ParentReference) Reference(org.alfresco.webservice.types.Reference) NamedValue(org.alfresco.webservice.types.NamedValue) RepositoryFault(org.alfresco.webservice.repository.RepositoryFault) CMLCreate(org.alfresco.webservice.types.CMLCreate) CMLAddAspect(org.alfresco.webservice.types.CMLAddAspect) AuthenticationFault(org.alfresco.webservice.authentication.AuthenticationFault) RemoteException(java.rmi.RemoteException) UpdateResult(org.alfresco.webservice.repository.UpdateResult)

Example 2 with CMLCreate

use of org.alfresco.webservice.types.CMLCreate in project trainning by fernandotomasio.

the class AlfrescoContentDAO method createDocumentWithUUIDParent.

@Override
public String createDocumentWithUUIDParent(DocumentDTO document, String uuidParent) {
    try {
        AuthenticationUtils.startSession(USERNAME, PASSWORD);
        ParentReference parentReference = new ParentReference(STORE, uuidParent, null, Constants.ASSOC_CONTAINS, null);
        parentReference.setChildName("{" + Constants.NAMESPACE_CONTENT_MODEL + "}" + document.getName());
        // Define the content format for the content we are adding
        ContentFormat contentFormat = new ContentFormat(document.getMimeType(), document.getCharset());
        // Construct CML statement to create content node
        // Note: Assign "1" as a local id, so we can refer to it in
        // subsequent
        // CML statements within the same CML block
        NamedValue[] contentProps = new NamedValue[1];
        contentProps[0] = Utils.createNamedValue(Constants.PROP_NAME, document.getName());
        CMLCreate create = new CMLCreate("1", parentReference, null, null, null, Constants.TYPE_CONTENT, contentProps);
        // Construct CML statement to add titled aspect
        NamedValue[] titledProps = new NamedValue[2];
        titledProps[0] = Utils.createNamedValue(Constants.PROP_TITLE, document.getTitle());
        titledProps[1] = Utils.createNamedValue(Constants.PROP_DESCRIPTION, document.getDescription());
        CMLAddAspect addAspect = new CMLAddAspect(Constants.ASPECT_TITLED, titledProps, null, "1");
        // Construct CML Block
        CML cml = new CML();
        cml.setCreate(new CMLCreate[] { create });
        cml.setAddAspect(new CMLAddAspect[] { addAspect });
        // Issue CML statement via Repository Web Service and retrieve
        // result
        // Note: Batching of multiple statements into a single web call
        UpdateResult[] result = WebServiceFactory.getRepositoryService().update(cml);
        Reference content = result[0].getDestination();
        ContentServiceSoapBindingStub contentService = WebServiceFactory.getContentService();
        contentService.write(content, Constants.PROP_CONTENT, document.getContentStream(), contentFormat);
        return content.getUuid();
    } catch (AuthenticationFault e) {
        Logger.getLogger(AlfrescoContentDAO.class.getName()).log(Level.SEVERE, "Erro de Autenticação");
        return null;
    } catch (RepositoryFault e) {
        Logger.getLogger(AlfrescoContentDAO.class.getName()).log(Level.INFO, "Conteúdo não disponível");
        return null;
    } catch (RemoteException e) {
        Logger.getLogger(AlfrescoContentDAO.class.getName()).log(Level.SEVERE, "Erro de Acesso a Serviço Web");
        return null;
    } finally {
        // End the session
        AuthenticationUtils.endSession();
    }
}
Also used : ParentReference(org.alfresco.webservice.types.ParentReference) CML(org.alfresco.webservice.types.CML) ContentFormat(org.alfresco.webservice.types.ContentFormat) ParentReference(org.alfresco.webservice.types.ParentReference) Reference(org.alfresco.webservice.types.Reference) NamedValue(org.alfresco.webservice.types.NamedValue) ContentServiceSoapBindingStub(org.alfresco.webservice.content.ContentServiceSoapBindingStub) RepositoryFault(org.alfresco.webservice.repository.RepositoryFault) CMLCreate(org.alfresco.webservice.types.CMLCreate) CMLAddAspect(org.alfresco.webservice.types.CMLAddAspect) AuthenticationFault(org.alfresco.webservice.authentication.AuthenticationFault) RemoteException(java.rmi.RemoteException) UpdateResult(org.alfresco.webservice.repository.UpdateResult)

Example 3 with CMLCreate

use of org.alfresco.webservice.types.CMLCreate in project trainning by fernandotomasio.

the class AlfrescoContentDAO method createFolder.

@Override
public String createFolder(FolderDTO folder, String path) {
    try {
        AuthenticationUtils.startSession(USERNAME, PASSWORD);
        ParentReference parentReference = new ParentReference(STORE, null, encodePath(path), Constants.ASSOC_CONTAINS, null);
        parentReference.setChildName("{" + Constants.NAMESPACE_CONTENT_MODEL + "}" + folder.getName());
        // Construct CML statement to create content node
        // Note: Assign "1" as a local id, so we can refer to it in
        // subsequent
        // CML statements within the same CML block
        NamedValue[] contentProps = new NamedValue[1];
        contentProps[0] = Utils.createNamedValue(Constants.PROP_NAME, folder.getName());
        CMLCreate create = new CMLCreate("1", parentReference, null, null, null, Constants.TYPE_FOLDER, contentProps);
        // Construct CML statement to add titled aspect
        NamedValue[] titledProps = new NamedValue[2];
        titledProps[0] = Utils.createNamedValue(Constants.PROP_TITLE, folder.getTitle());
        titledProps[1] = Utils.createNamedValue(Constants.PROP_DESCRIPTION, folder.getDescription());
        CMLAddAspect addAspect = new CMLAddAspect(Constants.ASPECT_TITLED, titledProps, null, "1");
        // Construct CML Block
        CML cml = new CML();
        cml.setCreate(new CMLCreate[] { create });
        cml.setAddAspect(new CMLAddAspect[] { addAspect });
        // Issue CML statement via Repository Web Service and retrieve
        // result
        // Note: Batching of multiple statements into a single web call
        UpdateResult[] result = WebServiceFactory.getRepositoryService().update(cml);
        Reference content = result[0].getDestination();
        return content.getUuid();
    } catch (AuthenticationFault e) {
        Logger.getLogger(AlfrescoContentDAO.class.getName()).log(Level.SEVERE, "Erro de Autenticação");
        return null;
    } catch (RepositoryFault e) {
        Logger.getLogger(AlfrescoContentDAO.class.getName()).log(Level.INFO, "Conteúdo não disponível");
        return null;
    } catch (RemoteException e) {
        Logger.getLogger(AlfrescoContentDAO.class.getName()).log(Level.SEVERE, "Erro de Acesso a Serviço Web");
        return null;
    } finally {
        // End the session
        AuthenticationUtils.endSession();
    }
}
Also used : ParentReference(org.alfresco.webservice.types.ParentReference) CML(org.alfresco.webservice.types.CML) ParentReference(org.alfresco.webservice.types.ParentReference) Reference(org.alfresco.webservice.types.Reference) NamedValue(org.alfresco.webservice.types.NamedValue) RepositoryFault(org.alfresco.webservice.repository.RepositoryFault) CMLCreate(org.alfresco.webservice.types.CMLCreate) CMLAddAspect(org.alfresco.webservice.types.CMLAddAspect) AuthenticationFault(org.alfresco.webservice.authentication.AuthenticationFault) RemoteException(java.rmi.RemoteException) UpdateResult(org.alfresco.webservice.repository.UpdateResult)

Example 4 with CMLCreate

use of org.alfresco.webservice.types.CMLCreate in project trainning by fernandotomasio.

the class AlfrescoContentDAO method createDocument.

@Override
public String createDocument(DocumentDTO document, String path) {
    try {
        AuthenticationUtils.startSession(USERNAME, PASSWORD);
        ParentReference parentReference = new ParentReference(STORE, null, encodePath(path), Constants.ASSOC_CONTAINS, null);
        parentReference.setChildName("{" + Constants.NAMESPACE_CONTENT_MODEL + "}" + document.getName());
        // Define the content format for the content we are adding
        ContentFormat contentFormat = new ContentFormat(document.getMimeType(), document.getCharset());
        // Construct CML statement to create content node
        // Note: Assign "1" as a local id, so we can refer to it in
        // subsequent
        // CML statements within the same CML block
        NamedValue[] contentProps = new NamedValue[1];
        contentProps[0] = Utils.createNamedValue(Constants.PROP_NAME, document.getName());
        CMLCreate create = new CMLCreate("1", parentReference, null, null, null, Constants.TYPE_CONTENT, contentProps);
        // Construct CML statement to add titled aspect
        NamedValue[] titledProps = new NamedValue[2];
        titledProps[0] = Utils.createNamedValue(Constants.PROP_TITLE, document.getTitle());
        titledProps[1] = Utils.createNamedValue(Constants.PROP_DESCRIPTION, document.getDescription());
        CMLAddAspect addAspect = new CMLAddAspect(Constants.ASPECT_TITLED, titledProps, null, "1");
        // Construct CML Block
        CML cml = new CML();
        cml.setCreate(new CMLCreate[] { create });
        cml.setAddAspect(new CMLAddAspect[] { addAspect });
        // Issue CML statement via Repository Web Service and retrieve
        // result
        // Note: Batching of multiple statements into a single web call
        UpdateResult[] result = WebServiceFactory.getRepositoryService().update(cml);
        Reference content = result[0].getDestination();
        ContentServiceSoapBindingStub contentService = WebServiceFactory.getContentService();
        contentService.write(content, Constants.PROP_CONTENT, document.getContentStream(), contentFormat);
        return content.getUuid();
    } catch (AuthenticationFault e) {
        Logger.getLogger(AlfrescoContentDAO.class.getName()).log(Level.SEVERE, "Erro de Autenticação");
        return null;
    } catch (RepositoryFault e) {
        Logger.getLogger(AlfrescoContentDAO.class.getName()).log(Level.INFO, "Conteúdo não disponível");
        return null;
    } catch (RemoteException e) {
        Logger.getLogger(AlfrescoContentDAO.class.getName()).log(Level.SEVERE, "Erro de Acesso a Serviço Web");
        return null;
    } finally {
        // End the session
        AuthenticationUtils.endSession();
    }
}
Also used : ParentReference(org.alfresco.webservice.types.ParentReference) CML(org.alfresco.webservice.types.CML) ContentFormat(org.alfresco.webservice.types.ContentFormat) ParentReference(org.alfresco.webservice.types.ParentReference) Reference(org.alfresco.webservice.types.Reference) NamedValue(org.alfresco.webservice.types.NamedValue) ContentServiceSoapBindingStub(org.alfresco.webservice.content.ContentServiceSoapBindingStub) RepositoryFault(org.alfresco.webservice.repository.RepositoryFault) CMLCreate(org.alfresco.webservice.types.CMLCreate) CMLAddAspect(org.alfresco.webservice.types.CMLAddAspect) AuthenticationFault(org.alfresco.webservice.authentication.AuthenticationFault) RemoteException(java.rmi.RemoteException) UpdateResult(org.alfresco.webservice.repository.UpdateResult)

Aggregations

RemoteException (java.rmi.RemoteException)4 AuthenticationFault (org.alfresco.webservice.authentication.AuthenticationFault)4 RepositoryFault (org.alfresco.webservice.repository.RepositoryFault)4 UpdateResult (org.alfresco.webservice.repository.UpdateResult)4 CML (org.alfresco.webservice.types.CML)4 CMLAddAspect (org.alfresco.webservice.types.CMLAddAspect)4 CMLCreate (org.alfresco.webservice.types.CMLCreate)4 NamedValue (org.alfresco.webservice.types.NamedValue)4 ParentReference (org.alfresco.webservice.types.ParentReference)4 Reference (org.alfresco.webservice.types.Reference)4 ContentServiceSoapBindingStub (org.alfresco.webservice.content.ContentServiceSoapBindingStub)2 ContentFormat (org.alfresco.webservice.types.ContentFormat)2