Search in sources :

Example 11 with AuthenticationFault

use of org.alfresco.webservice.authentication.AuthenticationFault in project trainning by fernandotomasio.

the class AlfrescoContentDAO method contentExistsByUUID.

@Override
public boolean contentExistsByUUID(String uuid) {
    boolean result = false;
    try {
        AuthenticationUtils.startSession(USERNAME, PASSWORD);
        RepositoryServiceSoapBindingStub repositoryService = WebServiceFactory.getRepositoryService();
        Reference node = new Reference();
        node.setStore(STORE);
        node.setUuid(uuid);
        Node[] nodes = null;
        nodes = repositoryService.get(new Predicate(new Reference[] { node }, STORE, null));
        if (nodes != null) {
            return true;
        }
    } catch (AuthenticationFault e) {
        Logger.getLogger(AlfrescoContentDAO.class.getName()).log(Level.SEVERE, "Erro de Autenticação");
    } catch (RepositoryFault e) {
        Logger.getLogger(AlfrescoContentDAO.class.getName()).log(Level.INFO, "Conteúdo não disponível");
    } catch (RemoteException e) {
        Logger.getLogger(AlfrescoContentDAO.class.getName()).log(Level.SEVERE, "Erro de Acesso a Serviço Web");
    } finally {
        // End the session
        AuthenticationUtils.endSession();
    }
    return result;
}
Also used : RepositoryFault(org.alfresco.webservice.repository.RepositoryFault) ParentReference(org.alfresco.webservice.types.ParentReference) Reference(org.alfresco.webservice.types.Reference) Node(org.alfresco.webservice.types.Node) RepositoryServiceSoapBindingStub(org.alfresco.webservice.repository.RepositoryServiceSoapBindingStub) AuthenticationFault(org.alfresco.webservice.authentication.AuthenticationFault) RemoteException(java.rmi.RemoteException) Predicate(org.alfresco.webservice.types.Predicate)

Example 12 with AuthenticationFault

use of org.alfresco.webservice.authentication.AuthenticationFault 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 13 with AuthenticationFault

use of org.alfresco.webservice.authentication.AuthenticationFault in project trainning by fernandotomasio.

the class AlfrescoContentDAO method findDocumentByUUID.

@SuppressWarnings("unused")
@Override
public DocumentDTO findDocumentByUUID(String uuid) {
    DocumentDTO content = new DocumentDTO();
    try {
        AuthenticationUtils.startSession(USERNAME, PASSWORD);
        RepositoryServiceSoapBindingStub repositoryService = WebServiceFactory.getRepositoryService();
        Reference node = new Reference();
        node.setStore(STORE);
        node.setUuid(uuid);
        Node[] nodes = null;
        nodes = repositoryService.get(new Predicate(new Reference[] { node }, STORE, null));
        ContentServiceSoapBindingStub contentService = WebServiceFactory.getContentService();
        Content[] readResult = contentService.read(new Predicate(new Reference[] { nodes[0].getReference() }, STORE, null), Constants.PROP_CONTENT);
        Content c = readResult[0];
        byte[] stream = ContentUtils.convertToByteArray(ContentUtils.getContentAsInputStream(c));
        content.setContentStream(stream);
        if (nodes != null) {
            for (NamedValue namedValue : nodes[0].getProperties()) {
                if (namedValue.getName().endsWith(Constants.PROP_CREATED) == true) {
                // contentResult.setCreateDate(namedValue.getValue());
                } else if (namedValue.getName().endsWith(Constants.PROP_NAME) == true) {
                    content.setName(namedValue.getValue());
                } else if (namedValue.getName().endsWith(Constants.PROP_DESCRIPTION) == true) {
                    content.setDescription(namedValue.getValue());
                } else if (namedValue.getName().endsWith(Constants.PROP_TITLE) == true) {
                    content.setTitle(namedValue.getValue());
                }
            }
        } else {
            return null;
        }
    } catch (AuthenticationFault e) {
        Logger.getLogger(AlfrescoContentDAO.class.getName()).log(Level.SEVERE, "Erro de Autenticação");
    } catch (RepositoryFault e) {
        Logger.getLogger(AlfrescoContentDAO.class.getName()).log(Level.INFO, "Conteúdo não disponível");
    } catch (RemoteException e) {
        Logger.getLogger(AlfrescoContentDAO.class.getName()).log(Level.SEVERE, "Erro de Acesso a Serviço Web");
    } catch (Exception e) {
        Logger.getLogger(AlfrescoContentDAO.class.getName()).log(Level.SEVERE, "Erro de abertura do arquivo");
    } finally {
        // End the session
        AuthenticationUtils.endSession();
    }
    return content;
}
Also used : ParentReference(org.alfresco.webservice.types.ParentReference) Reference(org.alfresco.webservice.types.Reference) Node(org.alfresco.webservice.types.Node) NamedValue(org.alfresco.webservice.types.NamedValue) RemoteException(java.rmi.RemoteException) Predicate(org.alfresco.webservice.types.Predicate) ContentServiceSoapBindingStub(org.alfresco.webservice.content.ContentServiceSoapBindingStub) RepositoryFault(org.alfresco.webservice.repository.RepositoryFault) Content(org.alfresco.webservice.content.Content) DocumentDTO(com.tomasio.projects.trainning.dto.DocumentDTO) RepositoryServiceSoapBindingStub(org.alfresco.webservice.repository.RepositoryServiceSoapBindingStub) AuthenticationFault(org.alfresco.webservice.authentication.AuthenticationFault) RemoteException(java.rmi.RemoteException)

