use of it.cnr.contab.util00.bulk.storage.AllegatoGenericoBulk in project sigla-main by consiglionazionaledellericerche.
the class CRUDMissioneBP method delete.
@Override
public void delete(ActionContext actioncontext) throws BusinessProcessException {
if (Optional.ofNullable(getModel()).filter(MissioneBulk.class::isInstance).map(MissioneBulk.class::cast).map(el -> {
try {
return el.isMissioneFromGemis() && !el.isAbilitatoCancellazioneMissioneFromGemis(actioncontext.getUserContext());
} catch (Exception e) {
throw new DetailedRuntimeException(e);
}
}).orElse(Boolean.FALSE))
throw handleException(new ApplicationException("Missione non eliminabile in quanto proveniente da un flusso approvato."));
MissioneBulk missioneBulk = (MissioneBulk) getModel();
if (missioneBulk.isMissioneFromGemis()) {
for (AllegatoGenericoBulk allegato : missioneBulk.getArchivioAllegati()) {
allegato.setDaNonEliminare(true);
}
}
super.delete(actioncontext);
}
use of it.cnr.contab.util00.bulk.storage.AllegatoGenericoBulk in project sigla-main by consiglionazionaledellericerche.
the class AllegatiDocContBP method scaricaAllegatoAmministrativo.
public void scaricaAllegatoAmministrativo(ActionContext actioncontext) throws IOException, ServletException, ApplicationException {
AllegatoGenericoBulk allegato = (AllegatoGenericoBulk) getDettaglioAllegati().getModel();
StorageObject storageObject = storeService.getStorageObjectBykey(allegato.getStorageKey());
InputStream is = storeService.getResource(allegato.getStorageKey());
((HttpActionContext) actioncontext).getResponse().setContentLength((storageObject.<BigInteger>getPropertyValue(StoragePropertyNames.CONTENT_STREAM_LENGTH.value())).intValue());
((HttpActionContext) actioncontext).getResponse().setContentType((String) 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();
}
use of it.cnr.contab.util00.bulk.storage.AllegatoGenericoBulk in project sigla-main by consiglionazionaledellericerche.
the class AllegatiDocContBP method aggiungiAllegati.
public void aggiungiAllegati(ActionContext actioncontext, List<UploadedFile> uploadedFiles) throws BusinessProcessException {
final V_mandato_reversaleBulk v_mandato_reversaleBulk = Optional.ofNullable(getModel()).filter(V_mandato_reversaleBulk.class::isInstance).map(V_mandato_reversaleBulk.class::cast).orElseThrow(() -> handleException(new ApplicationException("Modello non trovato!")));
for (UploadedFile uploadedFile : uploadedFiles) {
AllegatoGenericoBulk allegato = new AllegatoGenericoBulk();
allegato.setContentType(Optional.ofNullable(uploadedFile).flatMap(uploadedFile1 -> Optional.ofNullable(uploadedFile1.getContentType())).orElseThrow(() -> handleException(new ApplicationException("Non è stato possibile determinare il tipo di file!"))));
allegato.setNome(Optional.ofNullable(uploadedFile).flatMap(uploadedFile1 -> Optional.ofNullable(uploadedFile1.getName())).orElseThrow(() -> handleException(new ApplicationException("Non è stato possibile determinare il nome del file!"))));
allegato.setFile(Optional.ofNullable(uploadedFile).flatMap(uploadedFile1 -> Optional.ofNullable(uploadedFile1.getFile())).orElseThrow(() -> handleException(new ApplicationException("File non presente!"))));
try {
final Optional<StorageObject> parentFolder = Optional.ofNullable(storeService.getStorageObjectByPath(v_mandato_reversaleBulk.getStorePath()));
if (parentFolder.isPresent()) {
try {
storeService.storeSimpleDocument(allegato, new FileInputStream(allegato.getFile()), allegato.getContentType(), allegato.getNome(), Optional.ofNullable(uploadedFile.getFilePath()).map(s -> s.substring(s.indexOf(File.separator), s.indexOf(uploadedFile.getName()))).map(s -> v_mandato_reversaleBulk.getStorePath().concat(s)).orElse(v_mandato_reversaleBulk.getStorePath()));
} catch (StringIndexOutOfBoundsException _ex) {
logger.warn("File non caricato path locale {}", uploadedFile.getFilePath());
throw handleException(new ApplicationMessageFormatException("Il caricamento è stato interrotto verificare il file [{0}]", uploadedFile.getFilePath()));
}
} else {
throw handleException(new ApplicationException("La Cartella di destinazione non esiste!"));
}
} catch (FileNotFoundException e) {
throw handleException(e);
} catch (StorageException e) {
if (e.getType().equals(StorageException.Type.CONSTRAINT_VIOLATED))
throw handleException(new ApplicationException("File [" + allegato.getNome() + "] gia' presente. Inserimento non possibile!"));
throw handleException(e);
}
}
edit(actioncontext, v_mandato_reversaleBulk);
setMessage(FormBP.INFO_MESSAGE, "Allegati inseriti correttamente al documento.");
}
use of it.cnr.contab.util00.bulk.storage.AllegatoGenericoBulk in project sigla-main by consiglionazionaledellericerche.
the class AllegatiCRUDBP method scaricaAllegatoGenerico.
public void scaricaAllegatoGenerico(ActionContext actioncontext) throws IOException, ServletException, ApplicationException {
AllegatoGenericoBulk allegato = (T) crudArchivioAllegati.getModel();
StorageObject storageObject = storeService.getStorageObjectBykey(allegato.getStorageKey());
InputStream is = storeService.getResource(allegato.getStorageKey());
((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();
}
use of it.cnr.contab.util00.bulk.storage.AllegatoGenericoBulk in project sigla-main by consiglionazionaledellericerche.
the class AllegatiCRUDBP method archiviaAllegati.
@SuppressWarnings("unchecked")
protected void archiviaAllegati(ActionContext actioncontext) throws BusinessProcessException, ApplicationException {
AllegatoParentBulk allegatoParentBulk = (AllegatoParentBulk) getModel();
for (AllegatoGenericoBulk allegato : allegatoParentBulk.getArchivioAllegati()) {
if (allegato.isToBeCreated()) {
final File file = Optional.ofNullable(allegato.getFile()).orElseThrow(() -> new ApplicationException("File non presente"));
try {
allegato.complete(actioncontext.getUserContext());
storeService.storeSimpleDocument(allegato, new FileInputStream(file), allegato.getContentType(), allegato.getNome(), getStorePath((K) allegatoParentBulk, true));
allegato.setCrudStatus(OggettoBulk.NORMAL);
} catch (FileNotFoundException e) {
throw handleException(e);
} catch (StorageException e) {
if (e.getType().equals(StorageException.Type.CONSTRAINT_VIOLATED))
throw new ApplicationException("File [" + allegato.getNome() + "] gia' presente. Inserimento non possibile!");
throw handleException(e);
}
} else if (allegato.isToBeUpdated()) {
if (isPossibileModifica(allegato)) {
try {
if (allegato.getFile() != null) {
storeService.updateStream(allegato.getStorageKey(), new FileInputStream(allegato.getFile()), allegato.getContentType());
}
allegato.complete(actioncontext.getUserContext());
storeService.updateProperties(allegato, storeService.getStorageObjectBykey(allegato.getStorageKey()));
allegato.setCrudStatus(OggettoBulk.NORMAL);
} catch (FileNotFoundException e) {
throw handleException(e);
} catch (StorageException e) {
if (e.getType().equals(StorageException.Type.CONSTRAINT_VIOLATED))
throw new ApplicationException("File [" + allegato.getNome() + "] gia' presente. Inserimento non possibile!");
throw handleException(e);
}
}
}
}
gestioneCancellazioneAllegati(allegatoParentBulk);
}
Aggregations