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;
}
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)));
}
}
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));
}
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();
}
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;
}
Aggregations