Search in sources :

Example 1 with FolderDTO

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

the class TurmasEfetivasController method saveDocumento.

@RequestMapping("/save_documento")
public String saveDocumento(Model model, @Valid Documento documento, BindingResult bindingResult, @RequestParam(value = "file", required = false) MultipartFile file, WebRequest request) {
    SimpleDateFormat df = new SimpleDateFormat("yyyy");
    String turmaId = request.getParameter("turmaId");
    TurmaEfetivaDTO turma = atividadesEnsinoService.findTurmaEfetiva(Long.parseLong(turmaId));
    String folderId = turma.getFolderId();
    String folderName = df.format(turma.getExercicio()) + "_" + turma.getCurso().getCodigo() + "_" + turma.getNumeroTurma() + "_" + turma.getId();
    String documentsRoot = "SGC/Documentos de Treinamentos";
    if (bindingResult.hasErrors()) {
        return "turmas_efetivas/form_documento";
    }
    if (!file.isEmpty()) {
        DocumentDTO dto = new DocumentDTO();
        dto.setTitle(documento.getTitle());
        dto.setDescription(documento.getDescription());
        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);
        }
        if (folderId == null || folderId.equals("")) {
            FolderDTO folder = new FolderDTO();
            folder.setName(folderName);
            folderId = ecmService.createFolder(folder, documentsRoot);
            turma.setFolderId(folderId);
            atividadesEnsinoService.updateTurmaEfetiva(turma);
            model.addAttribute("turma", turma);
            ecmService.createDocumentWithUUIDParent(dto, folderId);
        } else {
            boolean folderExists = ecmService.contentExistsByUUID(folderId);
            if (folderExists) {
                ecmService.createDocumentWithUUIDParent(dto, folderId);
            } else {
                FolderDTO folder = new FolderDTO();
                folder.setName(folderName);
                folderId = ecmService.createFolder(folder, documentsRoot);
                turma.setFolderId(folderId);
                atividadesEnsinoService.updateTurmaEfetiva(turma);
                model.addAttribute("turma", turma);
                ecmService.createDocumentWithUUIDParent(dto, folderId);
            }
        }
    }
    model.addAttribute("tab", "documentos");
    return "redirect:detail/documentos";
}
Also used : TurmaEfetivaDTO(com.tomasio.projects.trainning.dto.TurmaEfetivaDTO) FolderDTO(com.tomasio.projects.trainning.dto.FolderDTO) DocumentDTO(com.tomasio.projects.trainning.dto.DocumentDTO) IOException(java.io.IOException) SimpleDateFormat(java.text.SimpleDateFormat) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 2 with FolderDTO

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

the class TeachingDocumentsServiceSimpleImpl method createApostila.

@Override
@Transactional
@SuppressWarnings({ "BroadCatchBlock", "TooBroadCatch" })
public Long createApostila(ApostilaDTO apostila) {
    ApostilaDAO dao = factory.getApostilaDAO();
    ContentDAO contentDAO = factory.getContentDAO();
    String documentsRoot = "SGC/Material Didático/Apostilas";
    Apostila model = new Apostila(apostila);
    Long id = null;
    try {
        id = dao.create(model);
        model = dao.find(id);
        String folderName = apostila.getDisciplina().getCurriculoMinimo().getCurso().getCodigo() + "_" + model.getId() + "_" + apostila.getDisciplina().getNumeroGeral() + "_" + apostila.getDisciplina().getDescricao();
        String finalPath = documentsRoot + "/" + folderName;
        if (contentDAO.contentExistsByPath(finalPath) == false) {
            FolderDTO folder = new FolderDTO();
            folder.setName(folderName);
            String folderId = contentDAO.createFolder(folder, documentsRoot);
            FolderDTO assetsFolder = new FolderDTO();
            assetsFolder.setName("assets");
            String assetsFolderId = contentDAO.createFolderWithUUIDParent(assetsFolder, folderId);
            model.setAssetsFolderId(assetsFolderId);
            model.setFolderId(folderId);
            dao.update(model);
        }
    } catch (DAOException ex) {
        throw new CoreException("Erro de de acesso ao banco de dados: " + ex.getMessage());
    } catch (Exception ex) {
        throw new CoreException("Erro de sistema: " + ex.getMessage());
    }
    return id;
}
Also used : DAOException(com.tomasio.projects.trainning.exception.DAOException) FolderDTO(com.tomasio.projects.trainning.dto.FolderDTO) CoreException(com.tomasio.projects.trainning.exeption.CoreException) AnexoApostila(com.tomasio.projects.trainning.model.AnexoApostila) Apostila(com.tomasio.projects.trainning.model.Apostila) CapituloApostila(com.tomasio.projects.trainning.model.CapituloApostila) SecaoApostila(com.tomasio.projects.trainning.model.SecaoApostila) CoreException(com.tomasio.projects.trainning.exeption.CoreException) DAOException(com.tomasio.projects.trainning.exception.DAOException) Transactional(org.springframework.transaction.annotation.Transactional)

