Search in sources :

Example 1 with NamedValue

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

the class AlfrescoContentDAO method findDocumentSWFByUUID.

@Override
public DocumentDTO findDocumentSWFByUUID(String uuid) {
    DocumentDTO content = new DocumentDTO();
    try {
        AuthenticationUtils.startSession(USERNAME, PASSWORD);
        RepositoryServiceSoapBindingStub repositoryService = WebServiceFactory.getRepositoryService();
        Reference referenceSource = new Reference();
        referenceSource.setStore(STORE);
        referenceSource.setUuid(uuid);
        Reference referenceDestination = new Reference();
        referenceDestination.setStore(STORE);
        referenceDestination.setUuid(ConfigHelper.getValue("repostitory.swf.folder"));
        Node[] nodes = null;
        nodes = repositoryService.get(new Predicate(new Reference[] { referenceSource }, STORE, null));
        ContentServiceSoapBindingStub contentService = WebServiceFactory.getContentService();
        Content c = contentService.transform(referenceSource, Constants.PROP_CONTENT, referenceDestination, Constants.PROP_CONTENT, new ContentFormat("application/x-shockwave-flash", "UTF-8"));
        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) ContentFormat(org.alfresco.webservice.types.ContentFormat) 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 2 with NamedValue

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

the class AlfrescoContentDAO method updateDocument.

@Override
public String updateDocument(ContentDTO document) {
    try {
        AuthenticationUtils.startSession(USERNAME, PASSWORD);
        WebServiceFactory.getRepositoryService();
        Reference node = new Reference();
        node.setStore(STORE);
        if (document.getUid() == null || document.getUid().equals("")) {
            return null;
        }
        node.setUuid(document.getUid());
        Predicate predicate = new Predicate(new Reference[] { node }, STORE, null);
        // update content
        CMLUpdate update = new CMLUpdate();
        NamedValue[] properties = new NamedValue[3];
        properties[0] = Utils.createNamedValue(Constants.PROP_NAME, document.getName());
        properties[1] = Utils.createNamedValue(Constants.PROP_TITLE, document.getTitle());
        properties[2] = Utils.createNamedValue(Constants.PROP_DESCRIPTION, document.getDescription());
        update.setProperty(properties);
        update.setWhere(predicate);
        CML cmlUpdate = new CML();
        cmlUpdate.setUpdate(new CMLUpdate[] { update });
        WebServiceFactory.getRepositoryService().update(cmlUpdate);
        return document.getUid();
    } 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 null;
}
Also used : CML(org.alfresco.webservice.types.CML) RepositoryFault(org.alfresco.webservice.repository.RepositoryFault) ParentReference(org.alfresco.webservice.types.ParentReference) Reference(org.alfresco.webservice.types.Reference) CMLUpdate(org.alfresco.webservice.types.CMLUpdate) NamedValue(org.alfresco.webservice.types.NamedValue) AuthenticationFault(org.alfresco.webservice.authentication.AuthenticationFault) RemoteException(java.rmi.RemoteException) Predicate(org.alfresco.webservice.types.Predicate)

Example 3 with NamedValue

use of org.alfresco.webservice.types.NamedValue 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 4 with NamedValue

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

the class AlfrescoContentDAO method findAllContentByPath.

@Override
public ContentDTO[] findAllContentByPath(String path) {
    ContentDTO[] contents = null;
    try {
        AuthenticationUtils.startSession(USERNAME, PASSWORD);
        RepositoryServiceSoapBindingStub repositoryService = WebServiceFactory.getRepositoryService();
        // Get a reference to the space we have named
        Reference reference = new Reference(STORE, null, encodePath(path));
        Predicate predicate = new Predicate(new Reference[] { reference }, null, null);
        Node[] nodes = repositoryService.get(predicate);
        // Create a query object, looking for all items with alfresco in the
        // name of text
        Query query = new Query(Constants.QUERY_LANG_LUCENE, "+PARENT:\"workspace://SpacesStore/" + nodes[0].getReference().getUuid() + "\"");
        // Execute the query
        QueryResult queryResult = repositoryService.query(STORE, query, false);
        // Display the results
        ResultSet resultSet = queryResult.getResultSet();
        ResultSetRow[] rows = resultSet.getRows();
        if (rows != null) {
            contents = new ContentDTO[rows.length];
            // Get the infomation from the result set
            for (int i = 0; i < rows.length; i++) {
                ResultSetRow row = (ResultSetRow) rows[i];
                String nodeId = row.getNode().getId();
                ContentDTO content = new ContentDTO();
                content.setUid(nodeId);
                for (NamedValue namedValue : row.getColumns()) {
                    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());
                    }
                }
                contents[i] = content;
            // results.add(contentResult);
            }
        }
    } 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 contents;
}
Also used : Query(org.alfresco.webservice.types.Query) ParentReference(org.alfresco.webservice.types.ParentReference) Reference(org.alfresco.webservice.types.Reference) Node(org.alfresco.webservice.types.Node) ResultSetRow(org.alfresco.webservice.types.ResultSetRow) NamedValue(org.alfresco.webservice.types.NamedValue) Predicate(org.alfresco.webservice.types.Predicate) ContentDTO(com.tomasio.projects.trainning.dto.ContentDTO) QueryResult(org.alfresco.webservice.repository.QueryResult) RepositoryFault(org.alfresco.webservice.repository.RepositoryFault) RepositoryServiceSoapBindingStub(org.alfresco.webservice.repository.RepositoryServiceSoapBindingStub) ResultSet(org.alfresco.webservice.types.ResultSet) AuthenticationFault(org.alfresco.webservice.authentication.AuthenticationFault) RemoteException(java.rmi.RemoteException)

