use of it.cnr.cool.web.scripts.exception.ClientMessageException in project cool-jconon by consiglionazionaledellericerche.
the class PrintService method extractionApplicationForPunteggi.
public Map<String, Object> extractionApplicationForPunteggi(Session session, String callId, String contexURL, String userId) throws IOException {
Map<String, Object> model = new HashMap<String, Object>();
List<String> columns = new ArrayList<>();
columns.addAll(headCSVPunteggi);
int[] idx = { 1 };
final Map<String, PropertyDefinition<?>> propertyDefinitions = session.getTypeDefinition("P:jconon_call:aspect_punteggi").getPropertyDefinitions();
Folder call = Optional.ofNullable(session.getObject(callId)).filter(Folder.class::isInstance).map(Folder.class::cast).orElseThrow(() -> new ClientMessageException("Bando non trovato!"));
addHeaderPunteggi(call, propertyDefinitions, columns, JCONON_CALL_PUNTEGGIO_1);
addHeaderPunteggi(call, propertyDefinitions, columns, JCONON_CALL_PUNTEGGIO_2);
addHeaderPunteggi(call, propertyDefinitions, columns, JCONON_CALL_PUNTEGGIO_3);
addHeaderPunteggi(call, propertyDefinitions, columns, JCONON_CALL_PUNTEGGIO_4);
addHeaderPunteggi(call, propertyDefinitions, columns, JCONON_CALL_PUNTEGGIO_5);
addHeaderPunteggi(call, propertyDefinitions, columns, JCONON_CALL_PUNTEGGIO_6);
columns.add("Totale Punteggi");
columns.add("Graduatoria");
columns.add("Esito");
columns.add("Note");
columns.add("Data Protocollo Graduatoria");
columns.add("Numero Protocollo Graduatoria");
columns.add("Data Protocollo Assunzione Idoneo");
columns.add("Numero Protocollo Assunzione Idoneo");
HSSFWorkbook wb = createHSSFWorkbook(columns);
final HSSFSheet sheet = wb.getSheet(SHEET_DOMANDE);
sheet.setColumnHidden(0, true);
List<CmisObject> applications = new ArrayList<>();
call.getChildren().forEach(cmisObject -> {
applications.add(cmisObject);
});
applications.stream().filter(Folder.class::isInstance).map(Folder.class::cast).filter(folder -> folder.getType().getId().equalsIgnoreCase(JCONONFolderType.JCONON_APPLICATION.value())).filter(folder -> folder.getPropertyValue(JCONONPropertyIds.APPLICATION_STATO_DOMANDA.value()).equals(StatoDomanda.CONFERMATA.getValue())).sorted(Comparator.comparing(folder -> Optional.ofNullable(folder.<BigInteger>getPropertyValue(JCONONPropertyIds.APPLICATION_GRADUATORIA.value())).orElse(BigInteger.valueOf(Integer.MAX_VALUE)))).forEach(folder -> {
final String userApplicationId = folder.getPropertyValue(JCONONPropertyIds.APPLICATION_USER.value());
CMISUser user = null;
try {
user = userService.loadUserForConfirm(userApplicationId);
} catch (CoolUserFactoryException _ex) {
LOGGER.error("USER {} not found", userId, _ex);
user = new CMISUser(userId);
}
getRecordCSVForPunteggi(session, call, folder, user, contexURL, sheet, idx[0]++);
});
autoSizeColumns(wb);
Document doc = createXLSDocument(session, wb, userId);
model.put("objectId", doc.getId());
model.put("nameBando", competitionService.getCallName(call));
return model;
}
use of it.cnr.cool.web.scripts.exception.ClientMessageException in project cool-jconon by consiglionazionaledellericerche.
the class PrintService method schedeNonAnonime.
public void schedeNonAnonime(PrintParameterModel item) {
final Session adminSession = cmisService.createAdminSession();
final String idCall = Optional.ofNullable(item.getIds()).map(List::stream).map(Stream::findFirst).orElseThrow(() -> new ClientMessageException("ID CALL NOT FOUND")).orElseThrow(() -> new ClientMessageException("ID CALL NOT FOUND"));
final String callCodice = adminSession.getObject(idCall).getPropertyValue(JCONONPropertyIds.CALL_CODICE.value());
String messageBody = schedeNonAnonime(adminSession, idCall, item.getContextURL());
EmailMessage message = new EmailMessage();
message.setBody("<b>Il processo di controllo delle schede anonime relative al bando " + callCodice + " è terminato.</b><br>" + messageBody);
message.setHtmlBody(true);
message.setSubject(i18nService.getLabel("subject-info", Locale.ITALIAN) + "Controllo delle schede anonime - " + callCodice);
message.setRecipients(Arrays.asList(item.getIndirizzoEmail()));
mailService.send(message);
}
use of it.cnr.cool.web.scripts.exception.ClientMessageException in project cool-jconon by consiglionazionaledellericerche.
the class ApplicationService method loadApplicationById.
public Folder loadApplicationById(Session cmisSession, String folderId, Map<String, Object> model) {
if (folderId == null || folderId.isEmpty())
throw new ClientMessageException("message.error.caller");
if (model != null && !model.isEmpty() && model.get("folder") != null && model.get("folder").equals(folderId))
return (Folder) model.get("folder");
Folder application = null;
try {
application = (Folder) cmisSession.getObject(folderId);
} catch (CmisObjectNotFoundException ex) {
throw new ClientMessageException("message.error.domanda.assente", ex);
} catch (CmisUnauthorizedException | CmisPermissionDeniedException ex) {
throw new ClientMessageException("message.error.user.not.authorized", ex);
}
application.refresh();
if (model != null)
model.put("folder", application);
return application;
}
use of it.cnr.cool.web.scripts.exception.ClientMessageException in project cool-jconon by consiglionazionaledellericerche.
the class ApplicationService method concludiProcessoSchedeAnonime.
public String concludiProcessoSchedeAnonime(Session currentCMISSession, String idCall, Locale locale, String contextURL, CMISUser user) {
final String userId = user.getId();
if (!callService.isMemberOfRDPGroup(user, (Folder) currentCMISSession.getObject(idCall)) && !user.isAdmin()) {
LOGGER.error("USER:" + userId + " try to generaSchedeValutazione for call:" + idCall);
throw new ClientMessageException("USER:" + userId + " try to generaSchedeValutazione for call:" + idCall);
}
OperationContext context = currentCMISSession.getDefaultContext();
context.setMaxItemsPerPage(Integer.MAX_VALUE);
String message = "";
Criteria criteriaSchedeAnonime = CriteriaFactory.createCriteria(JCONONDocumentType.JCONON_ATTACHMENT_SCHEDA_ANONIMA_SINTETICA_GENERATED.queryName(), "doc");
criteriaSchedeAnonime.add(Restrictions.inTree(idCall));
Criteria criteriaValutazione = criteriaSchedeAnonime.createCriteria(JCONONPolicyType.JCONON_SCHEDA_ANONIMA_VALUTAZIONE.queryName(), "val");
criteriaValutazione.addJoinCriterion(Restrictions.eqProperty(criteriaSchedeAnonime.prefix(PropertyIds.OBJECT_ID), criteriaValutazione.prefix(PropertyIds.OBJECT_ID)));
criteriaValutazione.add(Restrictions.isNull(criteriaValutazione.getTypeAlias() + "." + JCONONPropertyIds.SCHEDA_ANONIMA_VALUTAZIONE_ESITO.value()));
if (criteriaSchedeAnonime.executeQuery(currentCMISSession, false, context).getTotalNumItems() > 0)
throw new ClientMessageException("message.concludi.processo.schede.anonime.interrotto");
Criteria criteria = CriteriaFactory.createCriteria(JCONONDocumentType.JCONON_ATTACHMENT_SCHEDA_ANONIMA_SINTETICA_GENERATED.queryName(), "doc");
criteria.add(Restrictions.inTree(idCall));
ItemIterable<QueryResult> schede = criteria.executeQuery(currentCMISSession, false, context);
int domandeConfermate = 0, domandeEscluse = 0;
for (QueryResult scheda : schede) {
Document schedaAnonimaSintetica = (Document) currentCMISSession.getObject((String) scheda.getPropertyById(PropertyIds.OBJECT_ID).getFirstValue());
Folder domanda = schedaAnonimaSintetica.getParents().get(0);
if (schedaAnonimaSintetica.<Boolean>getPropertyValue(JCONONPropertyIds.SCHEDA_ANONIMA_VALUTAZIONE_ESITO.value())) {
domandeConfermate++;
} else {
Map<String, Object> schedaAnonimaproperties = new HashMap<String, Object>();
List<String> secondaryTypesId = new ArrayList<String>();
for (SecondaryType secondaryType : schedaAnonimaSintetica.getSecondaryTypes()) {
secondaryTypesId.add(secondaryType.getId());
}
secondaryTypesId.add(JCONONPolicyType.JCONON_ATTACHMENT_GENERIC_DOCUMENT.value());
schedaAnonimaproperties.put(PropertyIds.SECONDARY_OBJECT_TYPE_IDS, secondaryTypesId);
schedaAnonimaSintetica.updateProperties(schedaAnonimaproperties);
Map<String, Serializable> properties = new HashMap<String, Serializable>();
properties.put("jconon_application:esclusione_rinuncia", "S");
cmisService.createAdminSession().getObject(domanda).updateProperties(properties);
domandeEscluse++;
}
message = "Il processo di valutazione si è concluso con:<br><b>Domande Confermate:</b> " + domandeConfermate + "<br><b>Domande Escluse:</b>" + domandeEscluse;
}
if (schede.getTotalNumItems() != 0) {
Folder call = (Folder) currentCMISSession.getObject(idCall);
Map<String, Object> properties = new HashMap<String, Object>();
properties.put(JCONONPropertyIds.CALL_STATO.value(), CallStato.PROCESSO_SCHEDE_ANONIME_CONCLUSO_COMMISSIONE_NON_ABILITATA.name());
call.updateProperties(properties);
}
return message;
}
use of it.cnr.cool.web.scripts.exception.ClientMessageException in project cool-jconon by consiglionazionaledellericerche.
the class ApplicationService method exportSchedeValutazione.
public String exportSchedeValutazione(Session currentCMISSession, String idCall, String format, CMISUser user) {
Folder bando = (Folder) currentCMISSession.getObject(idCall);
String fileName = "Schede del bando " + bando.getProperty(JCONONPropertyIds.CALL_CODICE.value()).getValueAsString() + " al " + new SimpleDateFormat("dd-MM-yyyy HH.mm.ss", Locale.ITALY).format(new Date());
Map<String, String> schede = findSchedeValutazione(currentCMISSession, idCall);
if (format.equalsIgnoreCase("xls")) {
HSSFWorkbook wb = new HSSFWorkbook();
Map<Integer, HSSFCellStyle> styleMap = new HashMap<Integer, HSSFCellStyle>();
for (String sheetName : schede.keySet()) {
InputStream stream = ((Document) currentCMISSession.getObject(schede.get(sheetName))).getContentStream().getStream();
try {
HSSFWorkbook workbook = new HSSFWorkbook(stream);
int pictureId = 0;
for (HSSFPictureData picture : workbook.getAllPictures()) {
pictureId = wb.addPicture(picture.getData(), picture.getFormat());
}
HSSFSheet newSheet = wb.createSheet(sheetName);
HSSFPrintSetup ps = newSheet.getPrintSetup();
ps.setLandscape(false);
HSSFUtil.copySheets(newSheet, workbook.getSheetAt(0), styleMap, pictureId);
workbook.close();
} catch (IOException e) {
throw new CMISApplicationException("HSSFWorkbook error.", e);
}
}
Map<String, Object> properties = new HashMap<String, Object>();
properties.put(PropertyIds.NAME, fileName + ".xls");
properties.put(PropertyIds.OBJECT_TYPE_ID, BaseTypeId.CMIS_DOCUMENT.value());
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
try {
wb.write(outputStream);
wb.close();
} catch (IOException e) {
throw new CMISApplicationException("HSSFWorkbook error.", e);
}
Document doc;
ContentStream contentStream = new ContentStreamImpl(fileName, BigInteger.ZERO, "application/vnd.ms-excels", new ByteArrayInputStream(outputStream.toByteArray()));
Folder homeFolder = (Folder) currentCMISSession.getObject(user.getHomeFolder());
doc = homeFolder.createDocument(properties, contentStream, VersioningState.MAJOR);
return doc.getId();
} else if (format.equalsIgnoreCase("zip")) {
List<String> documents = callService.findDocumentFinal(currentCMISSession, cmisService.getAdminSession(), idCall, JCONONDocumentType.JCONON_ATTACHMENT_SCHEDA_VALUTAZIONE);
if (documents.isEmpty()) {
// Se non ci sono domande definitive finalCall non viene creata
throw new ClientMessageException("Il bando " + bando.getProperty(JCONONPropertyIds.CALL_CODICE.value()).getValueAsString() + " non presenta schede di valutazione!");
}
Map<String, String> finalZip = exportApplicationsService.invokePost(documents, fileName, cmisService.getAdminSession(), user, false, null);
return finalZip.get("nodeRef");
} else {
throw new CMISApplicationException("Formato non supportato");
}
}
Aggregations