Search in sources :

Example 16 with Criteria

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

the class CallService method comunicazioni.

protected Long comunicazioni(Session session, MultipartHttpServletRequest mRequest, BindingSession bindingSession, String contextURL, Locale locale, String userId) throws IOException {
    String callId = mRequest.getParameter("callId");
    String note = mRequest.getParameter("note");
    String firma = mRequest.getParameter("firma");
    List<String> applicationsId = Arrays.asList(Optional.ofNullable(mRequest.getParameterValues("application")).orElse(new String[0]));
    String filtersProvvisorieInviate = mRequest.getParameter("filters-provvisorie_inviate");
    Integer totalepunteggioda = null, totalepunteggioa = null;
    try {
        totalepunteggioda = Optional.ofNullable(mRequest.getParameter("totalepunteggioda")).filter(s -> s.length() > 0).map(Integer::valueOf).orElse(null);
        totalepunteggioa = Optional.ofNullable(mRequest.getParameter("totalepunteggioa")).filter(s -> s.length() > 0).map(Integer::valueOf).orElse(null);
    } catch (NumberFormatException _ex) {
    }
    Folder call = (Folder) session.getObject(String.valueOf(callId));
    if (!call.getAllowableActions().getAllowableActions().contains(Action.CAN_UPDATE_PROPERTIES))
        throw new ClientMessageException("message.error.call.cannnot.modify");
    List<String> nodeRefAllegato = addAttachmentToCall(session, bindingSession, call, mRequest.getFiles("file"));
    Criteria criteriaApplications = CriteriaFactory.createCriteria(JCONONFolderType.JCONON_APPLICATION.queryName());
    criteriaApplications.add(Restrictions.inTree(call.getPropertyValue(PropertyIds.OBJECT_ID)));
    if (Optional.ofNullable(filtersProvvisorieInviate).isPresent() && !filtersProvvisorieInviate.equalsIgnoreCase("tutte") && !filtersProvvisorieInviate.equalsIgnoreCase("attive") && !filtersProvvisorieInviate.equalsIgnoreCase("escluse")) {
        criteriaApplications.add(Restrictions.eq(JCONONPropertyIds.APPLICATION_STATO_DOMANDA.value(), filtersProvvisorieInviate));
    }
    if (Optional.ofNullable(filtersProvvisorieInviate).isPresent() && filtersProvvisorieInviate.equalsIgnoreCase("attive")) {
        criteriaApplications.add(Restrictions.eq(JCONONPropertyIds.APPLICATION_STATO_DOMANDA.value(), ApplicationService.StatoDomanda.CONFERMATA.getValue()));
        criteriaApplications.add(Restrictions.isNull(JCONONPropertyIds.APPLICATION_ESCLUSIONE_RINUNCIA.value()));
    }
    if (Optional.ofNullable(filtersProvvisorieInviate).isPresent() && filtersProvvisorieInviate.equalsIgnoreCase("escluse")) {
        criteriaApplications.add(Restrictions.eq(JCONONPropertyIds.APPLICATION_STATO_DOMANDA.value(), ApplicationService.StatoDomanda.CONFERMATA.getValue()));
        criteriaApplications.add(Restrictions.isNotNull(JCONONPropertyIds.APPLICATION_ESCLUSIONE_RINUNCIA.value()));
    }
    if (Optional.ofNullable(totalepunteggioda).isPresent()) {
        criteriaApplications.add(Restrictions.ge(JCONONPropertyIds.APPLICATION_TOTALE_PUNTEGGIO.value(), totalepunteggioda));
    }
    if (Optional.ofNullable(totalepunteggioa).isPresent()) {
        criteriaApplications.add(Restrictions.le(JCONONPropertyIds.APPLICATION_TOTALE_PUNTEGGIO.value(), totalepunteggioa));
    }
    applicationsId.stream().filter(string -> !string.isEmpty()).findAny().map(map -> criteriaApplications.add(Restrictions.in(PropertyIds.OBJECT_ID, applicationsId.toArray())));
    long result = 0;
    ItemIterable<QueryResult> applications = criteriaApplications.executeQuery(session, false, session.getDefaultContext());
    for (QueryResult application : applications.getPage(Integer.MAX_VALUE)) {
        Folder applicationObject = (Folder) session.getObject((String) application.getPropertyById(PropertyIds.OBJECT_ID).getFirstValue());
        final String attachmentId = competitionService.findAttachmentId(session, applicationObject.getId(), JCONONDocumentType.JCONON_ATTACHMENT_COMUNICAZIONE);
        if (attachmentId != null) {
            final CmisObject document = session.getObject(attachmentId);
            if (document.getPropertyValue(JCONON_COMUNICAZIONE_STATO) != null && document.getPropertyValue(JCONON_COMUNICAZIONE_STATO).equals(StatoComunicazione.GENERATO.name())) {
                continue;
            }
        }
        StrSubstitutor sub = formatPlaceHolder(applicationObject, applicationObject.getFolderParent());
        byte[] bytes = printService.printComunicazione(session, applicationObject, contextURL, locale, sub.replace(note), firma);
        String name = "COMUNICAZIONE_" + applicationObject.getPropertyValue(JCONONPropertyIds.APPLICATION_COGNOME.value()) + " " + applicationObject.getPropertyValue(JCONONPropertyIds.APPLICATION_NOME.value()) + "_" + applicationObject.getPropertyValue(JCONONPropertyIds.APPLICATION_USER.value()) + "_" + LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd_HH-mm-ss")) + ".pdf";
        result++;
        LOGGER.info("Generate comunication n. {} width name {}", result, name);
        Map<String, Object> properties = new HashMap<String, Object>();
        properties.put(PropertyIds.OBJECT_TYPE_ID, JCONONDocumentType.JCONON_ATTACHMENT_COMUNICAZIONE.value());
        properties.put(PropertyIds.NAME, name);
        properties.put(JCONONPropertyIds.ATTACHMENT_USER.value(), applicationObject.getPropertyValue(JCONONPropertyIds.APPLICATION_USER.value()));
        properties.put(JCONON_COMUNICAZIONE_STATO, StatoComunicazione.GENERATO.name());
        properties.put("jconon_comunicazione:email", applicationObject.getPropertyValue(JCONONPropertyIds.APPLICATION_EMAIL_COMUNICAZIONI.value()));
        properties.put("jconon_comunicazione:email_pec", applicationObject.getPropertyValue(JCONONPropertyIds.APPLICATION_EMAIL_PEC_COMUNICAZIONI.value()));
        List<String> aspects = Stream.of(JCONONPolicyType.JCONON_ATTACHMENT_GENERIC_DOCUMENT.value(), JCONONPolicyType.JCONON_ATTACHMENT_FROM_RDP.value()).collect(Collectors.toList());
        if (!nodeRefAllegato.isEmpty()) {
            properties.put(JCONONPropertyIds.ATTACHMENT_RELATED.value(), nodeRefAllegato.stream().collect(Collectors.joining(",")));
            aspects.add(JCONONPolicyType.JCONON_ATTACHMENT_ATTACHED.value());
        }
        properties.put(PropertyIds.SECONDARY_OBJECT_TYPE_IDS, aspects);
        ContentStreamImpl contentStream = new ContentStreamImpl();
        contentStream.setStream(new ByteArrayInputStream(bytes));
        contentStream.setMimeType("application/pdf");
        String documentPresentId = findAttachmentName(session, applicationObject.getId(), name);
        if (documentPresentId == null) {
            Document doc = applicationObject.createDocument(properties, contentStream, VersioningState.MAJOR);
            aclService.setInheritedPermission(bindingSession, doc.getPropertyValue(CoolPropertyIds.ALFCMIS_NODEREF.value()), false);
            Map<String, ACLType> acesGroup = new HashMap<String, ACLType>();
            acesGroup.put(JcononGroups.CONCORSI.group(), ACLType.Coordinator);
            acesGroup.put("GROUP_" + getCallGroupRdPName(call), ACLType.Coordinator);
            aclService.addAcl(bindingSession, doc.getPropertyValue(CoolPropertyIds.ALFCMIS_NODEREF.value()), acesGroup);
        } else {
            Document doc = (Document) session.getObject(documentPresentId);
            doc.updateProperties(properties);
            doc.setContentStream(contentStream, true);
        }
    }
    return result;
}
Also used : Order(it.cnr.si.opencmis.criteria.Order) ByteArrayDataSource(javax.mail.util.ByteArrayDataSource) InlineResponse201(it.cnr.si.cool.jconon.io.model.InlineResponse201) ApplicationService(it.cnr.si.cool.jconon.service.application.ApplicationService) Autowired(org.springframework.beans.factory.annotation.Autowired) CallRepository(it.cnr.si.cool.jconon.repository.CallRepository) StringUtils(org.apache.commons.lang3.StringUtils) BigDecimal(java.math.BigDecimal) CriteriaFactory(it.cnr.si.opencmis.criteria.CriteriaFactory) OperationContextUtils(org.apache.chemistry.opencmis.client.util.OperationContextUtils) HSSFSheet(org.apache.poi.hssf.usermodel.HSSFSheet) CoolPropertyIds(it.cnr.cool.cmis.model.CoolPropertyIds) ObjectIdImpl(org.apache.chemistry.opencmis.client.runtime.ObjectIdImpl) BigInteger(java.math.BigInteger) HttpStatus(org.apache.commons.httpclient.HttpStatus) PrintParameterModel(it.cnr.si.cool.jconon.model.PrintParameterModel) PropertyDefinition(org.apache.chemistry.opencmis.commons.definitions.PropertyDefinition) CompetitionFolderService(it.cnr.si.cool.jconon.service.cache.CompetitionFolderService) JCONONPolicyType(it.cnr.si.cool.jconon.cmis.model.JCONONPolicyType) org.apache.chemistry.opencmis.commons.enums(org.apache.chemistry.opencmis.commons.enums) ZoneId(java.time.ZoneId) CMISUser(it.cnr.cool.security.service.impl.alfresco.CMISUser) MailService(it.cnr.cool.mail.MailService) Stream(java.util.stream.Stream) MessageContent2(it.cnr.si.cool.jconon.io.model.MessageContent2) HSSFWorkbook(org.apache.poi.hssf.usermodel.HSSFWorkbook) VerificaPECTask(it.cnr.si.cool.jconon.dto.VerificaPECTask) it.cnr.si.cool.jconon.util(it.cnr.si.cool.jconon.util) java.util(java.util) MimeTypes(it.cnr.cool.util.MimeTypes) CmisRuntimeException(org.apache.chemistry.opencmis.commons.exceptions.CmisRuntimeException) LocalDateTime(java.time.LocalDateTime) SimpleDateFormat(java.text.SimpleDateFormat) JsonParser(com.google.gson.JsonParser) NumberFormat(java.text.NumberFormat) InternetAddress(javax.mail.internet.InternetAddress) HttpServletRequest(javax.servlet.http.HttpServletRequest) GroupsEnum(it.cnr.cool.security.GroupsEnum) Service(org.springframework.stereotype.Service) StreamSupport(java.util.stream.StreamSupport) Restrictions(it.cnr.si.opencmis.criteria.restrictions.Restrictions) UrlBuilder(org.apache.chemistry.opencmis.commons.impl.UrlBuilder) org.apache.chemistry.opencmis.client.api(org.apache.chemistry.opencmis.client.api) JSONTokener(org.json.JSONTokener) PropertyData(org.apache.chemistry.opencmis.commons.data.PropertyData) JCONONFolderType(it.cnr.si.cool.jconon.cmis.model.JCONONFolderType) StrServ(it.cnr.cool.util.StrServ) HelpdeskService(it.cnr.si.cool.jconon.service.helpdesk.HelpdeskService) ProtocolRepository(it.cnr.si.cool.jconon.repository.ProtocolRepository) UserService(it.cnr.cool.security.service.UserService) Message(javax.mail.Message) JsonObject(com.google.gson.JsonObject) PermissionServiceImpl(it.cnr.cool.web.PermissionServiceImpl) URLName(javax.mail.URLName) LoggerFactory(org.slf4j.LoggerFactory) MultipartHttpServletRequest(org.springframework.web.multipart.MultipartHttpServletRequest) CmisObjectNotFoundException(org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException) MessagingException(javax.mail.MessagingException) JSONObject(org.json.JSONObject) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Cell(org.apache.poi.ss.usermodel.Cell) ParseException(java.text.ParseException) Store(javax.mail.Store) CmisBindingsHelper(org.apache.chemistry.opencmis.client.bindings.impl.CmisBindingsHelper) Response(org.apache.chemistry.opencmis.client.bindings.spi.http.Response) AddressException(javax.mail.internet.AddressException) NewMessage(it.cnr.si.cool.jconon.io.model.NewMessage) QueueService(it.cnr.si.cool.jconon.service.QueueService) StringUtil(it.cnr.cool.util.StringUtil) SubjectTerm(javax.mail.search.SubjectTerm) ACLType(it.cnr.cool.cmis.model.ACLType) Collectors(java.util.stream.Collectors) Environment(org.springframework.core.env.Environment) PropertyIds(org.apache.chemistry.opencmis.commons.PropertyIds) LocalDate(java.time.LocalDate) EmailException(org.apache.commons.mail.EmailException) CoolUserFactoryException(it.cnr.cool.exception.CoolUserFactoryException) JCONONPropertyIds(it.cnr.si.cool.jconon.cmis.model.JCONONPropertyIds) Async(org.springframework.scheduling.annotation.Async) PECConfiguration(it.cnr.si.cool.jconon.configuration.PECConfiguration) ContentStreamImpl(org.apache.chemistry.opencmis.commons.impl.dataobjects.ContentStreamImpl) CommonsMultipartResolver(org.springframework.web.multipart.commons.CommonsMultipartResolver) IO(it.cnr.si.cool.jconon.io.repository.IO) PrintService(it.cnr.si.cool.jconon.service.PrintService) Inject(javax.inject.Inject) SearchTerm(javax.mail.search.SearchTerm) it.cnr.cool.cmis.service(it.cnr.cool.cmis.service) EmailAttachment(org.apache.commons.mail.EmailAttachment) Criteria(it.cnr.si.opencmis.criteria.Criteria) Util(it.cnr.cool.rest.util.Util) JCONONDocumentType(it.cnr.si.cool.jconon.cmis.model.JCONONDocumentType) TypeService(it.cnr.si.cool.jconon.service.TypeService) CacheRepository(it.cnr.si.cool.jconon.repository.CacheRepository) Logger(org.slf4j.Logger) BindingSession(org.apache.chemistry.opencmis.client.bindings.spi.BindingSession) ClientMessageException(it.cnr.cool.web.scripts.exception.ClientMessageException) Output(org.apache.chemistry.opencmis.client.bindings.spi.http.Output) StrSubstitutor(org.apache.commons.text.StrSubstitutor) ApplicationContext(org.springframework.context.ApplicationContext) EmailMessage(it.cnr.cool.mail.model.EmailMessage) java.io(java.io) DateTimeFormatter(java.time.format.DateTimeFormatter) Row(org.apache.poi.ss.usermodel.Row) MultipartFile(org.springframework.web.multipart.MultipartFile) CMISGroup(it.cnr.cool.security.service.impl.alfresco.CMISGroup) CMISUtil(it.cnr.cool.util.CMISUtil) I18nService(it.cnr.cool.service.I18nService) ContentStreamImpl(org.apache.chemistry.opencmis.commons.impl.dataobjects.ContentStreamImpl) ACLType(it.cnr.cool.cmis.model.ACLType) Criteria(it.cnr.si.opencmis.criteria.Criteria) BigInteger(java.math.BigInteger) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) StrSubstitutor(org.apache.commons.text.StrSubstitutor) ClientMessageException(it.cnr.cool.web.scripts.exception.ClientMessageException) JsonObject(com.google.gson.JsonObject) JSONObject(org.json.JSONObject)