Example 5 with NamedValue

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

the class AlfrescoContentDAO method findAllContentByUUID.

@Override
public ContentDTO[] findAllContentByUUID(String uuid) {
    ContentDTO[] contents = null;
    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));
        // Create a query object, looking for all items with alfresco in the
        // name of text
        Query query = new Query(Constants.QUERY_LANG_LUCENE, "+PARENT:\"workspace://SpacesStore/" + nodes[0].getReference().getUuid() + "\"");
        // Execute the query
        QueryResult queryResult = repositoryService.query(STORE, query, false);
        // Display the results
        ResultSet resultSet = queryResult.getResultSet();
        ResultSetRow[] rows = resultSet.getRows();
        if (rows != null) {
            contents = new ContentDTO[rows.length];
            // Get the infomation from the result set
            for (int i = 0; i < rows.length; i++) {
                ResultSetRow row = (ResultSetRow) rows[i];
                String nodeId = row.getNode().getId();
                ContentDTO content = new ContentDTO();
                content.setUid(nodeId);
                for (NamedValue namedValue : row.getColumns()) {
                    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());
                    }
                }
                contents[i] = content;
            // results.add(contentResult);
            }
        }
    } 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 contents;
}
Also used : Query(org.alfresco.webservice.types.Query) ParentReference(org.alfresco.webservice.types.ParentReference) Reference(org.alfresco.webservice.types.Reference) Node(org.alfresco.webservice.types.Node) ResultSetRow(org.alfresco.webservice.types.ResultSetRow) NamedValue(org.alfresco.webservice.types.NamedValue) Predicate(org.alfresco.webservice.types.Predicate) ContentDTO(com.tomasio.projects.trainning.dto.ContentDTO) QueryResult(org.alfresco.webservice.repository.QueryResult) RepositoryFault(org.alfresco.webservice.repository.RepositoryFault) RepositoryServiceSoapBindingStub(org.alfresco.webservice.repository.RepositoryServiceSoapBindingStub) ResultSet(org.alfresco.webservice.types.ResultSet) AuthenticationFault(org.alfresco.webservice.authentication.AuthenticationFault) RemoteException(java.rmi.RemoteException)

Aggregations

RemoteException (java.rmi.RemoteException)11 AuthenticationFault (org.alfresco.webservice.authentication.AuthenticationFault)11 RepositoryFault (org.alfresco.webservice.repository.RepositoryFault)11 NamedValue (org.alfresco.webservice.types.NamedValue)11 Reference (org.alfresco.webservice.types.Reference)11 ParentReference (org.alfresco.webservice.types.ParentReference)9 Predicate (org.alfresco.webservice.types.Predicate)7 RepositoryServiceSoapBindingStub (org.alfresco.webservice.repository.RepositoryServiceSoapBindingStub)6 Node (org.alfresco.webservice.types.Node)6 ContentServiceSoapBindingStub (org.alfresco.webservice.content.ContentServiceSoapBindingStub)5 CML (org.alfresco.webservice.types.CML)5 UpdateResult (org.alfresco.webservice.repository.UpdateResult)4 CMLAddAspect (org.alfresco.webservice.types.CMLAddAspect)4 CMLCreate (org.alfresco.webservice.types.CMLCreate)4 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 Query (org.alfresco.webservice.types.Query)3