Search in sources :

Example 6 with DocumentDTO

use of com.tomasio.projects.trainning.dto.DocumentDTO in project trainning by fernandotomasio.

the class TurmasEfetivasController method saveCertificado.

@RequestMapping("/save_certificado")
public String saveCertificado(Model model, @Valid CertificadoConclusaoForm certificado, BindingResult bindingResult, @RequestParam(value = "file", required = false) MultipartFile file, WebRequest request, final RedirectAttributes redirectAttributes) {
    String folderId = "614fca6b-f633-4430-a810-74096b460518";
    String folderName = "Certificados";
    String documentsRoot = "SGC/Certificados";
    if (bindingResult.hasErrors()) {
        return "turmas_efetivas/form_certificado";
    }
    SimpleDateFormat df = new SimpleDateFormat("dd/MM/yyyy");
    ConclusaoDTO conclusao = atividadesEnsinoService.findConclusao(Long.parseLong(certificado.getConclusaoId()));
    CertificadoConclusaoDTO certificadoDTO = new CertificadoConclusaoDTO();
    certificadoDTO.setNumero(certificado.getNumero());
    try {
        certificadoDTO.setDataEmissao(df.parse(certificado.getDataEmissao()));
    } catch (ParseException ex) {
        Logger.getLogger(TurmasEfetivasController.class.getName()).log(Level.SEVERE, null, ex);
    }
    certificadoDTO.setObservacao(certificado.getObservacao());
    certificadoDTO.setConclusao(conclusao);
    if (!file.isEmpty()) {
        DocumentDTO dto = new DocumentDTO();
        dto.setTitle("Certificado Nº " + certificado.getNumero());
        dto.setDescription("Certificado Nº " + certificado.getNumero() + " Do aluno Matricula: " + conclusao.getMatricula() + " Emitido na data: " + certificado.getDataEmissao() + " Com a seguinte Observação: " + certificado.getObservacao());
        dto.setName(file.getOriginalFilename());
        dto.setMimeType(file.getContentType());
        try {
            byte[] content = file.getBytes();
            dto.setContentStream(content);
        } catch (IOException ex) {
            Logger.getLogger(TurmasEfetivasController.class.getName()).log(Level.SEVERE, null, ex);
        }
        String contentId = ecmService.createDocumentWithUUIDParent(dto, folderId);
        if (contentId == null || contentId.equals("")) {
            // erro certificado não upload
            redirectAttributes.addFlashAttribute("errorMessage", "Nao foi possível fazer o UPLOAD no Arquivo do Certificado!");
        } else {
            certificadoDTO.setContentId(contentId);
        }
        // gravar o certificado no BD
        try {
            atividadesEnsinoService.createCertificadoConclusao(certificadoDTO);
            redirectAttributes.addFlashAttribute("successMessage", "Certificado de Conclusão cadastrado com sucesso.");
        } catch (CoreException e) {
            redirectAttributes.addFlashAttribute("errorMessage", e.getMessage());
        }
    }
    model.addAttribute("tab", "certificados");
    return "redirect:detail/certificados";
}
Also used : CertificadoConclusaoDTO(com.tomasio.projects.trainning.dto.CertificadoConclusaoDTO) CoreException(com.tomasio.projects.trainning.exeption.CoreException) CertificadoConclusaoDTO(com.tomasio.projects.trainning.dto.CertificadoConclusaoDTO) ConclusaoDTO(com.tomasio.projects.trainning.dto.ConclusaoDTO) DocumentDTO(com.tomasio.projects.trainning.dto.DocumentDTO) ParseException(java.text.ParseException) IOException(java.io.IOException) SimpleDateFormat(java.text.SimpleDateFormat) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 7 with DocumentDTO

use of com.tomasio.projects.trainning.dto.DocumentDTO in project trainning by fernandotomasio.

the class ECMServiceSimpleImpl method findDocumentByUUID.

@Override
public DocumentDTO findDocumentByUUID(String uuid) {
    ContentDAO dao = factory.getContentDAO();
    DocumentDTO document = dao.findDocumentByUUID(uuid);
    return document;
}
Also used : DocumentDTO(com.tomasio.projects.trainning.dto.DocumentDTO) ContentDAO(com.tomasio.projects.trainning.dao.ContentDAO)

