Search in sources :

Example 1 with CMISApplicationException

use of it.cnr.cool.web.scripts.exception.CMISApplicationException 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);
    }
}
Also used : CMISUser(it.cnr.cool.security.service.impl.alfresco.CMISUser) ApplicationModel(it.cnr.si.cool.jconon.model.ApplicationModel) CMISApplicationException(it.cnr.cool.web.scripts.exception.CMISApplicationException) JRPdfExporter(net.sf.jasperreports.engine.export.JRPdfExporter) JsonDataSource(net.sf.jasperreports.engine.data.JsonDataSource) JRGzipVirtualizer(net.sf.jasperreports.engine.fill.JRGzipVirtualizer) ClassPathResource(org.springframework.core.io.ClassPathResource) JSONException(org.json.JSONException) CmisObjectNotFoundException(org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException) WriterException(com.google.zxing.WriterException) ParseException(java.text.ParseException) CMISApplicationException(it.cnr.cool.web.scripts.exception.CMISApplicationException) CoolUserFactoryException(it.cnr.cool.exception.CoolUserFactoryException) NotImplementedException(org.apache.commons.lang3.NotImplementedException) CmisStreamNotSupportedException(org.apache.chemistry.opencmis.commons.exceptions.CmisStreamNotSupportedException) ClientMessageException(it.cnr.cool.web.scripts.exception.ClientMessageException) ACLType(it.cnr.cool.cmis.model.ACLType) Type(java.lang.reflect.Type) PDImageXObject(org.apache.pdfbox.pdmodel.graphics.image.PDImageXObject) JSONObject(org.json.JSONObject) CoolUserFactoryException(it.cnr.cool.exception.CoolUserFactoryException)

Example 2 with CMISApplicationException

use of it.cnr.cool.web.scripts.exception.CMISApplicationException in project cool-jconon by consiglionazionaledellericerche.

the class PrintService method getSchedaAnonimaSintetica.

@SuppressWarnings("unchecked")
public byte[] getSchedaAnonimaSintetica(Session cmisSession, Folder application, String contextURL, Locale locale, int index) throws CMISApplicationException {
    Folder call = application.getFolderParent();
    ApplicationModel applicationModel = new ApplicationModel(application, cmisSession.getDefaultContext(), i18nService.loadLabels(locale), contextURL, false);
    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_SEZIONE_SCHEDE_ANONIME.value()) != null) {
        applicationModel.getProperties().put("schedeAnonime", getCurriculum(call.getPropertyValue(JCONONPropertyIds.CALL_ELENCO_SEZIONE_SCHEDE_ANONIME.value()), application, cmisSession, applicationModel));
    }
    String json = "{\"properties\":" + gson.toJson(applicationModel.getProperties()) + "}";
    try {
        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("INDICE", index);
        parameters.put("DIR_IMAGE", new ClassPathResource(PRINT_RESOURCE_PATH).getPath());
        parameters.put("SUBREPORT_DIR", new ClassPathResource(PRINT_RESOURCE_PATH).getPath());
        ClassLoader classLoader = ClassLoader.getSystemClassLoader();
        parameters.put(JRParameter.REPORT_CLASS_LOADER, classLoader);
        JasperReport jasperReport = cacheRepository.jasperReport(PRINT_RESOURCE_PATH + "SchedaAnonima.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);
    }
}
Also used : ApplicationModel(it.cnr.si.cool.jconon.model.ApplicationModel) CMISApplicationException(it.cnr.cool.web.scripts.exception.CMISApplicationException) JRPdfExporter(net.sf.jasperreports.engine.export.JRPdfExporter) JsonDataSource(net.sf.jasperreports.engine.data.JsonDataSource) JRGzipVirtualizer(net.sf.jasperreports.engine.fill.JRGzipVirtualizer) ClassPathResource(org.springframework.core.io.ClassPathResource) JSONException(org.json.JSONException) CmisObjectNotFoundException(org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException) WriterException(com.google.zxing.WriterException) ParseException(java.text.ParseException) CMISApplicationException(it.cnr.cool.web.scripts.exception.CMISApplicationException) CoolUserFactoryException(it.cnr.cool.exception.CoolUserFactoryException) NotImplementedException(org.apache.commons.lang3.NotImplementedException) CmisStreamNotSupportedException(org.apache.chemistry.opencmis.commons.exceptions.CmisStreamNotSupportedException) ClientMessageException(it.cnr.cool.web.scripts.exception.ClientMessageException) ACLType(it.cnr.cool.cmis.model.ACLType) Type(java.lang.reflect.Type) PDImageXObject(org.apache.pdfbox.pdmodel.graphics.image.PDImageXObject) JSONObject(org.json.JSONObject)

