Search in sources :

Example 11 with Criteria

use of it.cnr.si.opencmis.criteria.Criteria in project cool-jconon by consiglionazionaledellericerche.

the class CallService method deleteApplicationInitial.

public void deleteApplicationInitial(Session session) {
    Calendar midNight = Calendar.getInstance();
    midNight.set(Calendar.HOUR, 0);
    midNight.set(Calendar.MINUTE, 0);
    midNight.set(Calendar.SECOND, 0);
    Criteria criteria = CriteriaFactory.createCriteria(JCONONFolderType.JCONON_CALL.queryName());
    criteria.add(Restrictions.le(JCONONPropertyIds.CALL_DATA_FINE_INVIO_DOMANDE.value(), ISO8601DATEFORMAT.format(Calendar.getInstance().getTime())));
    criteria.add(Restrictions.ge(JCONONPropertyIds.CALL_DATA_FINE_INVIO_DOMANDE.value(), ISO8601DATEFORMAT.format(midNight.getTime())));
    ItemIterable<QueryResult> bandi = criteria.executeQuery(session, false, session.getDefaultContext());
    for (QueryResult queryResult : bandi.getPage(Integer.MAX_VALUE)) {
        Folder call = (Folder) session.getObject((String) queryResult.getPropertyValueById(PropertyIds.OBJECT_ID));
        Criteria criteriaDomande = CriteriaFactory.createCriteria(JCONONFolderType.JCONON_APPLICATION.queryName());
        criteriaDomande.add(Restrictions.inFolder(call.getId()));
        criteriaDomande.add(Restrictions.eq(JCONONPropertyIds.APPLICATION_STATO_DOMANDA.value(), ApplicationService.StatoDomanda.INIZIALE.getValue()));
        ItemIterable<QueryResult> domande = criteriaDomande.executeQuery(session, false, session.getDefaultContext());
        if (domande.getTotalNumItems() != 0) {
            for (QueryResult queryResultDomande : domande.getPage(Integer.MAX_VALUE)) {
                Folder domanda = (Folder) session.getObject((String) queryResultDomande.getPropertyValueById(PropertyIds.OBJECT_ID));
                LOGGER.info("Delete application initial: {}", domanda.getName());
                domanda.delete();
            }
        }
    }
}
Also used : Criteria(it.cnr.si.opencmis.criteria.Criteria)

Example 12 with Criteria

use of it.cnr.si.opencmis.criteria.Criteria in project cool-jconon by consiglionazionaledellericerche.

the class ApplicationService method findApplications.