Example 17 with Criteria

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

the class CallService method aggiornaProtocolloScorrimento.

public void aggiornaProtocolloScorrimento(Folder call, String numeroProtocollo, GregorianCalendar dataProtocollo) {
    if (!call.getAllowableActions().getAllowableActions().contains(Action.CAN_UPDATE_PROPERTIES))
        throw new ClientMessageException("message.error.call.cannnot.modify");
    Session session = cmisService.createAdminSession();
    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()));
    criteriaApplications.add(Restrictions.eq(JCONONPropertyIds.APPLICATION_ESITO_CALL.value(), "S"));
    ItemIterable<QueryResult> domande = criteriaApplications.executeQuery(session, false, session.getDefaultContext());
    for (QueryResult item : domande.getPage(Integer.MAX_VALUE)) {
        Folder domanda = (Folder) session.getObject(item.<String>getPropertyValueById(PropertyIds.OBJECT_ID));
        domanda.updateProperties(Stream.of(new AbstractMap.SimpleEntry<>("jconon_application:protocollo_numero_assunzione_idoneo", numeroProtocollo), new AbstractMap.SimpleEntry<>("jconon_application:protocollo_data_assunzione_idoneo", dataProtocollo)).collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)));
    }
}
Also used : ClientMessageException(it.cnr.cool.web.scripts.exception.ClientMessageException) Criteria(it.cnr.si.opencmis.criteria.Criteria) BindingSession(org.apache.chemistry.opencmis.client.bindings.spi.BindingSession)

