Search in sources :

Example 6 with StorageObject

use of it.cnr.si.spring.storage.StorageObject in project sigla-main by consiglionazionaledellericerche.

the class CRUDRichiestaUopBP method scaricaAllegato.

public void scaricaAllegato(ActionContext actioncontext) throws IOException, ServletException, ApplicationException {
    AllegatoRichiestaBulk allegato = (AllegatoRichiestaBulk) getCrudArchivioAllegati().getModel();
    StorageObject storageObject = richiesteCMISService.getStorageObjectBykey(allegato.getStorageKey());
    InputStream is = richiesteCMISService.getResource(storageObject.getKey());
    ((HttpActionContext) actioncontext).getResponse().setContentLength(storageObject.<BigInteger>getPropertyValue(StoragePropertyNames.CONTENT_STREAM_LENGTH.value()).intValue());
    ((HttpActionContext) actioncontext).getResponse().setContentType(storageObject.getPropertyValue(StoragePropertyNames.CONTENT_STREAM_MIME_TYPE.value()));
    OutputStream os = ((HttpActionContext) actioncontext).getResponse().getOutputStream();
    ((HttpActionContext) actioncontext).getResponse().setDateHeader("Expires", 0);
    byte[] buffer = new byte[((HttpActionContext) actioncontext).getResponse().getBufferSize()];
    int buflength;
    while ((buflength = is.read(buffer)) > 0) {
        os.write(buffer, 0, buflength);
    }
    is.close();
    os.flush();
}
Also used : StorageObject(it.cnr.si.spring.storage.StorageObject) AllegatoRichiestaBulk(it.cnr.contab.ordmag.richieste.bulk.AllegatoRichiestaBulk) BigInteger(java.math.BigInteger)

Example 7 with StorageObject

use of it.cnr.si.spring.storage.StorageObject in project sigla-main by consiglionazionaledellericerche.

the class CRUDRichiestaUopBP method scaricaDocumentoDettaglioCollegato.

public void scaricaDocumentoDettaglioCollegato(ActionContext actioncontext) throws Exception {
    AllegatoRichiestaDettaglioBulk dettaglio = (AllegatoRichiestaDettaglioBulk) getDettaglioAllegatiController().getModel();
    if (dettaglio != null) {
        StorageObject storageObject = richiesteCMISService.getStorageObjectBykey(dettaglio.getStorageKey());
        InputStream is = richiesteCMISService.getResource(storageObject.getKey());
        ((HttpActionContext) actioncontext).getResponse().setContentLength(storageObject.<BigInteger>getPropertyValue(StoragePropertyNames.CONTENT_STREAM_LENGTH.value()).intValue());
        ((HttpActionContext) actioncontext).getResponse().setContentType(storageObject.getPropertyValue(StoragePropertyNames.CONTENT_STREAM_MIME_TYPE.value()));
        OutputStream os = ((HttpActionContext) actioncontext).getResponse().getOutputStream();
        ((HttpActionContext) actioncontext).getResponse().setDateHeader("Expires", 0);
        byte[] buffer = new byte[((HttpActionContext) actioncontext).getResponse().getBufferSize()];
        int buflength;
        while ((buflength = is.read(buffer)) > 0) {
            os.write(buffer, 0, buflength);
        }
        is.close();
        os.flush();
    } else {
        throw new it.cnr.jada.action.MessageToUser("Documenti non presenti sul documentale per la riga selezionata");
    }
}
Also used : AllegatoRichiestaDettaglioBulk(it.cnr.contab.ordmag.richieste.bulk.AllegatoRichiestaDettaglioBulk) StorageObject(it.cnr.si.spring.storage.StorageObject) BigInteger(java.math.BigInteger)

Example 8 with StorageObject

use of it.cnr.si.spring.storage.StorageObject in project sigla-main by consiglionazionaledellericerche.

the class DistintaCassiereComponent method generaFlussoSiopeplus.