public Map<String, Object> findApplications(Session session, boolean inTree, Integer page, Integer offset, String user, boolean fetchCall, String type, FilterType filterType, String callCode, LocalDate inizioScadenza, LocalDate fineScadenza, String applicationStatus, String firstname, String lastname, String codicefiscale, String callId) {
    Map<String, Object> model = new HashMap<String, Object>();
    final OperationContext defaultContext = OperationContextUtils.copyOperationContext(session.getDefaultContext());
    defaultContext.setMaxItemsPerPage(offset);
    Criteria criteriaApplications = CriteriaFactory.createCriteria(JCONONFolderType.JCONON_APPLICATION.queryName(), "root");
    criteriaApplications.addColumn(PropertyIds.OBJECT_ID);
    criteriaApplications.addColumn(PropertyIds.PARENT_ID);
    if (inTree) {
        criteriaApplications.add(Restrictions.inTree(Optional.ofNullable(callId).filter(s -> !s.isEmpty()).orElseGet(() -> competitionService.getCompetitionFolder().getString("id"))));
    }
    criteriaApplications.add(Restrictions.ne(JCONONPropertyIds.APPLICATION_STATO_DOMANDA.value(), StatoDomanda.INIZIALE.value));
    if (Optional.ofNullable(user).filter(s -> s.length() > 0).isPresent()) {
        criteriaApplications.add(Restrictions.eq(JCONONPropertyIds.APPLICATION_USER.value(), user));
    }
    final Optional<String> applicationStatusOpt = Optional.ofNullable(applicationStatus).filter(s -> !s.isEmpty()).filter(s -> !s.equalsIgnoreCase("all"));
    final Optional<String> typeOpt = Optional.ofNullable(type).filter(s -> !s.isEmpty());
    final Optional<String> firstnameOpt = Optional.ofNullable(firstname).filter(s -> !s.isEmpty());
    final Optional<String> lastnameOpt = Optional.ofNullable(lastname).filter(s -> !s.isEmpty());
    final Optional<String> codicefiscaleOpt = Optional.ofNullable(codicefiscale).filter(s -> !s.isEmpty());
    if (applicationStatusOpt.isPresent()) {
        switch(applicationStatusOpt.get()) {
            case "P":
                criteriaApplications.add(Restrictions.eq(JCONONPropertyIds.APPLICATION_STATO_DOMANDA.value(), StatoDomanda.PROVVISORIA.value));
                break;
            case "C":
                criteriaApplications.add(Restrictions.eq(JCONONPropertyIds.APPLICATION_STATO_DOMANDA.value(), StatoDomanda.CONFERMATA.value));
                break;
            case "active":
                criteriaApplications.add(Restrictions.eq(JCONONPropertyIds.APPLICATION_STATO_DOMANDA.value(), StatoDomanda.CONFERMATA.value));
                criteriaApplications.add(Restrictions.isNull(JCONONPropertyIds.APPLICATION_ESCLUSIONE_RINUNCIA.value()));
                break;
            case "excluded":
                criteriaApplications.add(Restrictions.isNotNull(JCONONPropertyIds.APPLICATION_ESCLUSIONE_RINUNCIA.value()));
                break;
        }
    }
    if (firstnameOpt.isPresent()) {
        criteriaApplications.add(Restrictions.contains(JCONONPropertyIds.APPLICATION_NOME.value(), firstnameOpt.map(s -> s.replace("'", "''")).map(s -> "\'*".concat(s).concat("*\''")).orElse("")));
    }
    if (lastnameOpt.isPresent()) {
        criteriaApplications.add(Restrictions.contains(JCONONPropertyIds.APPLICATION_COGNOME.value(), lastnameOpt.map(s -> s.replace("'", "''")).map(s -> "\'*".concat(s).concat("*\''")).orElse("")));
    }
    if (codicefiscaleOpt.isPresent()) {
        criteriaApplications.add(Restrictions.like(JCONONPropertyIds.APPLICATION_CODICE_FISCALE.value(), codicefiscaleOpt.map(String::toUpperCase).map(s -> "%".concat(s).concat("%")).orElse("")));
    }
    List<Map<String, Object>> items = new ArrayList<>();
    ItemIterable<QueryResult> applications = criteriaApplications.executeQuery(session, false, defaultContext);
    long totalNumItems = applications.getTotalNumItems();
    for (QueryResult result : applications.skipTo(page * defaultContext.getMaxItemsPerPage()).getPage(defaultContext.getMaxItemsPerPage())) {
        final Map<String, Object> applicationMap = CMISUtil.convertToProperties(session.getObject(result.<String>getPropertyValueById(PropertyIds.OBJECT_ID), defaultContext));
        if (fetchCall) {
            final Folder call = Optional.ofNullable(session.getObject(result.<String>getPropertyValueById(PropertyIds.PARENT_ID), defaultContext)).filter(Folder.class::isInstance).map(Folder.class::cast).orElseThrow(() -> new CmisInvalidArgumentException("Parent object is not folder!"));
            if (typeOpt.isPresent() && !call.getType().getQueryName().equals(typeOpt.get())) {
                totalNumItems--;
                continue;
            }
            if (Optional.ofNullable(filterType).isPresent()) {
                if ((filterType.equals(FilterType.active) && !callService.isBandoInCorso(call)) || (filterType.equals(FilterType.expire) && callService.isBandoInCorso(call))) {
                    totalNumItems--;
                    continue;
                }
            }
            if (Optional.ofNullable(callCode).filter(s -> s.length() > 0).isPresent()) {
                if (Optional.ofNullable(call.<String>getPropertyValue(JCONONPropertyIds.CALL_CODICE.value())).map(s -> s.toUpperCase()).filter(s -> !s.contains(callCode.toUpperCase())).isPresent()) {
                    totalNumItems--;
                    continue;
                }
            }
            if (Optional.ofNullable(inizioScadenza).isPresent()) {
                if (Optional.ofNullable(call.<Calendar>getPropertyValue(JCONONPropertyIds.CALL_DATA_FINE_INVIO_DOMANDE.value())).map(cal -> LocalDateTime.ofInstant(cal.toInstant(), ZoneId.systemDefault())).filter(dateTime -> dateTime.isBefore(inizioScadenza.atStartOfDay())).isPresent()) {
                    totalNumItems--;
                    continue;
                }
            }
            if (Optional.ofNullable(fineScadenza).isPresent()) {
                if (Optional.ofNullable(call.<Calendar>getPropertyValue(JCONONPropertyIds.CALL_DATA_FINE_INVIO_DOMANDE.value())).map(cal -> LocalDateTime.ofInstant(cal.toInstant(), ZoneId.systemDefault())).filter(dateTime -> dateTime.isAfter(fineScadenza.atStartOfDay())).isPresent()) {
                    totalNumItems--;
                    continue;
                }
            }
            applicationMap.put("call", CMISUtil.convertToProperties(call));
        }
        items.add(applicationMap);
    }
    model.put("count", totalNumItems);
    model.put("page", page);
    model.put("offset", defaultContext.getMaxItemsPerPage());
    model.put("items", items);
    return model;
}
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) Criteria(it.cnr.si.opencmis.criteria.Criteria) JsonObject(com.google.gson.JsonObject) JSONObject(org.json.JSONObject) UnfileObject(org.apache.chemistry.opencmis.commons.enums.UnfileObject)

