use of org.apache.chemistry.opencmis.client.bindings.spi.BindingSession in project cool-jconon by consiglionazionaledellericerche.
the class CallService method inviaEsclusioni.
public Long inviaEsclusioni(Session session, BindingSession bindingSession, String query, String contexURL, String userId, String callId, String userName, String password, AddressType addressFromApplication) throws IOException {
Folder call = (Folder) session.getObject(callId);
ItemIterable<QueryResult> esclusioni = session.query(query, false);
String subject = i18NService.getLabel("subject-info", Locale.ITALIAN) + i18NService.getLabel("subject-confirm-esclusione", Locale.ITALIAN, call.getProperty(JCONONPropertyIds.CALL_CODICE.value()).getValueAsString());
long index = 0;
for (QueryResult esclusione : esclusioni.getPage(Integer.MAX_VALUE)) {
Document esclusioneObject = (Document) session.getObject((String) esclusione.getPropertyById(PropertyIds.OBJECT_ID).getFirstValue());
final Optional<Folder> application = esclusioneObject.getParents().stream().findFirst();
if (application.isPresent() && !Optional.ofNullable(application.get().getPropertyValue(JCONONPropertyIds.APPLICATION_ESCLUSIONE_RINUNCIA.value())).isPresent()) {
Map<String, Serializable> properties = new HashMap<String, Serializable>();
properties.put(JCONONPropertyIds.APPLICATION_ESCLUSIONE_RINUNCIA.value(), ApplicationService.StatoDomanda.ESCLUSA.getValue());
cmisService.createAdminSession().getObject(application.get()).updateProperties(properties);
Map<String, ACLType> acesToRemove = new HashMap<String, ACLType>();
List<String> groups = getGroupsCallToApplication(call);
for (String group : groups) {
acesToRemove.put(group, ACLType.Contributor);
}
aclService.removeAcl(cmisService.getAdminSession(), application.get().getProperty(CoolPropertyIds.ALFCMIS_NODEREF.value()).getValueAsString(), acesToRemove);
}
aclService.setInheritedPermission(bindingSession, esclusioneObject.getProperty(CoolPropertyIds.ALFCMIS_NODEREF.value()).getValueAsString(), true);
String contentURL = contexURL + "/rest/application/esclusione?nodeRef=" + esclusioneObject.getId();
String user = esclusioneObject.<String>getPropertyValue(JCONONPropertyIds.ATTACHMENT_USER.value());
List<Document> attachmentRelated = Optional.ofNullable(esclusioneObject.<String>getPropertyValue(JCONONPropertyIds.ATTACHMENT_RELATED.value())).map(s -> Arrays.asList(s.split(","))).orElse(Collections.emptyList()).stream().map(s -> session.getObject(s)).filter(Document.class::isInstance).map(Document.class::cast).collect(Collectors.toList());
String address = obtainAddress(esclusioneObject, "jconon_esclusione:email_pec", "jconon_esclusione:email", addressFromApplication);
SimplePECMail simplePECMail = new SimplePECMail(userName, password);
simplePECMail.setHostName(pecConfiguration.getHostSmtp());
simplePECMail.setSubject(subject + " $$ " + esclusioneObject.getId());
String content = "Con riferimento alla Sua domanda di partecipazione al concorso indicato in oggetto, si invia in allegato la relativa esclusione.<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(esclusioneObject.getContentStream().getStream(), esclusioneObject.getContentStreamMimeType()), esclusioneObject.getName(), esclusioneObject.getName());
if (!attachmentRelated.isEmpty()) {
for (Document doc : attachmentRelated) {
simplePECMail.attach(new ByteArrayDataSource(doc.getContentStream().getStream(), doc.getContentStreamMimeType()), doc.getName(), doc.getName());
aclService.addAcl(bindingSession, doc.getPropertyValue(CoolPropertyIds.ALFCMIS_NODEREF.value()), Stream.of(new AbstractMap.SimpleEntry<>(user, ACLType.Consumer)).collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)));
}
}
simplePECMail.send();
Map<String, Object> properties = new HashMap<String, Object>();
properties.put(JCONON_ESCLUSIONE_STATO, StatoComunicazione.SPEDITO.name());
esclusioneObject.updateProperties(properties);
index++;
} catch (EmailException | AddressException e) {
LOGGER.error("Cannot send email to {}", address, e);
}
if (Optional.ofNullable(ioClient).isPresent()) {
Optional<String> fiscalCode = esclusioneObject.getParents().stream().findAny().flatMap(folder -> Optional.ofNullable(folder.<String>getPropertyValue(JCONONPropertyIds.APPLICATION_CODICE_FISCALE.value())));
if (fiscalCode.isPresent()) {
try {
NewMessage newMessage = new NewMessage();
newMessage.setTimeToLive(7200);
newMessage.setFiscalCode(fiscalCode.get());
MessageContent2 messageContent2 = new MessageContent2();
messageContent2.setSubject(StringUtils.rightPad("Bando ".concat(call.getProperty(JCONONPropertyIds.CALL_CODICE.value()).getValueAsString()), 10));
messageContent2.setMarkdown("# Esclusione\n" + "In riferimento alla Sua domanda di partecipazione al concorso indicato in oggetto, Le inviamo la seguente *Esclusione*, che può essere scaricata attraverso il seguente link:\n" + "\n" + "[Scarica l'Esclusione](" + contentURL + ")\n" + "\n" + "Distinti saluti.");
newMessage.setContent(messageContent2);
if (Optional.ofNullable(ioClient.getProfile(fiscalCode.get())).map(limitedProfile -> Optional.ofNullable(limitedProfile.getSenderAllowed()).orElse(Boolean.TRUE)).orElse(Boolean.FALSE)) {
final InlineResponse201 inlineResponse201 = ioClient.submitMessageforUser(fiscalCode.get(), newMessage);
LOGGER.info("The IO message was successfully sent to {} with Id: {}", fiscalCode.get(), inlineResponse201.getId());
}
} catch (Exception e) {
LOGGER.error("Cannot send IO message to {}", fiscalCode.get(), e);
}
}
}
}
callRepository.removeVerificaPECTask(subject);
callRepository.verificaPECTask(userName, password, subject, JCONON_ESCLUSIONE_STATO);
return index;
}
use of org.apache.chemistry.opencmis.client.bindings.spi.BindingSession in project cool-jconon by consiglionazionaledellericerche.
the class CallService method inviaConvocazioni.
public Long inviaConvocazioni(Session session, BindingSession bindingSession, String query, String contexURL, String userId, String callId, String userName, String password, AddressType addressFromApplication) throws IOException {
Folder call = (Folder) session.getObject(callId);
ItemIterable<QueryResult> convocazioni = session.query(query, false);
long index = 0;
String subject = i18NService.getLabel("subject-info", Locale.ITALIAN) + i18NService.getLabel("subject-confirm-convocazione", Locale.ITALIAN, call.getProperty(JCONONPropertyIds.CALL_CODICE.value()).getValueAsString());
for (QueryResult convocazione : convocazioni.getPage(Integer.MAX_VALUE)) {
Document convocazioneObject = (Document) session.getObject((String) convocazione.getPropertyById(PropertyIds.OBJECT_ID).getFirstValue());
aclService.setInheritedPermission(bindingSession, convocazioneObject.getProperty(CoolPropertyIds.ALFCMIS_NODEREF.value()).getValueAsString(), true);
String contentURL = contexURL + "/rest/application/convocazione?nodeRef=" + convocazioneObject.getId();
String address = obtainAddress(convocazioneObject, "jconon_convocazione:email_pec", "jconon_convocazione:email", addressFromApplication);
String user = convocazioneObject.<String>getPropertyValue(JCONONPropertyIds.ATTACHMENT_USER.value());
List<Document> attachmentRelated = Optional.ofNullable(convocazioneObject.<String>getPropertyValue(JCONONPropertyIds.ATTACHMENT_RELATED.value())).map(s -> Arrays.asList(s.split(","))).orElse(Collections.emptyList()).stream().map(s -> session.getObject(s)).filter(Document.class::isInstance).map(Document.class::cast).collect(Collectors.toList());
SimplePECMail simplePECMail = new SimplePECMail(userName, password);
simplePECMail.setHostName(pecConfiguration.getHostSmtp());
simplePECMail.setSubject(subject + " $$ " + convocazioneObject.getId());
String content = "Con riferimento alla Sua domanda di partecipazione al concorso indicato in oggetto, si invia in allegato la relativa convocazione.<br>" + "Per i candidati che non hanno indicato in domanda un indirizzo PEC o che non lo hanno comunicato in seguito, e' richiesta conferma di ricezione della presente cliccando sul seguente <a href=\"" + contentURL + "\">link</a> , <br/>qualora non dovesse funzionare copi questo [" + contentURL + "] nella barra degli indirizzi del browser.<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(convocazioneObject.getContentStream().getStream(), convocazioneObject.getContentStreamMimeType()), convocazioneObject.getName(), convocazioneObject.getName());
if (!attachmentRelated.isEmpty()) {
for (Document doc : attachmentRelated) {
simplePECMail.attach(new ByteArrayDataSource(doc.getContentStream().getStream(), doc.getContentStreamMimeType()), doc.getName(), doc.getName());
aclService.addAcl(bindingSession, doc.getPropertyValue(CoolPropertyIds.ALFCMIS_NODEREF.value()), Stream.of(new AbstractMap.SimpleEntry<>(user, ACLType.Consumer)).collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)));
}
}
simplePECMail.send();
Map<String, Object> properties = new HashMap<String, Object>();
properties.put(JCONON_CONVOCAZIONE_STATO, StatoComunicazione.SPEDITO.name());
convocazioneObject.updateProperties(properties);
index++;
} catch (EmailException | AddressException e) {
LOGGER.error("Cannot send email to {}", address, e);
}
if (Optional.ofNullable(ioClient).isPresent()) {
Optional<String> fiscalCode = convocazioneObject.getParents().stream().findAny().flatMap(folder -> Optional.ofNullable(folder.<String>getPropertyValue(JCONONPropertyIds.APPLICATION_CODICE_FISCALE.value())));
if (fiscalCode.isPresent()) {
try {
NewMessage newMessage = new NewMessage();
newMessage.setTimeToLive(7200);
newMessage.setFiscalCode(fiscalCode.get());
MessageContent2 messageContent2 = new MessageContent2();
messageContent2.setSubject(StringUtils.rightPad("Bando ".concat(call.getProperty(JCONONPropertyIds.CALL_CODICE.value()).getValueAsString()), 10));
messageContent2.setMarkdown("# Convocazione\n" + "In riferimento alla Sua domanda di partecipazione al concorso indicato in oggetto, Le inviamo la seguente *Convocazione*, che può essere scaricata attraverso il seguente link:\n" + "\n" + "[Scarica la Convocazione](" + contentURL + ")\n" + "\n" + "Distinti saluti.");
newMessage.setContent(messageContent2);
if (Optional.ofNullable(ioClient.getProfile(fiscalCode.get())).map(limitedProfile -> Optional.ofNullable(limitedProfile.getSenderAllowed()).orElse(Boolean.TRUE)).orElse(Boolean.FALSE)) {
final InlineResponse201 inlineResponse201 = ioClient.submitMessageforUser(fiscalCode.get(), newMessage);
LOGGER.info("The IO message was successfully sent to {} with Id: {}", fiscalCode.get(), inlineResponse201.getId());
}
} catch (Exception e) {
LOGGER.error("Cannot send IO message to {}", fiscalCode.get(), e);
}
}
}
}
callRepository.removeVerificaPECTask(subject);
callRepository.verificaPECTask(userName, password, subject, JCONON_CONVOCAZIONE_STATO);
return index;
}
use of org.apache.chemistry.opencmis.client.bindings.spi.BindingSession 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 org.apache.chemistry.opencmis.client.bindings.spi.BindingSession in project cool-jconon by consiglionazionaledellericerche.
the class ExportApplicationsService method exportApplications.
public Map<String, String> exportApplications(Session currentSession, BindingSession bindingSession, String nodeRefBando, CMISUser user, boolean all, boolean active, JSONArray types) {
Folder bando = (Folder) currentSession.getObject(nodeRefBando);
String finalApplicationName = Call.refactoringFileName(Arrays.asList("BANDO", bando.<String>getPropertyValue(JCONONPropertyIds.CALL_CODICE.value()), Optional.ofNullable(bando.<String>getPropertyValue(JCONONPropertyIds.CALL_SEDE.value())).map(s -> s.replaceAll("[^a-zA-Z0-9]+", " ")).orElse("")).stream().collect(Collectors.joining("_")), "_");
Map<String, String> result;
if (all) {
List<String> documents = new ArrayList<String>();
Criteria criteriaDomande = CriteriaFactory.createCriteria(JCONONFolderType.JCONON_APPLICATION.queryName());
criteriaDomande.addColumn(PropertyIds.OBJECT_ID);
criteriaDomande.add(Restrictions.inTree(nodeRefBando));
criteriaDomande.add(Restrictions.eq(JCONONPropertyIds.APPLICATION_STATO_DOMANDA.value(), ApplicationService.StatoDomanda.CONFERMATA.getValue()));
if (active) {
criteriaDomande.add(Restrictions.isNull(JCONONPropertyIds.APPLICATION_ESCLUSIONE_RINUNCIA.value()));
}
ItemIterable<QueryResult> domande = criteriaDomande.executeQuery(currentSession, false, currentSession.getDefaultContext());
for (QueryResult queryResultDomande : domande.getPage(Integer.MAX_VALUE)) {
String applicationAttach = competitionService.findAttachmentId(currentSession, (String) queryResultDomande.getPropertyById(PropertyIds.OBJECT_ID).getFirstValue(), JCONONDocumentType.JCONON_ATTACHMENT_APPLICATION, true);
if (applicationAttach != null) {
documents.add(applicationAttach);
}
}
if (documents.isEmpty()) {
// Se non ci sono domande definitive finalCall non viene creata
throw new ClientMessageException("Il bando " + finalApplicationName + " non presenta domande definitive");
}
result = invokePost(documents, finalApplicationName, bindingSession, user, true, types);
} else {
List<String> documents = callService.findDocumentFinal(currentSession, bindingSession, nodeRefBando, JCONONDocumentType.JCONON_ATTACHMENT_APPLICATION);
if (documents.isEmpty()) {
// Se non ci sono domande definitive finalCall non viene creata
throw new ClientMessageException("Il bando " + finalApplicationName + " non presenta domande definitive");
}
result = invokePost(documents, finalApplicationName, bindingSession, user, false, null);
}
LOGGER.info("ExportApplicationsService - File " + finalApplicationName + ".zip creata");
return result;
}
use of org.apache.chemistry.opencmis.client.bindings.spi.BindingSession in project cool-jconon by consiglionazionaledellericerche.
the class ExportApplicationServiceTest method exportApplicationsServiceTestUnautorized.
@Test
public void exportApplicationsServiceTestUnautorized() {
BindingSession bindingSession = cmisService.createBindingSession(guestUserName, guestPassword);
assertThrows(CmisUnauthorizedException.class, () -> {
exportApplicationsService.exportApplications(cmisService.getRepositorySession(guestUserName, guestPassword), bindingSession, call.getPropertyValue(PropertyIds.OBJECT_ID), userService.loadUser(guestUserName, bindingSession), false, false, null);
});
}
Aggregations