Search in sources :

Example 51 with Criteria

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

the class CallService method findAttachmentName.

public String findAttachmentName(Session cmisSession, String source, String name) {
    Criteria criteria = CriteriaFactory.createCriteria(BaseTypeId.CMIS_DOCUMENT.value());
    criteria.addColumn(PropertyIds.OBJECT_ID);
    criteria.addColumn(PropertyIds.NAME);
    criteria.add(Restrictions.inFolder(source));
    criteria.add(Restrictions.eq(PropertyIds.NAME, name));
    ItemIterable<QueryResult> iterable = criteria.executeQuery(cmisSession, false, cmisSession.getDefaultContext());
    for (QueryResult queryResult : iterable) {
        return (String) queryResult.getPropertyById(PropertyIds.OBJECT_ID).getFirstValue();
    }
    return null;
}
Also used : Criteria(it.cnr.si.opencmis.criteria.Criteria)

Example 52 with Criteria

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

the class CallService method sollecitaApplication.

public void sollecitaApplication(Session cmisSession) {
    Criteria criteria = CriteriaFactory.createCriteria(JCONONFolderType.JCONON_CALL.queryName());
    criteria.add(Restrictions.inTree(competitionService.getCompetitionFolder().getString("id")));
    ItemIterable<QueryResult> bandi = criteria.executeQuery(cmisSession, false, cmisSession.getDefaultContext());
    for (QueryResult queryResult : bandi.getPage(Integer.MAX_VALUE)) {
        BigInteger numGiorniSollecito = (BigInteger) queryResult.getPropertyById(JCONONPropertyIds.CALL_NUM_GIORNI_MAIL_SOLLECITO.value()).getFirstValue();
        if (numGiorniSollecito == null)
            numGiorniSollecito = new BigInteger("8");
        Calendar dataLimite = Calendar.getInstance();
        dataLimite.add(Calendar.DAY_OF_YEAR, numGiorniSollecito.intValue());
        Calendar dataFineDomande = (Calendar) queryResult.getPropertyById(JCONONPropertyIds.CALL_DATA_FINE_INVIO_DOMANDE.value()).getFirstValue();
        if (dataFineDomande == null)
            continue;
        if (dataFineDomande.before(dataLimite) && dataFineDomande.after(Calendar.getInstance())) {
            Criteria criteriaDomande = CriteriaFactory.createCriteria(JCONONFolderType.JCONON_APPLICATION.queryName());
            criteriaDomande.addColumn(JCONONPropertyIds.APPLICATION_USER.value());
            criteriaDomande.addColumn(JCONONPropertyIds.APPLICATION_NOME.value());
            criteriaDomande.addColumn(JCONONPropertyIds.APPLICATION_COGNOME.value());
            criteriaDomande.add(Restrictions.inFolder((String) queryResult.getPropertyById(PropertyIds.OBJECT_ID).getFirstValue()));
            criteriaDomande.add(Restrictions.eq(JCONONPropertyIds.APPLICATION_STATO_DOMANDA.value(), ApplicationService.StatoDomanda.PROVVISORIA.getValue()));
            ItemIterable<QueryResult> domande = criteriaDomande.executeQuery(cmisSession, false, cmisSession.getDefaultContext());
            for (QueryResult queryResultDomande : domande.getPage(Integer.MAX_VALUE)) {
                EmailMessage message = new EmailMessage();
                List<String> emailList = new ArrayList<String>();
                try {
                    CMISUser user = userService.loadUserForConfirm((String) queryResultDomande.getPropertyById(JCONONPropertyIds.APPLICATION_USER.value()).getFirstValue());
                    if (user != null && user.getEmail() != null) {
                        emailList.add(user.getEmail());
                        message.setRecipients(emailList);
                        message.setSubject(i18NService.getLabel("subject-info", Locale.ITALY) + i18NService.getLabel("subject-reminder-domanda", Locale.ITALY, queryResult.getPropertyById(JCONONPropertyIds.CALL_CODICE.value()).getFirstValue(), removeHtmlFromString((String) queryResult.getPropertyById(JCONONPropertyIds.CALL_DESCRIZIONE.value()).getFirstValue())));
                        Map<String, Object> templateModel = new HashMap<String, Object>();
                        templateModel.put("call", queryResult);
                        templateModel.put("folder", queryResultDomande);
                        templateModel.put("message", context.getBean("messageMethod", Locale.ITALY));
                        String body = Util.processTemplate(templateModel, "/pages/call/call.reminder.application.html.ftl");
                        message.setBody(body);
                        mailService.send(message);
                        LOGGER.info("Spedita mail a {} per il bando {}", user.getEmail(), message.getSubject());
                    }
                } catch (Exception e) {
                    LOGGER.error("Cannot send email for scheduler reminder application for call", e);
                }
            }
        }
    }
}
Also used : EmailMessage(it.cnr.cool.mail.model.EmailMessage) CMISUser(it.cnr.cool.security.service.impl.alfresco.CMISUser) Criteria(it.cnr.si.opencmis.criteria.Criteria) CmisRuntimeException(org.apache.chemistry.opencmis.commons.exceptions.CmisRuntimeException) CmisObjectNotFoundException(org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException) MessagingException(javax.mail.MessagingException) ParseException(java.text.ParseException) AddressException(javax.mail.internet.AddressException) EmailException(org.apache.commons.mail.EmailException) CoolUserFactoryException(it.cnr.cool.exception.CoolUserFactoryException) ClientMessageException(it.cnr.cool.web.scripts.exception.ClientMessageException) BigInteger(java.math.BigInteger) JsonObject(com.google.gson.JsonObject) JSONObject(org.json.JSONObject)