Example 13 with Criteria

use of it.cnr.si.opencmis.criteria.Criteria in project cool-jconon by consiglionazionaledellericerche.

the class ApplicationService method abilitaProcessoSchedeAnonime.

public String abilitaProcessoSchedeAnonime(Session currentCMISSession, String idCall, Locale locale, String contextURL, CMISUser user) {
    final String userId = user.getId();
    Folder call = (Folder) currentCMISSession.getObject(idCall);
    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);
    Criteria criteriaDomande = CriteriaFactory.createCriteria(JCONONFolderType.JCONON_APPLICATION.queryName());
    criteriaDomande.add(Restrictions.inTree(idCall));
    criteriaDomande.add(Restrictions.eq(JCONONPropertyIds.APPLICATION_STATO_DOMANDA.value(), ApplicationService.StatoDomanda.CONFERMATA.getValue()));
    criteriaDomande.add(Restrictions.isNull(JCONONPropertyIds.APPLICATION_ESCLUSIONE_RINUNCIA.value()));
    ItemIterable<QueryResult> domande = criteriaDomande.executeQuery(currentCMISSession, false, context);
    int domandeConfermate = 0;
    for (QueryResult item : domande) {
        Folder domanda = (Folder) currentCMISSession.getObject((String) item.getPropertyById(PropertyIds.OBJECT_ID).getFirstValue());
        Map<String, ACLType> acesToADD = new HashMap<String, ACLType>();
        List<String> groups = callService.getGroupsCallToApplication(call);
        for (String group : groups) {
            acesToADD.put(group, ACLType.Contributor);
        }
        aclService.addAcl(cmisService.getAdminSession(), domanda.getPropertyValue(CoolPropertyIds.ALFCMIS_NODEREF.value()), acesToADD);
        domandeConfermate++;
    }
    Map<String, Object> properties = new HashMap<String, Object>();
    properties.put(JCONONPropertyIds.CALL_STATO.value(), CallStato.PROCESSO_SCHEDE_ANONIME_ABILITATA_COMMISSIONE.name());
    call.updateProperties(properties);
    String message = "Il processo di abilitazione si รจ concluso con:<br><b>Domande abilitate:</b> " + domandeConfermate;
    return message;
}
Also used : ACLType(it.cnr.cool.cmis.model.ACLType) Criteria(it.cnr.si.opencmis.criteria.Criteria) 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)

Example 14 with Criteria

use of it.cnr.si.opencmis.criteria.Criteria in project cool-jconon by consiglionazionaledellericerche.

the class CallService method inviaAllegato.