public StorageObject generaFlussoSiopeplus(UserContext userContext, Distinta_cassiereBulk distinta) throws ComponentException, RemoteException {
    try {
        final DocumentiContabiliService documentiContabiliService = SpringUtil.getBean("documentiContabiliService", DocumentiContabiliService.class);
        DateTimeFormatter formatterTime = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss");
        JAXBContext jc = JAXBContext.newInstance("it.siopeplus");
        // creo i file del flusso
        // Testata
        final ObjectFactory objectFactory = new ObjectFactory();
        it.siopeplus.FlussoOrdinativi currentFlusso = objectFactory.createFlussoOrdinativi();
        Configurazione_cnrComponentSession sess = (Configurazione_cnrComponentSession) it.cnr.jada.util.ejb.EJBCommonServices.createEJB("CNRCONFIG00_EJB_Configurazione_cnrComponentSession");
        String codiceAbi = Optional.ofNullable(sess.getVal01(userContext, CNRUserContext.getEsercizio(userContext), null, Configurazione_cnrBulk.PK_FLUSSO_ORDINATIVI, Configurazione_cnrBulk.SK_CODICE_ABI_BT)).orElseThrow(() -> new ApplicationException("Configurazione mancante per flusso Ordinativo [CODICE_ABI_BT]"));
        String codiceA2A = Optional.ofNullable(sess.getVal01(userContext, CNRUserContext.getEsercizio(userContext), null, Configurazione_cnrBulk.PK_FLUSSO_ORDINATIVI, Configurazione_cnrBulk.SK_CODICE_A2A)).orElseThrow(() -> new ApplicationException("Configurazione mancante per flusso Ordinativo [CODICE_A2A]"));
        String codiceEnte = Optional.ofNullable(sess.getVal01(userContext, CNRUserContext.getEsercizio(userContext), null, Configurazione_cnrBulk.PK_FLUSSO_ORDINATIVI, Configurazione_cnrBulk.SK_CODICE_ENTE)).orElseThrow(() -> new ApplicationException("Configurazione mancante per flusso Ordinativo [CODICE_ENTE]"));
        String codiceEnteBT = Optional.ofNullable(sess.getVal01(userContext, CNRUserContext.getEsercizio(userContext), null, Configurazione_cnrBulk.PK_FLUSSO_ORDINATIVI, Configurazione_cnrBulk.SK_CODICE_ENTE_BT)).orElseThrow(() -> new ApplicationException("Configurazione mancante per flusso Ordinativo [CODICE_ENTE_BT]"));
        String codiceTramiteBT = Optional.ofNullable(sess.getVal01(userContext, CNRUserContext.getEsercizio(userContext), null, Configurazione_cnrBulk.PK_FLUSSO_ORDINATIVI, Configurazione_cnrBulk.SK_CODICE_TRAMITE_BT)).orElseThrow(() -> new ApplicationException("Configurazione mancante per flusso Ordinativo [CODICE_TRAMITE_BT]"));
        String codiceIstatEnte = Optional.ofNullable(sess.getVal01(userContext, CNRUserContext.getEsercizio(userContext), null, Configurazione_cnrBulk.PK_FLUSSO_ORDINATIVI, Configurazione_cnrBulk.SK_CODICE_ISTAT_ENTE)).orElseThrow(() -> new ApplicationException("Configurazione mancante per flusso Ordinativo [CODICE_ISTAT_ENTE]"));
        final CtTestataFlusso testataFlusso = objectFactory.createCtTestataFlusso();
        testataFlusso.setCodiceABIBT(codiceAbi);
        testataFlusso.setRiferimentoEnte(codiceA2A);
        testataFlusso.setIdentificativoFlusso(distinta.getIdentificativoFlusso());
        testataFlusso.setDataOraCreazioneFlusso(DatatypeFactory.newInstance().newXMLGregorianCalendar(formatterTime.format(it.cnr.jada.util.ejb.EJBCommonServices.getServerTimestamp().toLocalDateTime())));
        testataFlusso.setCodiceEnte(codiceEnte);
        testataFlusso.setCodiceEnteBT(codiceEnteBT);
        testataFlusso.setCodiceTramiteEnte(codiceA2A);
        testataFlusso.setCodiceTramiteBT(codiceTramiteBT);
        AnagraficoComponentSession component = (AnagraficoComponentSession) it.cnr.jada.util.ejb.EJBCommonServices.createEJB("CNRANAGRAF00_EJB_AnagraficoComponentSession");
        AnagraficoBulk uoEnte = component.getAnagraficoEnte(userContext);
        testataFlusso.setDescrizioneEnte(uoEnte.getRagione_sociale());
        testataFlusso.setCodiceIstatEnte(codiceIstatEnte);
        testataFlusso.setCodiceFiscaleEnte(uoEnte.getCodice_fiscale());
        currentFlusso.getContent().add(objectFactory.createTestataFlusso(testataFlusso));
        currentFlusso.getContent().add(objectFactory.createEsercizio(CNRUserContext.getEsercizio(userContext)));
        List dettagliRev = dettagliDistinta(userContext, distinta, it.cnr.contab.doccont00.core.bulk.Numerazione_doc_contBulk.TIPO_REV);
        // Elaboriamo prima le reversali
        Reversale currentReversale = null;
        for (Iterator i = dettagliRev.iterator(); i.hasNext(); ) {
            V_mandato_reversaleBulk bulk = (V_mandato_reversaleBulk) i.next();
            currentFlusso.getContent().add(objectFactory.createReversale(creaReversaleFlussoSiopeplus(userContext, bulk)));
        }
        List dettagliMan = dettagliDistinta(userContext, distinta, it.cnr.contab.doccont00.core.bulk.Numerazione_doc_contBulk.TIPO_MAN);
        // Mandati
        Mandato currentMandato = null;
        for (Iterator i = dettagliMan.iterator(); i.hasNext(); ) {
            V_mandato_reversaleBulk bulk = (V_mandato_reversaleBulk) i.next();
            currentFlusso.getContent().add(objectFactory.createMandato(creaMandatoFlussoSiopeplus(userContext, bulk)));
        }
        ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
        Marshaller jaxbMarshaller = jc.createMarshaller();
        jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.FALSE);
        jaxbMarshaller.marshal(currentFlusso, byteArrayOutputStream);
        // FIX per firma xml
        String out = new String(byteArrayOutputStream.toByteArray(), StandardCharsets.UTF_8);
        out = out.replace("</flusso_ordinativi>", "\n</flusso_ordinativi>");
        StorageFile storageFile = new StorageFile(out.getBytes(StandardCharsets.UTF_8), MimeTypes.XML.mimetype(), distinta.getFileNameXML());
        final StorageObject storageObject = documentiContabiliService.getStorageObjectBykey(documentiContabiliService.restoreSimpleDocument(storageFile, new ByteArrayInputStream(storageFile.getBytes()), storageFile.getContentType(), storageFile.getFileName(), distinta.getStorePath(), true).getKey());
        final BigInteger dimension = storageObject.<BigInteger>getPropertyValue(StoragePropertyNames.CONTENT_STREAM_LENGTH.value()).divide(BigInteger.valueOf(1024));
        if (dimension.add(BigInteger.valueOf(7)).compareTo(DistintaCassiereComponentSession.MAX_OPI_DIMENSION) > 0) {
            throw new ApplicationMessageFormatException("La dimensione del flusso {0}kbytes supera la dimensione massima consentita {1}kbytes!", dimension.add(BigInteger.valueOf(7)), DistintaCassiereComponentSession.MAX_OPI_DIMENSION);
        }
        return storageObject;
    } catch (Exception e) {
        throw handleException(e);
    }
}
Also used : DocumentiContabiliService(it.cnr.contab.doccont00.service.DocumentiContabiliService) JAXBContext(javax.xml.bind.JAXBContext) RemoteIterator(it.cnr.jada.util.RemoteIterator) ApplicationMessageFormatException(it.cnr.contab.util.ApplicationMessageFormatException) Configurazione_cnrComponentSession(it.cnr.contab.config00.ejb.Configurazione_cnrComponentSession) Marshaller(javax.xml.bind.Marshaller) StorageObject(it.cnr.si.spring.storage.StorageObject) it.siopeplus(it.siopeplus) AnagraficoBulk(it.cnr.contab.anagraf00.core.bulk.AnagraficoBulk) DatatypeConfigurationException(javax.xml.datatype.DatatypeConfigurationException) CRUDNotDeletableException(it.cnr.jada.comp.CRUDNotDeletableException) CompletionException(java.util.concurrent.CompletionException) RemoteException(java.rmi.RemoteException) BusinessProcessException(it.cnr.jada.action.BusinessProcessException) EJBException(javax.ejb.EJBException) DetailedRuntimeException(it.cnr.jada.DetailedRuntimeException) IntrospectionException(it.cnr.jada.persistency.IntrospectionException) SQLException(java.sql.SQLException) ApplicationException(it.cnr.jada.comp.ApplicationException) PersistencyException(it.cnr.jada.persistency.PersistencyException) ApplicationMessageFormatException(it.cnr.contab.util.ApplicationMessageFormatException) ComponentException(it.cnr.jada.comp.ComponentException) ApplicationException(it.cnr.jada.comp.ApplicationException) AnagraficoComponentSession(it.cnr.contab.anagraf00.ejb.AnagraficoComponentSession) StorageFile(it.cnr.si.spring.storage.bulk.StorageFile) BigInteger(java.math.BigInteger) DateTimeFormatter(java.time.format.DateTimeFormatter)