Example 53 with Criteria

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

the class CallService method sollecitaProdotti.

public void sollecitaProdotti(Session cmisSession) {
    Criteria criteria = CriteriaFactory.createCriteria(JCONONFolderType.JCONON_CALL.queryName());
    Criteria criteriaProfile = criteria.createCriteria(JCONONPolicyType.JCONON_CALL_ASPECT_PRODUCTS_AFTER_COMMISSION.queryName(), JCONONPolicyType.JCONON_CALL_ASPECT_PRODUCTS_AFTER_COMMISSION.queryName());
    criteriaProfile.addJoinCriterion(Restrictions.eqProperty(criteria.prefix(PropertyIds.OBJECT_ID), criteriaProfile.prefix(PropertyIds.OBJECT_ID)));
    ItemIterable<QueryResult> bandi = criteria.executeQuery(cmisSession, false, cmisSession.getDefaultContext());
    for (QueryResult queryResult : bandi.getPage(Integer.MAX_VALUE)) {
        Calendar dataInizioCaricamento = queryResult.<Calendar>getPropertyValueById(JCONONPropertyIds.CALL_SELECTED_PRODUCT_START_DATE.value());
        Calendar dataFineCaricamento = queryResult.<Calendar>getPropertyValueById(JCONONPropertyIds.CALL_SELECTED_PRODUCT_END_DATE.value());
        if (dataFineCaricamento == null || dataInizioCaricamento == null)
            continue;
        Calendar dataLimite = Calendar.getInstance();
        dataLimite.add(Calendar.DAY_OF_YEAR, 3);
        if (dataFineCaricamento.before(dataLimite) && dataFineCaricamento.after(Calendar.getInstance())) {
            Criteria criteriaDomande = CriteriaFactory.createCriteria(JCONONFolderType.JCONON_APPLICATION.queryName());
            criteriaDomande.add(Restrictions.inFolder((String) queryResult.getPropertyById(PropertyIds.OBJECT_ID).getFirstValue()));
            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(cmisSession, false, cmisSession.getDefaultContext());
            for (QueryResult queryResultDomande : domande.getPage(Integer.MAX_VALUE)) {
                if (!Optional.ofNullable(competitionService.findAttachmentId(cmisSession, queryResultDomande.getPropertyValueById(PropertyIds.OBJECT_ID), JCONONDocumentType.JCONON_ATTACHMENT_CURRICULUM_PROD_SCELTI_MULTIPLO)).isPresent()) {
                    EmailMessage message = new EmailMessage();
                    List<String> emailList = new ArrayList<String>();
                    try {
                        CMISUser user = userService.loadUserForConfirm((String) queryResultDomande.getPropertyById(JCONONPropertyIds.APPLICATION_USER.value()).getFirstValue());
                        if (user != null && user.getEmail() != null) {
                            emailList.add(user.getEmail());
                            message.setRecipients(emailList);
                            message.setSubject(i18NService.getLabel("subject-info", Locale.ITALY) + i18NService.getLabel("subject-reminder-selectedproducts", Locale.ITALY, queryResult.getPropertyById(JCONONPropertyIds.CALL_CODICE.value()).getFirstValue(), removeHtmlFromString((String) queryResult.getPropertyById(JCONONPropertyIds.CALL_DESCRIZIONE.value()).getFirstValue())));
                            Map<String, Object> templateModel = new HashMap<String, Object>();
                            templateModel.put("call", queryResult);
                            templateModel.put("folder", queryResultDomande);
                            templateModel.put("message", context.getBean("messageMethod", Locale.ITALY));
                            String body = Util.processTemplate(templateModel, "/pages/call/call.reminder.selectedproducts.html.ftl");
                            message.setBody(body);
                            mailService.send(message);
                            LOGGER.info("Spedita mail a {} per il bando {} con testo {}", user.getEmail(), message.getSubject(), body);
                        }
                    } catch (Exception e) {
                        LOGGER.error("Cannot send email for scheduler reminder application for call", e);
                    }
                }
            }
        }
    }
}
Also used : EmailMessage(it.cnr.cool.mail.model.EmailMessage) CMISUser(it.cnr.cool.security.service.impl.alfresco.CMISUser) Criteria(it.cnr.si.opencmis.criteria.Criteria) CmisRuntimeException(org.apache.chemistry.opencmis.commons.exceptions.CmisRuntimeException) CmisObjectNotFoundException(org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException) MessagingException(javax.mail.MessagingException) ParseException(java.text.ParseException) AddressException(javax.mail.internet.AddressException) EmailException(org.apache.commons.mail.EmailException) CoolUserFactoryException(it.cnr.cool.exception.CoolUserFactoryException) ClientMessageException(it.cnr.cool.web.scripts.exception.ClientMessageException) JsonObject(com.google.gson.JsonObject) JSONObject(org.json.JSONObject)

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