Example 3 with CMISApplicationException

use of it.cnr.cool.web.scripts.exception.CMISApplicationException 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");
    }
}
Also used : ContentStreamImpl(org.apache.chemistry.opencmis.commons.impl.dataobjects.ContentStreamImpl) CMISApplicationException(it.cnr.cool.web.scripts.exception.CMISApplicationException) ContentStream(org.apache.chemistry.opencmis.commons.data.ContentStream) ClientMessageException(it.cnr.cool.web.scripts.exception.ClientMessageException) LocalDate(java.time.LocalDate) BigInteger(java.math.BigInteger) JsonObject(com.google.gson.JsonObject) JSONObject(org.json.JSONObject) UnfileObject(org.apache.chemistry.opencmis.commons.enums.UnfileObject) SimpleDateFormat(java.text.SimpleDateFormat)

Example 4 with CMISApplicationException

use of it.cnr.cool.web.scripts.exception.CMISApplicationException 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);
}
Also used : OperationContextImpl(org.apache.chemistry.opencmis.client.runtime.OperationContextImpl) CMISApplicationException(it.cnr.cool.web.scripts.exception.CMISApplicationException) JSONException(org.json.JSONException) CMISApplicationException(it.cnr.cool.web.scripts.exception.CMISApplicationException) CoolUserFactoryException(it.cnr.cool.exception.CoolUserFactoryException) ClientMessageException(it.cnr.cool.web.scripts.exception.ClientMessageException) Response(org.apache.chemistry.opencmis.client.bindings.spi.http.Response) JSONObject(org.json.JSONObject) ClientMessageException(it.cnr.cool.web.scripts.exception.ClientMessageException) Output(org.apache.chemistry.opencmis.client.bindings.spi.http.Output) UrlBuilder(org.apache.chemistry.opencmis.commons.impl.UrlBuilder) CoolUserFactoryException(it.cnr.cool.exception.CoolUserFactoryException)

Example 5 with CMISApplicationException

