Creating folder structure

Hello everyone I have the following senary: I am migrating a data / files (blob) from a SQL Server database to nuxeo. These files should be in the following structure:

   --- Folder (document type)
        --- folder (year of document)
             --- file (attached document)

THERE WILL BE ARCHIVES OF THE SAME TYPE OF DOCUMENT AND SAME YEAR When I do the select in the database it has already me behind all this information, now what I need is to develop in Java this structure in nuxeo. I've done almost any structure so I'm not sure how to compare folders. Example:

If FOLDER 01 does not exist it must create it if it already exists it must save the file in it In the check that I'm doing, it will fill the folder that already exists.

HOW DO I DO THAT??????????

I'm using:

  • NUXEO 8.10
    • JAVA 8

WHEN I'M WITH MY OBJECT LOADED I CALL THE FOLLOWING METHODS

private void folder1(ArquivoTeorMigracao migracao)
            throws IOException, NuxeoClientException {

        Document doc = new Document("folder", "Folder");
        try {
            doc = nuxeoClient.repository().fetchDocumentByPath(
                    "/camara.leg/workspaces/infoleg/ArquivoTeor/" + migracao.getTxtSiglaTipoProposicao());
            folder2(migracao, doc);

        } catch (NuxeoClientException ex) {
            if (ex.getStatus() == 404) {
                doc.set("dc:title", migracao.getTxtSiglaTipoProposicao());
                doc = nuxeoClient.repository().createDocumentByPath("/camara.leg/workspaces/infoleg/ArquivoTeor/", doc);
                folder2(migracao, doc);
            }
        }
    }

    private void folder2(ArquivoTeorMigracao migracao, Document document)
            throws IOException, NuxeoClientException {

        Document doc = new Document("folder", "Folder");
        try {

            doc = nuxeoClient.repository().fetchDocumentByPath(document.getPath() + "/" + migracao.getNumAno());
            salveDoc(migracao, doc);

        } catch (NuxeoClientException ex) {
            if (ex.getStatus() == 404) {
                doc.set("dc:title", migracao.getNumAno());
                doc = nuxeoClient.repository().createDocumentByPath(document.getPath() + "/", doc);
                salveDoc(migracao, doc);
            }
        }
    }

    private void salveDoc(ArquivoTeorMigracao migracao, Document document)
            throws IOException, FileNotFoundException, PropertyNotFoundException {
        Document doc = new Document("file", "File");
        doc.set("dc:title", migracao.getTxtDescricaoTipoProposicao());
        doc.set("dc:name", migracao.getTxtNomeArquivo());
        doc.set("dc:type", migracao.getTxtTipoDocumento());
        doc = nuxeoClient.repository().createDocumentByPath(document.getPath() + "/", doc);

        Document docCriado = nuxeoClient.repository().fetchDocumentByPath(doc.getPath());

        String nomeArquivoFormatado = migracao.getTxtNomeArquivo().substring(0,
                migracao.getTxtNomeArquivo().lastIndexOf("."));
        String tipoDocFormatado = "." + migracao.getTxtTipoDocumento().toLowerCase();

        File file = criarTempFile(nomeArquivoFormatado, tipoDocFormatado);
        Files.write(file.toPath(), migracao.getImgArquivoTeor());
        file.deleteOnExit();

        Blob fileBlob = new Blob(file);
        fileBlob = nuxeoClient.automation().newRequest("Blob.AttachOnDocument").param("document", docCriado)
                .input(fileBlob).execute();

        Blob resultBlob = nuxeoClient.automation().input(docCriado).execute("Document.GetBlob");
        System.out.println(resultBlob);
    }

    public File criarTempFile(String prefix, String suffix) {
        String tempDir = System.getProperty("java.io.tmpdir");
        String fileName = (prefix != null ? prefix : "") + (suffix != null ? suffix : "");
        return new File(tempDir, fileName);
    }
0 votes

0 answers

3944 views

ANSWER

??????????????
04/06/2017