Example 9 with StorageObject

use of it.cnr.si.spring.storage.StorageObject in project sigla-main by consiglionazionaledellericerche.

the class CRUDMissioneBP method initializeModelForEditAllegati.

@Override
public OggettoBulk initializeModelForEditAllegati(ActionContext actioncontext, OggettoBulk oggettobulk) throws BusinessProcessException {
    MissioneBulk allegatoParentBulk = (MissioneBulk) oggettobulk;
    try {
        if (allegatoParentBulk.getIdRimborsoMissione() != null) {
            List<StorageObject> files = missioniCMISService.getFilesOrdineMissione(allegatoParentBulk);
            if (files != null) {
                for (StorageObject storageObject : files) {
                    if (missioniCMISService.hasAspect(storageObject, StoragePropertyNames.SYS_ARCHIVED.value()))
                        continue;
                    if (excludeChild(storageObject))
                        continue;
                    if (storageObject.getPropertyValue(StoragePropertyNames.BASE_TYPE_ID.value()).equals(StoragePropertyNames.CMIS_DOCUMENT.value())) {
                        AllegatoMissioneBulk allegato = (AllegatoMissioneBulk) Introspector.newInstance(getAllegatoClass(), storageObject);
                        allegato.setContentType(storageObject.<String>getPropertyValue(StoragePropertyNames.CONTENT_STREAM_MIME_TYPE.value()));
                        allegato.setNome(storageObject.getPropertyValue(StoragePropertyNames.NAME.value()));
                        allegato.setDescrizione(storageObject.getPropertyValue(StoragePropertyNames.DESCRIPTION.value()));
                        allegato.setTitolo(storageObject.getPropertyValue(StoragePropertyNames.TITLE.value()));
                        completeAllegato(allegato, storageObject);
                        allegato.setCrudStatus(OggettoBulk.NORMAL);
                        allegatoParentBulk.addToArchivioAllegati(allegato);
                    }
                }
            }
            List<StorageObject> filesRimborso = missioniCMISService.getFilesRimborsoMissione(allegatoParentBulk);
            if (filesRimborso != null) {
                for (StorageObject storageObject : filesRimborso) {
                    if (missioniCMISService.hasAspect(storageObject, StoragePropertyNames.SYS_ARCHIVED.value()))
                        continue;
                    if (excludeChild(storageObject))
                        continue;
                    recuperoAllegatiDettaglioMissioneSigla(allegatoParentBulk, storageObject);
                    if (storageObject.getPropertyValue(StoragePropertyNames.BASE_TYPE_ID.value()).equals(StoragePropertyNames.CMIS_DOCUMENT.value())) {
                        AllegatoMissioneBulk allegato = (AllegatoMissioneBulk) Introspector.newInstance(getAllegatoClass(), storageObject);
                        allegato.setContentType(storageObject.<String>getPropertyValue(StoragePropertyNames.CONTENT_STREAM_MIME_TYPE.value()));
                        allegato.setNome(storageObject.getPropertyValue(StoragePropertyNames.NAME.value()));
                        allegato.setDescrizione(storageObject.getPropertyValue(StoragePropertyNames.DESCRIPTION.value()));
                        allegato.setTitolo(storageObject.getPropertyValue(StoragePropertyNames.TITLE.value()));
                        completeAllegato(allegato, storageObject);
                        allegato.setCrudStatus(OggettoBulk.NORMAL);
                        allegatoParentBulk.addToArchivioAllegati(allegato);
                    }
                }
            }
            if (allegatoParentBulk.getIdFlusso() != null) {
                StorageObject storageObject = missioniCMISService.recuperoFlows(allegatoParentBulk.getIdFlusso());
                if (storageObject != null) {
                    AllegatoMissioneBulk allegato = (AllegatoMissioneBulk) Introspector.newInstance(getAllegatoClass(), storageObject);
                    allegato.setContentType(storageObject.<String>getPropertyValue(StoragePropertyNames.CONTENT_STREAM_MIME_TYPE.value()));
                    allegato.setNome(storageObject.getPropertyValue(StoragePropertyNames.NAME.value()));
                    allegato.setDescrizione(storageObject.getPropertyValue(StoragePropertyNames.DESCRIPTION.value()));
                    allegato.setTitolo(storageObject.getPropertyValue(StoragePropertyNames.TITLE.value()));
                    allegato.setAspectName(AllegatoMissioneBulk.FLUSSO_RIMBORSO);
                    allegato.setCrudStatus(OggettoBulk.NORMAL);
                    allegatoParentBulk.addToArchivioAllegati(allegato);
                }
            }
            if (allegatoParentBulk.getIdFlussoOrdineMissione() != null) {
                StorageObject storageObject = missioniCMISService.recuperoFlows(allegatoParentBulk.getIdFlussoOrdineMissione());
                if (storageObject != null) {
                    AllegatoMissioneBulk allegato = (AllegatoMissioneBulk) Introspector.newInstance(getAllegatoClass(), storageObject);
                    allegato.setContentType(storageObject.<String>getPropertyValue(StoragePropertyNames.CONTENT_STREAM_MIME_TYPE.value()));
                    allegato.setNome(storageObject.getPropertyValue(StoragePropertyNames.NAME.value()));
                    allegato.setDescrizione(storageObject.getPropertyValue(StoragePropertyNames.DESCRIPTION.value()));
                    allegato.setTitolo(storageObject.getPropertyValue(StoragePropertyNames.TITLE.value()));
                    allegato.setAspectName(AllegatoMissioneBulk.FLUSSO_ORDINE);
                    allegato.setCrudStatus(OggettoBulk.NORMAL);
                    allegatoParentBulk.addToArchivioAllegati(allegato);
                }
            }
        } else {
            List<StorageObject> files = missioniCMISService.getFilesMissioneSigla(allegatoParentBulk);
            if (files != null) {
                for (StorageObject storageObject : files) {
                    if (missioniCMISService.hasAspect(storageObject, StoragePropertyNames.SYS_ARCHIVED.value()))
                        continue;
                    if (excludeChild(storageObject))
                        continue;
                    recuperoAllegatiDettaglioMissioneSigla(allegatoParentBulk, storageObject);
                    if (storageObject.getPropertyValue(StoragePropertyNames.BASE_TYPE_ID.value()).equals(StoragePropertyNames.CMIS_DOCUMENT.value())) {
                        AllegatoMissioneBulk allegato = (AllegatoMissioneBulk) Introspector.newInstance(getAllegatoClass(), storageObject);
                        allegato.setContentType(storageObject.<String>getPropertyValue(StoragePropertyNames.CONTENT_STREAM_MIME_TYPE.value()));
                        allegato.setNome(storageObject.getPropertyValue(StoragePropertyNames.NAME.value()));
                        allegato.setDescrizione(storageObject.getPropertyValue(StoragePropertyNames.DESCRIPTION.value()));
                        allegato.setTitolo(storageObject.getPropertyValue(StoragePropertyNames.TITLE.value()));
                        completeAllegato(allegato, storageObject);
                        allegato.setCrudStatus(OggettoBulk.NORMAL);
                        allegatoParentBulk.addToArchivioAllegati(allegato);
                    }
                }
            }
        }
    } catch (IllegalAccessException | InstantiationException | InvocationTargetException | NoSuchMethodException | DetailedException e) {
        throw handleException(e);
    }
    return oggettobulk;
}
Also used : DetailedException(it.cnr.jada.DetailedException) StorageObject(it.cnr.si.spring.storage.StorageObject) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 10 with StorageObject

