use of it.cnr.cool.exception.CoolUserFactoryException in project cool-jconon by consiglionazionaledellericerche.
the class PrintService method getRicevutaReportModel.
@SuppressWarnings({ "unchecked", "deprecation" })
public byte[] getRicevutaReportModel(Session cmisSession, Folder application, String contextURL, String nameRicevutaReportModel, boolean immediate) throws CMISApplicationException {
Folder call = application.getFolderParent();
Locale locale = Locale.ITALY;
Properties props = i18nService.loadLabels(locale);
props.putAll(competitionService.getDynamicLabels(call, cmisSession));
ApplicationModel applicationModel = new ApplicationModel(application, cmisSession.getDefaultContext(), props, contextURL);
try {
CMISUser applicationUser = userService.loadUserForConfirm(application.getPropertyValue(JCONONPropertyIds.APPLICATION_USER.value()));
applicationModel.getProperties().put("jasperReport:user_matricola", applicationUser.getMatricola());
applicationModel.getProperties().put("jasperReport:user_email_comunicazione", applicationUser.getEmail());
applicationModel.getProperties().put("jconon_application:objectId", application.getId());
} catch (CoolUserFactoryException e) {
LOGGER.error("User not found", e);
}
final Gson gson = new GsonBuilder().setDateFormat("yyyy-MM-dd'T'HH:mm:ss").excludeFieldsWithoutExposeAnnotation().registerTypeAdapter(GregorianCalendar.class, new JsonSerializer<GregorianCalendar>() {
@Override
public JsonElement serialize(GregorianCalendar src, Type typeOfSrc, JsonSerializationContext context) {
return context.serialize(src.getTime());
}
}).create();
if (call.getPropertyValue(JCONONPropertyIds.CALL_ELENCO_ASSOCIATIONS.value()) != null) {
applicationModel.getProperties().put("allegati", getAllegati(application, JCONONPolicyType.JCONON_ATTACHMENT_GENERIC_DOCUMENT, cmisSession, applicationModel));
}
if (call.getPropertyValue(JCONONPropertyIds.CALL_ELENCO_SEZIONE_CURRICULUM.value()) != null) {
applicationModel.getProperties().put("curriculum", getCurriculum(call.getPropertyValue(JCONONPropertyIds.CALL_ELENCO_SEZIONE_CURRICULUM.value()), application, cmisSession, applicationModel));
}
if (call.getPropertyValue(JCONONPropertyIds.CALL_ELENCO_SEZIONE_CURRICULUM_ULTERIORE.value()) != null) {
applicationModel.getProperties().put("curriculum_ulteriore", getCurriculum(call.getPropertyValue(JCONONPropertyIds.CALL_ELENCO_SEZIONE_CURRICULUM_ULTERIORE.value()), application, cmisSession, applicationModel));
}
if (call.getPropertyValue(JCONONPropertyIds.CALL_ELENCO_SEZIONE_PRODOTTI.value()) != null) {
applicationModel.getProperties().put("prodotti", getProdotti(call.getPropertyValue(JCONONPropertyIds.CALL_ELENCO_SEZIONE_PRODOTTI.value()), application, JCONONPolicyType.PEOPLE_NO_SELECTED_PRODUCT, cmisSession, applicationModel));
applicationModel.getProperties().put("prodottiScelti", getProdotti(call.getPropertyValue(JCONONPropertyIds.CALL_ELENCO_SEZIONE_PRODOTTI.value()), application, JCONONPolicyType.PEOPLE_SELECTED_PRODUCT, cmisSession, applicationModel));
}
if (call.getPropertyValue(JCONONPropertyIds.CALL_ELENCO_SEZIONE_SCHEDE_ANONIME.value()) != null) {
applicationModel.getProperties().put("schedeAnonime", getCurriculum(call.getPropertyValue(JCONONPropertyIds.CALL_ELENCO_SEZIONE_SCHEDE_ANONIME.value()), application, cmisSession, applicationModel));
}
applicationModel.getProperties().put(Dichiarazioni.dichiarazioni.name(), getDichiarazioni(bulkInfoService.find(application.getType().getId()), application, JCONONPropertyIds.CALL_ELENCO_ASPECTS, applicationModel, Dichiarazioni.dichiarazioni));
applicationModel.getProperties().put(Dichiarazioni.datiCNR.name(), getDichiarazioni(bulkInfoService.find(application.getType().getId()), application, JCONONPropertyIds.CALL_ELENCO_ASPECTS_SEZIONE_CNR, applicationModel, Dichiarazioni.datiCNR));
applicationModel.getProperties().put(Dichiarazioni.ulterioriDati.name(), getDichiarazioni(bulkInfoService.find(application.getType().getId()), application, JCONONPropertyIds.CALL_ELENCO_ASPECTS_ULTERIORI_DATI, applicationModel, Dichiarazioni.ulterioriDati));
String labelSottoscritto = i18nService.getLabel("application.text.sottoscritto.lower." + application.getPropertyValue(JCONONPropertyIds.APPLICATION_SESSO.value()), locale);
String labelSanzioniPenali = i18nService.getLabel("text.jconon_application_dichiarazione_sanzioni_penali_" + call.getPropertyValue(JCONONPropertyIds.CALL_CODICE.value()), locale);
if (labelSanzioniPenali == null)
labelSanzioniPenali = i18nService.getLabel("text.jconon_application_dichiarazione_sanzioni_penali", locale, labelSottoscritto);
else
labelSanzioniPenali = i18nService.getLabel("text.jconon_application_dichiarazione_sanzioni_penali_" + call.getPropertyValue(JCONONPropertyIds.CALL_CODICE.value()), locale, labelSottoscritto);
applicationModel.getProperties().put("label_jconon_application_dichiarazione_sanzioni_penali", labelSanzioniPenali);
applicationModel.getProperties().put("label_jconon_application_dichiarazione_dati_personali", i18nService.getLabel("text.jconon_application_dichiarazione_dati_personali", locale, labelSottoscritto));
for (Object key : call.getProperty(JCONONPropertyIds.CALL_ELENCO_SEZIONI_DOMANDA.value()).getValues()) {
applicationModel.getProperties().put(String.valueOf(key), props.get(key));
}
if (immediate) {
applicationModel.getProperties().put(JCONONPropertyIds.APPLICATION_STATO_DOMANDA.value(), StatoDomanda.CONFERMATA.getValue());
applicationModel.getProperties().put(JCONONPropertyIds.APPLICATION_DATA_DOMANDA.value(), Calendar.getInstance());
}
String json = "{\"properties\":" + gson.toJson(applicationModel.getProperties()) + "}";
try {
/**
* Calcolo il QRCODE del link alla stampa
*/
ByteArrayOutputStream qrcode = QrCodeUtil.getQrcode(contextURL + "/rest/application/print-download?nodeRef=" + application.getId());
Map<String, Object> parameters = new HashMap<String, Object>();
JRDataSource datasource = new JsonDataSource(new ByteArrayInputStream(json.getBytes(StandardCharsets.UTF_8)), "properties");
JRGzipVirtualizer vir = new JRGzipVirtualizer(100);
final ResourceBundle resourceBundle = ResourceBundle.getBundle("net.sf.jasperreports.view.viewer", locale);
parameters.put(JRParameter.REPORT_LOCALE, locale);
parameters.put(JRParameter.REPORT_RESOURCE_BUNDLE, resourceBundle);
parameters.put(JRParameter.REPORT_DATA_SOURCE, datasource);
parameters.put(JRParameter.REPORT_VIRTUALIZER, vir);
parameters.put("DIR_IMAGE", new ClassPathResource(PRINT_RESOURCE_PATH).getPath());
parameters.put("SUBREPORT_DIR", new ClassPathResource(PRINT_RESOURCE_PATH).getPath());
if (qrcode != null) {
parameters.put("QRCODE", new ByteArrayInputStream(qrcode.toByteArray()));
}
ClassLoader classLoader = ClassLoader.getSystemClassLoader();
parameters.put(JRParameter.REPORT_CLASS_LOADER, classLoader);
JasperReport jasperReport = cacheRepository.jasperReport(PRINT_RESOURCE_PATH + "DomandaConcorso.jrxml", jasperCompileManager());
JasperPrint jasperPrint = jasperFillManager().fill(jasperReport, parameters);
ByteArrayOutputStream os = new ByteArrayOutputStream();
JRPdfExporter exporter = new JRPdfExporter();
exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);
exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, os);
exporter.setParameter(JRPdfExporterParameter.FORCE_LINEBREAK_POLICY, Boolean.TRUE);
exporter.exportReport();
return os.toByteArray();
} catch (Exception e) {
throw new CMISApplicationException("Error in JASPER", e);
}
}
use of it.cnr.cool.exception.CoolUserFactoryException 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.exception.CoolUserFactoryException in project cool-jconon by consiglionazionaledellericerche.
the class ApplicationService method reopenApplication.
public void reopenApplication(Session currentCMISSession, final String applicationSourceId, final String contextURL, Locale locale, String userId) {
/**
* Load application source with user session if user cannot access to application
* throw an exception
*/
try {
OperationContext oc = new OperationContextImpl(currentCMISSession.getDefaultContext());
oc.setFilterString(PropertyIds.OBJECT_ID);
currentCMISSession.getObject(applicationSourceId, oc);
} catch (CmisPermissionDeniedException _ex) {
throw new ClientMessageException("user.cannot.access.to.application", _ex);
}
final Folder newApplication = loadApplicationById(currentCMISSession, applicationSourceId, null);
final Folder call = loadCallById(currentCMISSession, newApplication.getParentId(), null);
if (newApplication.getPropertyValue(JCONONPropertyIds.APPLICATION_DATA_DOMANDA.value()) == null || !newApplication.getPropertyValue(JCONONPropertyIds.APPLICATION_STATO_DOMANDA.value()).equals(StatoDomanda.CONFERMATA.getValue())) {
throw new ClientMessageException("message.error.domanda.no.confermata");
}
try {
callService.isBandoInCorso(call, userService.loadUserForConfirm(userId));
} catch (CoolUserFactoryException e) {
throw new CMISApplicationException("Error loading user: " + userId, e);
}
String link = cmisService.getBaseURL().concat("service/cnr/jconon/manage-application/reopen");
UrlBuilder url = new UrlBuilder(link);
Response resp = cmisService.getHttpInvoker(cmisService.getAdminSession()).invokePOST(url, MimeTypes.JSON.mimetype(), new Output() {
@Override
public void write(OutputStream out) throws Exception {
JSONObject jsonObject = new JSONObject();
jsonObject.put("applicationSourceId", newApplication.getProperty(CoolPropertyIds.ALFCMIS_NODEREF.value()).getValueAsString());
jsonObject.put("groupRdP", "GROUP_" + call.getPropertyValue(JCONONPropertyIds.CALL_RDP.value()));
jsonObject.put("groupConsumer", JcononGroups.APPLICATION_CONSUMER.group());
out.write(jsonObject.toString().getBytes());
}
}, cmisService.getAdminSession());
int status = resp.getResponseCode();
if (status == HttpStatus.SC_NOT_FOUND || status == HttpStatus.SC_BAD_REQUEST || status == HttpStatus.SC_INTERNAL_SERVER_ERROR) {
throw new CMISApplicationException("Reopen Application error. Exception: " + resp.getErrorContent());
}
addToQueueForPrint(applicationSourceId, contextURL, emailOnReopen);
}
use of it.cnr.cool.exception.CoolUserFactoryException in project cool-jconon by consiglionazionaledellericerche.
the class ApplicationService method load.
public Folder load(Session currentCMISSession, String callId, String applicationId, String userId, boolean preview, String contextURL, Locale locale) {
Map<String, Object> result = new HashMap<String, Object>();
Folder application = null;
CMISUser loginUser = userService.loadUserForConfirm(userId), applicationUser = null;
Folder call = loadCallById(currentCMISSession, callId, result);
try {
if (applicationId != null && !applicationId.isEmpty()) {
application = loadApplicationById(currentCMISSession, applicationId, result);
// la chiamata con il parametro applicationId deve prevedere sempre l'esistenza della domanda
if (application == null)
throw new ClientMessageException("message.error.caller");
else {
// coincide con quello della domanda
if (!loginUser.isAdmin() && !loginUser.getId().equals(application.getPropertyValue(JCONONPropertyIds.APPLICATION_USER.value())))
throw new ClientMessageException("message.error.caller.user");
else if (!application.getParentId().equals(call.getId()))
throw new ClientMessageException("message.error.caller");
}
} else
application = loadApplicationByCall(currentCMISSession, callId, result, userId);
// Carico lo user dell'application
applicationUser = getApplicationUser(application);
// essere un dipendente
if (call.getType().getId().equals(JCONONFolderType.JCONON_CALL_EMPLOYEES.value()) && ((application == null && loginUser.getMatricola() == null) || (applicationUser != null && applicationUser.getMatricola() == null))) {
if (!isApplicationPreview(preview, loginUser, call) && blockSubmitEmployee)
throw new ClientMessageException("message.error.bando.tipologia.employees");
}
final Optional<String> canSubmitApplicationOnlySPID = Optional.ofNullable(call.<String>getPropertyValue(JCONONPropertyIds.CALL_ONLY_USER_SPID_CAN_SUBMIT_APPLICATION.value()));
if (canSubmitApplicationOnlySPID.map(Boolean::valueOf).filter(aBoolean -> {
return aBoolean.booleanValue();
}).map(aBoolean -> {
return !Optional.ofNullable(loginUser.getApplication()).filter(s -> !s.isEmpty()).filter(s -> s.equals("SPID")).isPresent();
}).orElse(Boolean.FALSE) && !isApplicationPreview(preview, loginUser, call)) {
throw new ClientMessageException(i18nService.getLabel("message.error.bando.cannot.submit.application.spid", locale));
}
/**
* Se nel bando รจ valorizzato il gruppo delle utenze viene controllata la presenza
* dell'utenza specifica nel gruppo
*/
final Optional<String> groupCanSubmitApplication = Optional.ofNullable(call.<String>getPropertyValue(JCONONPropertyIds.CALL_GROUP_CAN_SUBMIT_APPLICATION.value()));
if (groupCanSubmitApplication.map(groupName -> !loginUser.getGroupsArray().contains(groupName)).orElse(Boolean.FALSE)) {
throw new ClientMessageException(i18nService.getLabel("message.error.bando.cannot.submit.application", locale, groupService.loadGroup(groupCanSubmitApplication.map(s -> s.replaceAll("GROUP_", "")).orElseThrow(() -> new CMISApplicationException("Cannot find GROUP")), cmisService.getAdminSession()).getDisplay_name()));
}
// essere un dipendente
if (JCONONFolderType.isMobilityCall(call.getType().getId()) && ((application == null && loginUser.getMatricola() != null) || (applicationUser != null && applicationUser.getMatricola() != null))) {
if (!isApplicationPreview(preview, loginUser, call))
throw new ClientMessageException("message.error.bando.tipologia.mobility");
}
// Se presente e validata, entra...... Se presente e non validata il blocco lo ha in fase di invio.
if (application == null)
validateMacroCall(call, null, loginUser);
else if (application.getPropertyValue(JCONONPropertyIds.APPLICATION_STATO_DOMANDA.value()).equals(StatoDomanda.INIZIALE.getValue()))
validateMacroCall(call, application, applicationUser);
else if (isDomandaInviata(application, loginUser)) {
throw new ClientMessageException("message.error.domanda.inviata.accesso");
}
if (!isApplicationPreview(preview, loginUser, call))
callService.isBandoInCorso(call, loginUser);
if (application != null) {
/**
* Controllo di consistenza su nome e cognome dell'utenza
*/
if (!loginUser.isAdmin() && loginUser.getId().equals(application.getPropertyValue(JCONONPropertyIds.APPLICATION_USER.value()))) {
Map<String, Object> properties = new HashMap<String, Object>();
if (!loginUser.getFirstName().equalsIgnoreCase(application.getPropertyValue(JCONONPropertyIds.APPLICATION_NOME.value()))) {
properties.put(JCONONPropertyIds.APPLICATION_NOME.value(), loginUser.getFirstName());
}
if (!loginUser.getLastName().equalsIgnoreCase(application.getPropertyValue(JCONONPropertyIds.APPLICATION_COGNOME.value()))) {
properties.put(JCONONPropertyIds.APPLICATION_COGNOME.value(), loginUser.getLastName());
}
if (!properties.isEmpty())
cmisService.createAdminSession().getObject(application).updateProperties(properties, true);
}
try {
validateAllegatiLinked(call, application, currentCMISSession);
} catch (ClientMessageException e) {
LOGGER.warn("ValidateAllegatiLinked message: {}", e.getMessage());
result.put("validateAllegatiLinkedEmpty", e.getKeyMessage());
}
}
if (application == null)
application = createInitialFolder(loginUser, result, cmisService.createAdminSession(), call);
} catch (CoolUserFactoryException e) {
throw new CMISApplicationException("Load Application error.", e);
}
return application;
}
use of it.cnr.cool.exception.CoolUserFactoryException in project cool-jconon by consiglionazionaledellericerche.
the class ApplicationService method paste.
public String paste(Session currentCMISSession, final String applicationSourceId, final String callTargetId, String userId) {
/**
* Load application source with user session if user cannot access to application
* throw an exception
*/
try {
OperationContext oc = new OperationContextImpl(currentCMISSession.getDefaultContext());
oc.setFilterString(PropertyIds.OBJECT_ID);
currentCMISSession.getObject(applicationSourceId, oc);
} catch (CmisPermissionDeniedException _ex) {
throw new ClientMessageException("user.cannot.access.to.application", _ex);
}
final Folder application = loadApplicationById(currentCMISSession, applicationSourceId, null);
final Folder call = loadCallById(currentCMISSession, callTargetId, null);
try {
callService.isBandoInCorso(call, userService.loadUserForConfirm(userId));
} catch (CoolUserFactoryException e) {
throw new CMISApplicationException("Error loading user: " + userId, e);
}
String link = cmisService.getBaseURL().concat("service/cnr/jconon/manage-application/paste");
UrlBuilder url = new UrlBuilder(link);
Response resp = cmisService.getHttpInvoker(cmisService.getAdminSession()).invokePOST(url, MimeTypes.JSON.mimetype(), new Output() {
@Override
public void write(OutputStream out) throws Exception {
JSONObject jsonObject = new JSONObject();
jsonObject.put("applicationSourceId", application.getProperty(CoolPropertyIds.ALFCMIS_NODEREF.value()).getValueAsString());
jsonObject.put("callTargetId", call.getProperty(CoolPropertyIds.ALFCMIS_NODEREF.value()).getValueAsString());
out.write(jsonObject.toString().getBytes());
}
}, cmisService.getAdminSession());
int stato = resp.getResponseCode();
if (stato == HttpStatus.SC_BAD_REQUEST || stato == HttpStatus.SC_INTERNAL_SERVER_ERROR) {
try {
JSONObject jsonObject = new JSONObject(resp.getErrorContent());
throw new ClientMessageException(jsonObject.getString("message"));
} catch (JSONException e) {
throw new ClientMessageException("message.application.for.copy.alredy.exists", e);
}
}
if (stato == HttpStatus.SC_NOT_FOUND) {
throw new ClientMessageException("Paste Application error. Exception: " + resp.getErrorContent());
}
try {
JSONObject jsonObject = new JSONObject(StringUtil.convertStreamToString(resp.getStream()));
return jsonObject.getString("cmis:objectId");
} catch (JSONException e) {
throw new ClientMessageException("Paste Application error. Exception: " + resp.getErrorContent(), e);
}
}
Aggregations