public List<String> inviaAllegato(Session session, BindingSession bindingSession, String objectId, String contexURL, String userId, String callId, String userName, String password) throws IOException {
    List<String> result = new ArrayList<String>();
    Folder call = (Folder) session.getObject(callId);
    Document doc = (Document) session.getObject(objectId);
    Criteria criteriaApplications = CriteriaFactory.createCriteria(JCONONFolderType.JCONON_APPLICATION.queryName());
    criteriaApplications.add(Restrictions.inFolder(call.getPropertyValue(PropertyIds.OBJECT_ID)));
    criteriaApplications.add(Restrictions.eq(JCONONPropertyIds.APPLICATION_STATO_DOMANDA.value(), ApplicationService.StatoDomanda.CONFERMATA.getValue()));
    criteriaApplications.add(Restrictions.isNull(JCONONPropertyIds.APPLICATION_ESCLUSIONE_RINUNCIA.value()));
    ItemIterable<QueryResult> attive = criteriaApplications.executeQuery(session, false, session.getDefaultContext());
    for (QueryResult domanda : attive.getPage(Integer.MAX_VALUE)) {
        Folder domandaObject = (Folder) session.getObject((String) domanda.getPropertyById(PropertyIds.OBJECT_ID).getFirstValue());
        String address = Optional.ofNullable(domandaObject.getProperty(JCONONPropertyIds.APPLICATION_EMAIL_PEC_COMUNICAZIONI.value()).getValueAsString()).orElse(domandaObject.getProperty(JCONONPropertyIds.APPLICATION_EMAIL_COMUNICAZIONI.value()).getValueAsString());
        if (env.acceptsProfiles(Profile.DEVELOPMENT.value())) {
            address = env.getProperty("mail.to.error.message");
        }
        SimplePECMail simplePECMail = new SimplePECMail(userName, password);
        simplePECMail.setHostName(pecConfiguration.getHostSmtp());
        simplePECMail.setSubject(i18NService.getLabel("subject-info", Locale.ITALIAN) + i18NService.getLabel("subject-confirm-comunicazione", Locale.ITALIAN, call.getProperty(JCONONPropertyIds.CALL_CODICE.value()).getValueAsString()));
        String content = "Con riferimento alla Sua domanda di partecipazione al concorso indicato in oggetto, si invia in allegato il provvedimento contenente \"" + doc.getType().getDisplayName() + "\"<br>";
        content += "Distinti saluti.<br/><br/><br/><hr/>";
        content += "<b>Questo messaggio e' stato generato da un sistema automatico. Si prega di non rispondere.</b><br/><br/>";
        try {
            simplePECMail.setFrom(userName);
            simplePECMail.setReplyTo(Collections.singleton(new InternetAddress("undisclosed-recipients")));
            simplePECMail.setTo(Collections.singleton(new InternetAddress(address)));
            simplePECMail.attach(new ByteArrayDataSource(new ByteArrayInputStream(content.getBytes()), "text/html"), "", "", EmailAttachment.INLINE);
            simplePECMail.attach(new ByteArrayDataSource(doc.getContentStream().getStream(), doc.getContentStreamMimeType()), doc.getName(), doc.getName());
            simplePECMail.send();
            result.add(address);
        } catch (EmailException | AddressException e) {
            LOGGER.error("Cannot send email to {}", address, e);
        }
    }
    return result;
}
Also used : InternetAddress(javax.mail.internet.InternetAddress) Criteria(it.cnr.si.opencmis.criteria.Criteria) AddressException(javax.mail.internet.AddressException) EmailException(org.apache.commons.mail.EmailException) ByteArrayDataSource(javax.mail.util.ByteArrayDataSource)

Example 15 with Criteria

use of it.cnr.si.opencmis.criteria.Criteria in project cool-jconon by consiglionazionaledellericerche.

the class CallService method getTotalNumApplication.

public long getTotalNumApplication(Session cmisSession, Folder macroCall, Folder application, String userId, String statoDomanda) {
    if (macroCall != null) {
        Criteria criteria = CriteriaFactory.createCriteria(JCONONFolderType.JCONON_APPLICATION.queryName());
        criteria.addColumn(PropertyIds.OBJECT_ID);
        criteria.addColumn(PropertyIds.NAME);
        criteria.add(Restrictions.inTree(macroCall.getId()));
        if (userId != null) {
            criteria.add(Restrictions.eq(JCONONPropertyIds.APPLICATION_USER.value(), userId));
        }
        if (statoDomanda != null) {
            criteria.add(Restrictions.eq(JCONONPropertyIds.APPLICATION_STATO_DOMANDA.value(), statoDomanda));
        }
        if (application != null) {
            criteria.add(Restrictions.ne(PropertyIds.OBJECT_ID, application.getId()));
        }
        ItemIterable<QueryResult> iterable = criteria.executeQuery(cmisSession, false, cmisSession.getDefaultContext());
        return iterable.getTotalNumItems();
    } else {
        return 0;
    }
}
Also used : Criteria(it.cnr.si.opencmis.criteria.Criteria)

Aggregations

Criteria (it.cnr.si.opencmis.criteria.Criteria)53 ClientMessageException (it.cnr.cool.web.scripts.exception.ClientMessageException)26 JSONObject (org.json.JSONObject)19 BindingSession (org.apache.chemistry.opencmis.client.bindings.spi.BindingSession)18 CoolUserFactoryException (it.cnr.cool.exception.CoolUserFactoryException)17 CMISUser (it.cnr.cool.security.service.impl.alfresco.CMISUser)16 BigInteger (java.math.BigInteger)16 ACLType (it.cnr.cool.cmis.model.ACLType)14 CriteriaFactory (it.cnr.si.opencmis.criteria.CriteriaFactory)14 java.util (java.util)14 Collectors (java.util.stream.Collectors)14 Output (org.apache.chemistry.opencmis.client.bindings.spi.http.Output)14 Response (org.apache.chemistry.opencmis.client.bindings.spi.http.Response)14 PropertyIds (org.apache.chemistry.opencmis.commons.PropertyIds)14 UrlBuilder (org.apache.chemistry.opencmis.commons.impl.UrlBuilder)14 Logger (org.slf4j.Logger)14 LoggerFactory (org.slf4j.LoggerFactory)14 Autowired (org.springframework.beans.factory.annotation.Autowired)14 CoolPropertyIds (it.cnr.cool.cmis.model.CoolPropertyIds)13 GroupsEnum (it.cnr.cool.security.GroupsEnum)13