Example 8 with DocumentDTO

use of com.tomasio.projects.trainning.dto.DocumentDTO in project trainning by fernandotomasio.

the class ImportTurmasImplEfetivasFromTabelao method recuperarDocumentos.

private void recuperarDocumentos(String codCurso, String numeroTurma, TurmaEfetiva turmaCriada, Connection conn) {
    SimpleDateFormat df = new SimpleDateFormat("yyyy");
    ContentDAO contentDAO = new AlfrescoContentDAO();
    TurmaDAO turmaDAO = new HibernateTurmaDAO();
    String documentsRoot = "SGC/Documentos de Treinamentos/testes";
    String oldFolderName = "D-CTP/Documentos de Treinamentos/2013/" + codCurso + "-" + numeroTurma;
    String newFolderName = df.format(turmaCriada.getExercicio()) + "_" + turmaCriada.getCurso().getCodigo() + "_" + turmaCriada.getNumeroTurma() + "_" + turmaCriada.getId();
    try {
        WebServiceFactory.setEndpointAddress("http://dctp.decea.intraer:8080/ecm/api");
        boolean existsOldFolder = contentExistsByPath(oldFolderName);
        if (existsOldFolder) {
            WebServiceFactory.setEndpointAddress("http://10.32.63.32:8080/alfresco/api");
            FolderDTO folder = new FolderDTO();
            folder.setName(newFolderName);
            String folderId = contentDAO.createFolder(folder, documentsRoot);
            turmaCriada.setFolderId(folderId);
            turmaDAO.update(turmaCriada);
            WebServiceFactory.setEndpointAddress("http://dctp.decea.intraer:8080/ecm/api");
            ContentDTO[] contents = findAllContentByPath(oldFolderName);
            for (ContentDTO content : contents) {
                WebServiceFactory.setEndpointAddress("http://dctp.decea.intraer:8080/ecm/api");
                DocumentDTO document = findDocumentByUUID(content.getUid());
                document.setMimeType("application/pdf");
                WebServiceFactory.setEndpointAddress("http://10.32.63.32:8080/alfresco/api");
                contentDAO.createDocumentWithUUIDParent(document, folderId);
            }
        }
    } catch (Exception ex) {
        Logger.getLogger(ImportTurmasImplEfetivasFromTabelao.class.getName()).log(Level.SEVERE, null, ex);
    }
}
Also used : ParseException(java.text.ParseException) RemoteException(java.rmi.RemoteException) DAOException(com.tomasio.projects.trainning.exception.DAOException) ContentDAO(com.tomasio.projects.trainning.dao.ContentDAO) AlfrescoContentDAO(com.tomasio.projects.trainning.dao.AlfrescoContentDAO) ContentDTO(com.tomasio.projects.trainning.dto.ContentDTO) FolderDTO(com.tomasio.projects.trainning.dto.FolderDTO) HibernateTurmaDAO(com.tomasio.projects.trainning.dao.HibernateTurmaDAO) DocumentDTO(com.tomasio.projects.trainning.dto.DocumentDTO) AlfrescoContentDAO(com.tomasio.projects.trainning.dao.AlfrescoContentDAO) HibernateTurmaDAO(com.tomasio.projects.trainning.dao.HibernateTurmaDAO) TurmaDAO(com.tomasio.projects.trainning.dao.TurmaDAO) SimpleDateFormat(java.text.SimpleDateFormat)

Example 9 with DocumentDTO

use of com.tomasio.projects.trainning.dto.DocumentDTO 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 10 with DocumentDTO

use of com.tomasio.projects.trainning.dto.DocumentDTO in project trainning by fernandotomasio.

the class Main method main.