Example 3 with FolderDTO

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

the class TeachingDocumentsServiceSimpleImpl method createSecaoApostila.

@Override
@Transactional
@SuppressWarnings({ "BroadCatchBlock", "TooBroadCatch" })
public Long createSecaoApostila(SecaoApostilaDTO secao) {
    SecaoApostilaDAO dao = factory.getSecaoApostilaDAO();
    ContentDAO contentDAO = factory.getContentDAO();
    CapituloApostilaDAO capituloDAO = factory.getCapituloApostilaDAO();
    ApostilaDAO apostilaDAO = factory.getApostilaDAO();
    SecaoApostila model = new SecaoApostila(secao);
    Long id = null;
    try {
        id = dao.create(model);
        model = dao.find(id);
        String folderName = String.valueOf(model.getId());
        CapituloApostila capitulo = capituloDAO.find(model.getCapituloApostila().getId());
        Apostila apostila = apostilaDAO.find(capitulo.getApostila().getId());
        FolderDTO folder = new FolderDTO();
        folder.setName(folderName);
        String assetsFolderId = contentDAO.createFolderWithUUIDParent(folder, apostila.getAssetsFolderId());
        model.setAssetsFolderId(assetsFolderId);
        dao.update(model);
    } catch (DAOException ex) {
        throw new CoreException("Erro de de acesso ao banco de dados: " + ex.getMessage());
    } catch (Exception ex) {
        throw new CoreException("Erro de sistema: " + ex.getMessage());
    }
    return id;
}
Also used : SecaoApostila(com.tomasio.projects.trainning.model.SecaoApostila) CapituloApostila(com.tomasio.projects.trainning.model.CapituloApostila) AnexoApostila(com.tomasio.projects.trainning.model.AnexoApostila) Apostila(com.tomasio.projects.trainning.model.Apostila) CapituloApostila(com.tomasio.projects.trainning.model.CapituloApostila) SecaoApostila(com.tomasio.projects.trainning.model.SecaoApostila) CoreException(com.tomasio.projects.trainning.exeption.CoreException) DAOException(com.tomasio.projects.trainning.exception.DAOException) DAOException(com.tomasio.projects.trainning.exception.DAOException) FolderDTO(com.tomasio.projects.trainning.dto.FolderDTO) CoreException(com.tomasio.projects.trainning.exeption.CoreException) Transactional(org.springframework.transaction.annotation.Transactional)

Example 4 with FolderDTO

use of com.tomasio.projects.trainning.dto.FolderDTO 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)

Aggregations

FolderDTO (com.tomasio.projects.trainning.dto.FolderDTO)4 DAOException (com.tomasio.projects.trainning.exception.DAOException)3 DocumentDTO (com.tomasio.projects.trainning.dto.DocumentDTO)2 CoreException (com.tomasio.projects.trainning.exeption.CoreException)2 AnexoApostila (com.tomasio.projects.trainning.model.AnexoApostila)2 Apostila (com.tomasio.projects.trainning.model.Apostila)2 CapituloApostila (com.tomasio.projects.trainning.model.CapituloApostila)2 SecaoApostila (com.tomasio.projects.trainning.model.SecaoApostila)2 SimpleDateFormat (java.text.SimpleDateFormat)2 Transactional (org.springframework.transaction.annotation.Transactional)2 AlfrescoContentDAO (com.tomasio.projects.trainning.dao.AlfrescoContentDAO)1 ContentDAO (com.tomasio.projects.trainning.dao.ContentDAO)1 HibernateTurmaDAO (com.tomasio.projects.trainning.dao.HibernateTurmaDAO)1 TurmaDAO (com.tomasio.projects.trainning.dao.TurmaDAO)1 ContentDTO (com.tomasio.projects.trainning.dto.ContentDTO)1 TurmaEfetivaDTO (com.tomasio.projects.trainning.dto.TurmaEfetivaDTO)1 IOException (java.io.IOException)1 RemoteException (java.rmi.RemoteException)1 ParseException (java.text.ParseException)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1