Example 18 with Criteria

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

the class PrintService method addOrderCurriculum.

private void addOrderCurriculum(Session cmisSession, String queryName, Criteria criteria) {
    ObjectType type = cmisSession.getTypeDefinition("D:".concat(queryName));
    LOGGER.debug(type.getDisplayName());
    String aspectQueryName = null, aspectPropertyOrder = null;
    if (typeService.getMandatoryAspects(type).contains(JCONONPolicyType.CV_COMMON_METADATA_ASPECT2.value())) {
        aspectQueryName = JCONONPolicyType.CV_COMMON_METADATA_ASPECT2.queryName();
        aspectPropertyOrder = "common.cvelement:periodAttivitaDal";
    } else if (typeService.getMandatoryAspects(type).contains(JCONONPolicyType.CV_COMMON_PREMIO.value())) {
        aspectQueryName = JCONONPolicyType.CV_COMMON_PREMIO.queryName();
        aspectPropertyOrder = "common.cvelement:data";
    }
    if (aspectQueryName != null) {
        Criteria criteriaCommon = criteria.createCriteria(aspectQueryName, "common");
        criteriaCommon.addJoinCriterion(Restrictions.eqProperty(criteria.prefix(PropertyIds.OBJECT_ID), criteriaCommon.prefix(PropertyIds.OBJECT_ID)));
        criteriaCommon.addOrder(Order.desc(aspectPropertyOrder));
    }
    criteria.addOrder(Order.desc(PropertyIds.NAME));
}
Also used : Criteria(it.cnr.si.opencmis.criteria.Criteria)