Example 14 with AuthenticationFault

use of org.alfresco.webservice.authentication.AuthenticationFault 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)

Example 15 with AuthenticationFault

use of org.alfresco.webservice.authentication.AuthenticationFault in project trainning by fernandotomasio.

the class AlfrescoContentDAO method removeContent.

// @Override
// public ContentDTO[] findDocumentosByTreinamento(String curso, String turma,
// String exercicio) {
// String path = DCTP_SPACE + "/" + TREINAMENTOS_SPACE + "/" + exercicio
// + "/" + curso + "-" + turma;
// return findAllContentByPath(path);
// }
@Override
public void removeContent(String uuid) {
    try {
        AuthenticationUtils.startSession(USERNAME, PASSWORD);
        WebServiceFactory.getRepositoryService();
        Reference node = new Reference();
        node.setStore(STORE);
        node.setUuid(uuid);
        Predicate predicate = new Predicate(new Reference[] { node }, STORE, null);
        // delete content
        CMLDelete delete = new CMLDelete();
        delete.setWhere(predicate);
        // create CML update object
        CML cmlRemove = new CML();
        cmlRemove.setDelete(new CMLDelete[] { delete });
        // perform a CML update to create the node
        WebServiceFactory.getRepositoryService().update(cmlRemove);
    } catch (AuthenticationFault e) {
        Logger.getLogger(AlfrescoContentDAO.class.getName()).log(Level.SEVERE, "Erro de Autenticação");
    } catch (RepositoryFault e) {
        Logger.getLogger(AlfrescoContentDAO.class.getName()).log(Level.INFO, "Conteúdo não disponível");
    } catch (RemoteException e) {
        Logger.getLogger(AlfrescoContentDAO.class.getName()).log(Level.SEVERE, "Erro de Acesso a Serviço Web");
    } finally {
        // End the session
        AuthenticationUtils.endSession();
    }
}
Also used : CML(org.alfresco.webservice.types.CML) RepositoryFault(org.alfresco.webservice.repository.RepositoryFault) CMLDelete(org.alfresco.webservice.types.CMLDelete) ParentReference(org.alfresco.webservice.types.ParentReference) Reference(org.alfresco.webservice.types.Reference) AuthenticationFault(org.alfresco.webservice.authentication.AuthenticationFault) RemoteException(java.rmi.RemoteException) Predicate(org.alfresco.webservice.types.Predicate)

Aggregations

RemoteException (java.rmi.RemoteException)15 AuthenticationFault (org.alfresco.webservice.authentication.AuthenticationFault)15 RepositoryFault (org.alfresco.webservice.repository.RepositoryFault)15 Reference (org.alfresco.webservice.types.Reference)15 ParentReference (org.alfresco.webservice.types.ParentReference)12 NamedValue (org.alfresco.webservice.types.NamedValue)11 Predicate (org.alfresco.webservice.types.Predicate)11 RepositoryServiceSoapBindingStub (org.alfresco.webservice.repository.RepositoryServiceSoapBindingStub)9 Node (org.alfresco.webservice.types.Node)9 CML (org.alfresco.webservice.types.CML)6 ContentServiceSoapBindingStub (org.alfresco.webservice.content.ContentServiceSoapBindingStub)5 UpdateResult (org.alfresco.webservice.repository.UpdateResult)4 CMLAddAspect (org.alfresco.webservice.types.CMLAddAspect)4 CMLCreate (org.alfresco.webservice.types.CMLCreate)4 AlfrescoContentDAO (com.tomasio.projects.trainning.dao.AlfrescoContentDAO)3 ContentDTO (com.tomasio.projects.trainning.dto.ContentDTO)3 DocumentDTO (com.tomasio.projects.trainning.dto.DocumentDTO)3 Content (org.alfresco.webservice.content.Content)3 QueryResult (org.alfresco.webservice.repository.QueryResult)3 ContentFormat (org.alfresco.webservice.types.ContentFormat)3