public static void main(String[] args) throws Exception {
    // WebServiceFactory.setEndpointAddress("http://localhost:8084/alfresco/api");
    ContentDAO service = new AlfrescoContentDAO();
    DocumentDTO content = service.findDocumentSWFByUUID("6c8c1aad-79f6-46ce-a6f6-2380f7341271");
    OutputStream out = new FileOutputStream("DOCUMENT.pdf");
    out.write(content.getContentStream());
    out.close();
// DocumentDTO document = new DocumentDTO();
// FolderDTO folder = new FolderDTO();
// 
// document.setDescription("Description");
// document.setTitle("Title");
// document.setName("meusteste5s5.pdf");
// document.setMimeType("application/pdf");
// document.setCharset("UTF-8");
// 
// 
// InputStream viewStream = new FileInputStream(new File("/home/fernandofot/identidade.pdf"));
// byte[] bytes = org.apache.commons.io.IOUtils.toByteArray(viewStream);
// 
// document.setContentStream(bytes);
// 
// ContentDTO [] contents = service.findAllContentByPath("D-CTP");
// for(ContentDTO content: contents){
// System.out.println(content.getTitle());
// }
// service.addDocumentToTreinamento(document,"COMGAR", "2018", "AP005", "2");
// Open the file and convert to byte array
// 
// 
// folder.setDescription("My description folder");
// folder.setName("CTP001-3");
// folder.setTitle("Minha Linda Pasta");
// 
// 
// 
// 
// 
// ECMService service = new AlfrescoECMService();
// 
// ContentDTO content = service.findDocumentoByUUID("5e587e0b-f0ca-4264-abdc-dc791197b7f7");
// content.setName("new_name.pdf");
// content.setTitle("New Title");
// content.setDescription("New Description");
// DocumentDTO documento = (DocumentDTO) content;
// System.out.println(documento.getContentStream().length);
// ContentDTO [] docs = service.findDocumentosByTreinamento("CTP004", "5", "2015");
// for (ContentDTO documentDTO : docs) {
// System.out.println(documentDTO.getName());
// }
// ContentDTO [] documentos = service.findDocumentosByTreinamento("TEL007", "1", "2017");
// 
// for (ContentDTO contentDTO : documentos) {
// System.out.println(contentDTO.getName());
// }
// String uid = service.createDocument(document, "D-CTP/Documentos de Treinamentos/CTP001-3");
// System.out.println(uid);
// String uid = service.createFolder(folder, "D-CTP/Documentos de Treinamentos");
// System.out.println(uuid);
// service.findContentByUUID(uid);
// System.out.println(service.contentExistsByPath("D-CTP/Documentos de Treinamentos"));
}
Also used : OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) FileOutputStream(java.io.FileOutputStream) DocumentDTO(com.tomasio.projects.trainning.dto.DocumentDTO) AlfrescoContentDAO(com.tomasio.projects.trainning.dao.AlfrescoContentDAO) ContentDAO(com.tomasio.projects.trainning.dao.ContentDAO) AlfrescoContentDAO(com.tomasio.projects.trainning.dao.AlfrescoContentDAO)

Aggregations

DocumentDTO (com.tomasio.projects.trainning.dto.DocumentDTO)16 SimpleDateFormat (java.text.SimpleDateFormat)5 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)5 ContentDAO (com.tomasio.projects.trainning.dao.ContentDAO)4 IOException (java.io.IOException)4 RemoteException (java.rmi.RemoteException)4 AlfrescoContentDAO (com.tomasio.projects.trainning.dao.AlfrescoContentDAO)3 ParseException (java.text.ParseException)3 AuthenticationFault (org.alfresco.webservice.authentication.AuthenticationFault)3 Content (org.alfresco.webservice.content.Content)3 ContentServiceSoapBindingStub (org.alfresco.webservice.content.ContentServiceSoapBindingStub)3 RepositoryFault (org.alfresco.webservice.repository.RepositoryFault)3 RepositoryServiceSoapBindingStub (org.alfresco.webservice.repository.RepositoryServiceSoapBindingStub)3 NamedValue (org.alfresco.webservice.types.NamedValue)3 Node (org.alfresco.webservice.types.Node)3 Predicate (org.alfresco.webservice.types.Predicate)3 Reference (org.alfresco.webservice.types.Reference)3 CurriculoMinimoDTO (com.tomasio.projects.trainning.dto.CurriculoMinimoDTO)2 FolderDTO (com.tomasio.projects.trainning.dto.FolderDTO)2 DAOException (com.tomasio.projects.trainning.exception.DAOException)2