Example 19 with Criteria

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

the class PrintService method getNumberOfSchedeAnonime.

private Long getNumberOfSchedeAnonime(String nodeRef, Session adminCMISSession) {
    Criteria criteriaSchedeAnonime = CriteriaFactory.createCriteria(JCONONDocumentType.JCONON_ATTACHMENT_SCHEDA_ANONIMA_SINTETICA_GENERATED.queryName());
    criteriaSchedeAnonime.add(Restrictions.inTree(nodeRef));
    return criteriaSchedeAnonime.executeQuery(adminCMISSession, false, adminCMISSession.getDefaultContext()).getTotalNumItems();
}
Also used : Criteria(it.cnr.si.opencmis.criteria.Criteria)

Example 20 with Criteria

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

the class PrintService method findAttachmentId.

public String findAttachmentId(Session cmisSession, Folder source, JCONONDocumentType documentType, boolean search) {
    if (search) {
        Criteria criteria = CriteriaFactory.createCriteria(documentType.queryName());
        criteria.addColumn(PropertyIds.OBJECT_ID);
        criteria.addColumn(PropertyIds.NAME);
        criteria.add(Restrictions.inFolder(source.getId()));
        ItemIterable<QueryResult> iterable = criteria.executeQuery(cmisSession, false, cmisSession.getDefaultContext());
        for (QueryResult queryResult : iterable) {
            return queryResult.<String>getPropertyById(PropertyIds.OBJECT_ID).getFirstValue();
        }
    } else {
        for (CmisObject cmisObject : source.getChildren()) {
            if (cmisObject.getType().getId().equals(documentType.value()))
                return cmisObject.getId();
        }
    }
    return null;
}
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