use of it.cnr.si.spring.storage.StorageObject in project sigla-main by consiglionazionaledellericerche.

the class CRUDMissioneBP method scaricaGiustificativiCollegati.

public void scaricaGiustificativiCollegati(ActionContext actioncontext) throws Exception {
    AllegatoMissioneDettaglioSpesaBulk dettaglio = (AllegatoMissioneDettaglioSpesaBulk) getDettaglioSpesaAllegatiController().getModel();
    if (dettaglio != null) {
        StorageObject storageObject = missioniCMISService.getStorageObjectBykey(dettaglio.getStorageKey());
        if (storageObject != null) {
            InputStream is = missioniCMISService.getResource(storageObject);
            ((HttpActionContext) actioncontext).getResponse().setContentLength(storageObject.<BigInteger>getPropertyValue(StoragePropertyNames.CONTENT_STREAM_LENGTH.value()).intValue());
            ((HttpActionContext) actioncontext).getResponse().setContentType(storageObject.getPropertyValue(StoragePropertyNames.CONTENT_STREAM_MIME_TYPE.value()));
            OutputStream os = ((HttpActionContext) actioncontext).getResponse().getOutputStream();
            ((HttpActionContext) actioncontext).getResponse().setDateHeader("Expires", 0);
            byte[] buffer = new byte[((HttpActionContext) actioncontext).getResponse().getBufferSize()];
            int buflength;
            while ((buflength = is.read(buffer)) > 0) {
                os.write(buffer, 0, buflength);
            }
            is.close();
            os.flush();
        } else {
            throw new it.cnr.jada.action.MessageToUser("Giustificativi non presenti sul documentale per la riga selezionata");
        }
    } else {
        throw new it.cnr.jada.action.MessageToUser("Giustificativi non presenti sul documentale per la riga selezionata");
    }
}
Also used : StorageObject(it.cnr.si.spring.storage.StorageObject) BigInteger(java.math.BigInteger)

