use of it.cnr.cool.cmis.model.ACLType in project cool-jconon by consiglionazionaledellericerche.
the class CallService method importEsclusioniFirmate.
public Long importEsclusioniFirmate(Session session, HttpServletRequest req, CMISUser user) throws IOException, ParseException {
final String userId = user.getId();
long index = 0;
MultipartHttpServletRequest mRequest = resolver.resolveMultipart(req);
String idCall = mRequest.getParameter("callId");
String tipo = mRequest.getParameter("tipo");
Calendar calDataProtocollo = Calendar.getInstance();
Date dataProtocollo = StringUtil.CMIS_DATEFORMAT.parse(mRequest.getParameter(JCONONPropertyIds.PROTOCOLLO_DATA.value()));
calDataProtocollo.setTime(dataProtocollo);
String numeroProtocollo = mRequest.getParameter(JCONONPropertyIds.PROTOCOLLO_NUMERO.value());
MultipartFile file = mRequest.getFile("file");
if (!Optional.ofNullable(mRequest.getParameterValues("application")).isPresent())
throw new ClientMessageException("Bisogna selezionare almeno una domanda!");
String[] applications = mRequest.getParameterValues("application");
for (String application : applications) {
Folder applicationObject = (Folder) session.getObject(application);
Map<String, Object> properties = new HashMap<String, Object>();
properties.put(PropertyIds.OBJECT_TYPE_ID, JCONONDocumentType.JCONON_ATTACHMENT_ESCLUSIONE.value());
properties.put(PropertyIds.NAME, file.getOriginalFilename());
properties.put(JCONONPropertyIds.ATTACHMENT_USER.value(), applicationObject.getPropertyValue(JCONONPropertyIds.APPLICATION_USER.value()));
properties.put(JCONON_ESCLUSIONE_STATO, StatoComunicazione.FIRMATO.name());
properties.put("jconon_esclusione:email", applicationObject.getPropertyValue(JCONONPropertyIds.APPLICATION_EMAIL_COMUNICAZIONI.value()));
properties.put("jconon_esclusione:email_pec", applicationObject.getPropertyValue(JCONONPropertyIds.APPLICATION_EMAIL_PEC_COMUNICAZIONI.value()));
properties.put(JCONONPropertyIds.PROTOCOLLO_NUMERO.value(), numeroProtocollo);
properties.put(JCONONPropertyIds.PROTOCOLLO_DATA.value(), calDataProtocollo);
properties.put(PropertyIds.SECONDARY_OBJECT_TYPE_IDS, Arrays.asList(JCONONPolicyType.JCONON_ATTACHMENT_GENERIC_DOCUMENT.value(), JCONONPolicyType.JCONON_ATTACHMENT_FROM_RDP.value(), JCONONPolicyType.JCONON_PROTOCOLLO.value()));
ContentStreamImpl contentStream = new ContentStreamImpl();
contentStream.setStream(file.getInputStream());
contentStream.setMimeType("application/pdf");
applicationObject.createDocument(properties, contentStream, VersioningState.MAJOR);
Map<String, Serializable> propertiesApplication = new HashMap<String, Serializable>();
propertiesApplication.put("jconon_application:esclusione_rinuncia", tipo.equalsIgnoreCase("RINUNCIA") ? "R" : "E");
cmisService.createAdminSession().getObject(applicationObject).updateProperties(propertiesApplication);
Map<String, ACLType> acesToRemove = new HashMap<String, ACLType>();
List<String> groups = getGroupsCallToApplication(applicationObject.getFolderParent());
for (String group : groups) {
acesToRemove.put(group, ACLType.Contributor);
}
aclService.removeAcl(cmisService.getAdminSession(), applicationObject.getProperty(CoolPropertyIds.ALFCMIS_NODEREF.value()).getValueAsString(), acesToRemove);
index++;
}
return index;
}
use of it.cnr.cool.cmis.model.ACLType in project cool-jconon by consiglionazionaledellericerche.
the class CallService method save.
public Folder save(Session cmisSession, BindingSession bindingSession, String contextURL, Locale locale, String userId, Map<String, Object> properties, Map<String, Object> aspectProperties) {
Folder call;
properties.putAll(aspectProperties);
String codiceBando = (String) properties.get(JCONONPropertyIds.CALL_CODICE.value());
/**
* Verifico inizialmente se sto in creazione del Bando
*/
if (codiceBando == null)
throw new ClientMessageException("message.error.required.codice");
if (!isAlphaNumeric(codiceBando)) {
throw new ClientMessageException("message.error.codice.not.valid");
}
String name = Optional.ofNullable(i18NService.getLabel("call.name", locale)).orElse("").concat(codiceBando);
if (properties.get(JCONONPropertyIds.CALL_SEDE.value()) != null)
name = name.concat(" - ").concat(properties.get(JCONONPropertyIds.CALL_SEDE.value()).toString());
properties.put(PropertyIds.NAME, folderService.integrityChecker(name));
GregorianCalendar dataInizioInvioDomande = (GregorianCalendar) properties.get(JCONONPropertyIds.CALL_DATA_INIZIO_INVIO_DOMANDE.value());
Map<String, Object> otherProperties = new HashMap<String, Object>();
if (properties.get(PropertyIds.OBJECT_ID) == null) {
if (properties.get(PropertyIds.PARENT_ID) == null)
properties.put(PropertyIds.PARENT_ID, competitionService.getCompetitionFolder().get("id"));
call = (Folder) cmisSession.getObject(cmisSession.createFolder(properties, new ObjectIdImpl((String) properties.get(PropertyIds.PARENT_ID))));
aclService.setInheritedPermission(bindingSession, call.getProperty(CoolPropertyIds.ALFCMIS_NODEREF.value()).getValueAsString(), false);
if (dataInizioInvioDomande != null && properties.get(PropertyIds.PARENT_ID) == null) {
moveCall(cmisSession, dataInizioInvioDomande, call);
}
} else {
call = (Folder) cmisSession.getObject((String) properties.get(PropertyIds.OBJECT_ID));
CMISUser user = userService.loadUserForConfirm(userId);
if ((Boolean) call.getPropertyValue(JCONONPropertyIds.CALL_PUBBLICATO.value()) && !(user.isAdmin() || isMemberOfConcorsiGroup(user))) {
if (!existsProvvedimentoProrogaTermini(cmisSession, call))
throw new ClientMessageException("message.error.call.cannnot.modify");
}
call.updateProperties(properties, true);
if (!call.getParentId().equals(properties.get(PropertyIds.PARENT_ID)) && properties.get(PropertyIds.PARENT_ID) != null)
call.move(call.getFolderParent(), new ObjectIdImpl((String) properties.get(PropertyIds.PARENT_ID)));
}
otherProperties.put(JCONONPropertyIds.CALL_HAS_MACRO_CALL.value(), cmisSession.getObject(call.getParentId()).getType().getId().equals(call.getType().getId()));
List<Object> secondaryTypes = call.getProperty(PropertyIds.SECONDARY_OBJECT_TYPE_IDS).getValues();
if (!typeService.hasSecondaryType(call, JCONONPolicyType.JCONON_MACRO_CALL.value())) {
secondaryTypes.add(JCONONPolicyType.JCONON_CALL_SUBMIT_APPLICATION.value());
} else {
secondaryTypes.remove(JCONONPolicyType.JCONON_CALL_SUBMIT_APPLICATION.value());
}
otherProperties.put(PropertyIds.SECONDARY_OBJECT_TYPE_IDS, secondaryTypes);
call.updateProperties(otherProperties);
creaGruppoRdP(call, userId);
Map<String, ACLType> aces = new HashMap<String, ACLType>();
aces.put(JcononGroups.CONCORSI.group(), ACLType.Coordinator);
aclService.addAcl(bindingSession, call.getProperty(CoolPropertyIds.ALFCMIS_NODEREF.value()).getValueAsString(), aces);
return call;
}
use of it.cnr.cool.cmis.model.ACLType 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 it.cnr.cool.cmis.model.ACLType in project cool-jconon by consiglionazionaledellericerche.
the class CallService method creaGruppoRdP.
protected void creaGruppoRdP(final Folder call, String userId) {
if (call.getPropertyValue(JCONONPropertyIds.CALL_RDP.value()) != null)
return;
// Creazione del gruppo per i Responsabili del Procedimento
final String groupRdPName = createGroupRdPName(call);
try {
String link = cmisService.getBaseURL().concat("service/cnr/groups/group");
UrlBuilder url = new UrlBuilder(link);
Response response = CmisBindingsHelper.getHttpInvoker(cmisService.getAdminSession()).invokePOST(url, MimeTypes.JSON.mimetype(), new Output() {
@Override
public void write(OutputStream out) throws Exception {
String groupJson = "{";
groupJson = groupJson.concat("\"parent_group_name\":\"" + JcononGroups.RDP_CONCORSO.group() + "\",");
groupJson = groupJson.concat("\"group_name\":\"" + groupRdPName + "\",");
groupJson = groupJson.concat("\"display_name\":\"" + "RESPONSABILI BANDO [".concat(call.getPropertyValue(JCONONPropertyIds.CALL_CODICE.value())) + "]\",");
groupJson = groupJson.concat("\"zones\":[\"AUTH.ALF\",\"APP.DEFAULT\"]");
groupJson = groupJson.concat("}");
out.write(groupJson.getBytes());
}
}, cmisService.getAdminSession());
JSONObject jsonObject = new JSONObject(StringUtil.convertStreamToString(response.getStream()));
String nodeRefRdP = jsonObject.optString("nodeRef");
if (nodeRefRdP == "")
return;
/**
* Aggiorno il bando con il NodeRef del gruppo commissione
*/
Map<String, Object> propertiesRdP = new HashMap<String, Object>();
propertiesRdP.put(JCONONPropertyIds.CALL_RDP.value(), groupRdPName);
call.updateProperties(propertiesRdP, true);
/**
* Il Gruppo dei responsabili del procedimento deve avere il controllo completo sul bando
*/
addCoordinatorRdp(groupRdPName, call.getProperty(CoolPropertyIds.ALFCMIS_NODEREF.value()).getValueAsString());
Map<String, ACLType> acesGroup = new HashMap<String, ACLType>();
acesGroup.put(userId, ACLType.FullControl);
acesGroup.put(JcononGroups.CONCORSI.group(), ACLType.FullControl);
aclService.addAcl(cmisService.getAdminSession(), nodeRefRdP, acesGroup);
} catch (Exception e) {
LOGGER.error("ACL error", e);
}
}
use of it.cnr.cool.cmis.model.ACLType 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;
}
Aggregations