use of it.cnr.cool.web.scripts.exception.CMISApplicationException 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;
}
Also used : JsonObject(com.google.gson.JsonObject) Order(it.cnr.si.opencmis.criteria.Order) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) GroupService(it.cnr.cool.security.service.GroupService) BigDecimal(java.math.BigDecimal) JSONException(org.json.JSONException) CriteriaFactory(it.cnr.si.opencmis.criteria.CriteriaFactory) JSONObject(org.json.JSONObject) OperationContextUtils(org.apache.chemistry.opencmis.client.util.OperationContextUtils) CoolPropertyIds(it.cnr.cool.cmis.model.CoolPropertyIds) BigInteger(java.math.BigInteger) HttpStatus(org.apache.commons.httpclient.HttpStatus) PrintParameterModel(it.cnr.si.cool.jconon.model.PrintParameterModel) ContentStream(org.apache.chemistry.opencmis.commons.data.ContentStream) PropertyDefinition(org.apache.chemistry.opencmis.commons.definitions.PropertyDefinition) it.cnr.cool.util(it.cnr.cool.util) CompetitionFolderService(it.cnr.si.cool.jconon.service.cache.CompetitionFolderService) Response(org.apache.chemistry.opencmis.client.bindings.spi.http.Response) PolicyType(it.cnr.cool.cmis.model.PolicyType) CMISApplicationException(it.cnr.cool.web.scripts.exception.CMISApplicationException) QueueService(it.cnr.si.cool.jconon.service.QueueService) ACLType(it.cnr.cool.cmis.model.ACLType) Collectors(java.util.stream.Collectors) ZoneId(java.time.ZoneId) CMISUser(it.cnr.cool.security.service.impl.alfresco.CMISUser) MailService(it.cnr.cool.mail.MailService) JsonArray(com.google.gson.JsonArray) Choice(org.apache.chemistry.opencmis.commons.definitions.Choice) Stream(java.util.stream.Stream) OperationContextImpl(org.apache.chemistry.opencmis.client.runtime.OperationContextImpl) PropertyIds(org.apache.chemistry.opencmis.commons.PropertyIds) LocalDate(java.time.LocalDate) Entry(java.util.Map.Entry) CoolUserFactoryException(it.cnr.cool.exception.CoolUserFactoryException) FieldProperty(it.cnr.bulkinfo.BulkInfoImpl.FieldProperty) it.cnr.si.cool.jconon.util(it.cnr.si.cool.jconon.util) java.util(java.util) LocalDateTime(java.time.LocalDateTime) ContentStreamImpl(org.apache.chemistry.opencmis.commons.impl.dataobjects.ContentStreamImpl) SimpleDateFormat(java.text.SimpleDateFormat) BaseTypeId(org.apache.chemistry.opencmis.commons.enums.BaseTypeId) Function(java.util.function.Function) InitializingBean(org.springframework.beans.factory.InitializingBean) PrintService(it.cnr.si.cool.jconon.service.PrintService) JsonElement(com.google.gson.JsonElement) Value(org.springframework.beans.factory.annotation.Value) it.cnr.cool.cmis.service(it.cnr.cool.cmis.service) GroupsEnum(it.cnr.cool.security.GroupsEnum) Criteria(it.cnr.si.opencmis.criteria.Criteria) Service(org.springframework.stereotype.Service) SiperService(it.cnr.si.cool.jconon.service.SiperService) StreamSupport(java.util.stream.StreamSupport) Restrictions(it.cnr.si.opencmis.criteria.restrictions.Restrictions) UrlBuilder(org.apache.chemistry.opencmis.commons.impl.UrlBuilder) IncludeRelationships(org.apache.chemistry.opencmis.commons.enums.IncludeRelationships) TypeService(it.cnr.si.cool.jconon.service.TypeService) org.apache.chemistry.opencmis.client.api(org.apache.chemistry.opencmis.client.api) UnfileObject(org.apache.chemistry.opencmis.commons.enums.UnfileObject) VersioningState(org.apache.chemistry.opencmis.commons.enums.VersioningState) org.apache.chemistry.opencmis.commons.exceptions(org.apache.chemistry.opencmis.commons.exceptions) Logger(org.slf4j.Logger) BindingSession(org.apache.chemistry.opencmis.client.bindings.spi.BindingSession) org.apache.poi.hssf.usermodel(org.apache.poi.hssf.usermodel) it.cnr.si.cool.jconon.cmis.model(it.cnr.si.cool.jconon.cmis.model) BulkInfo(it.cnr.bulkinfo.BulkInfo) ClientMessageException(it.cnr.cool.web.scripts.exception.ClientMessageException) Output(org.apache.chemistry.opencmis.client.bindings.spi.http.Output) ApplicationContext(org.springframework.context.ApplicationContext) CallService(it.cnr.si.cool.jconon.service.call.CallService) java.io(java.io) BulkInfoCoolService(it.cnr.cool.service.BulkInfoCoolService) UserService(it.cnr.cool.security.service.UserService) I18nService(it.cnr.cool.service.I18nService) CMISUser(it.cnr.cool.security.service.impl.alfresco.CMISUser) ClientMessageException(it.cnr.cool.web.scripts.exception.ClientMessageException) JsonObject(com.google.gson.JsonObject) JSONObject(org.json.JSONObject) UnfileObject(org.apache.chemistry.opencmis.commons.enums.UnfileObject) CMISApplicationException(it.cnr.cool.web.scripts.exception.CMISApplicationException) CoolUserFactoryException(it.cnr.cool.exception.CoolUserFactoryException)

Aggregations

CMISApplicationException (it.cnr.cool.web.scripts.exception.CMISApplicationException)16 ClientMessageException (it.cnr.cool.web.scripts.exception.ClientMessageException)16 CoolUserFactoryException (it.cnr.cool.exception.CoolUserFactoryException)15 JSONException (org.json.JSONException)15 JSONObject (org.json.JSONObject)15 WriterException (com.google.zxing.WriterException)10 ParseException (java.text.ParseException)10 CmisObjectNotFoundException (org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException)10 CmisStreamNotSupportedException (org.apache.chemistry.opencmis.commons.exceptions.CmisStreamNotSupportedException)10 NotImplementedException (org.apache.commons.lang3.NotImplementedException)10 ACLType (it.cnr.cool.cmis.model.ACLType)9 ApplicationModel (it.cnr.si.cool.jconon.model.ApplicationModel)8 Type (java.lang.reflect.Type)8 JsonDataSource (net.sf.jasperreports.engine.data.JsonDataSource)8 PDImageXObject (org.apache.pdfbox.pdmodel.graphics.image.PDImageXObject)8 ClassPathResource (org.springframework.core.io.ClassPathResource)8 JRGzipVirtualizer (net.sf.jasperreports.engine.fill.JRGzipVirtualizer)7 Output (org.apache.chemistry.opencmis.client.bindings.spi.http.Output)5 Response (org.apache.chemistry.opencmis.client.bindings.spi.http.Response)5 UrlBuilder (org.apache.chemistry.opencmis.commons.impl.UrlBuilder)5