Aggregations

StorageObject (it.cnr.si.spring.storage.StorageObject)86 ApplicationException (it.cnr.jada.comp.ApplicationException)48 ComponentException (it.cnr.jada.comp.ComponentException)36 BigInteger (java.math.BigInteger)34 StorageException (it.cnr.si.spring.storage.StorageException)31 RemoteException (java.rmi.RemoteException)27 StoragePropertyNames (it.cnr.si.spring.storage.config.StoragePropertyNames)25 SpringUtil (it.cnr.contab.service.SpringUtil)24 BusinessProcessException (it.cnr.jada.action.BusinessProcessException)24 HttpActionContext (it.cnr.jada.action.HttpActionContext)24 OggettoBulk (it.cnr.jada.bulk.OggettoBulk)23 StoreService (it.cnr.si.spring.storage.StoreService)21 java.util (java.util)20 ServletException (javax.servlet.ServletException)19 ActionContext (it.cnr.jada.action.ActionContext)18 Unita_organizzativaBulk (it.cnr.contab.config00.sto.bulk.Unita_organizzativaBulk)16 EJBCommonServices (it.cnr.jada.util.ejb.EJBCommonServices)16 Collectors (java.util.stream.Collectors)16 Print_spoolerBulk (it.cnr.contab.reports.bulk.Print_spoolerBulk)15 Report (it.cnr.contab.reports.bulk.Report)15