use of it.cnr.cool.cmis.model.ACLType in project cool-jconon by consiglionazionaledellericerche.
the class CallService method internalEsclusioni.
protected Long internalEsclusioni(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 query = mRequest.getParameter("query");
boolean stampaPunteggi = Boolean.valueOf(mRequest.getParameter("stampaPunteggi"));
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.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()));
applicationsId.stream().filter(string -> !string.isEmpty()).findAny().map(map -> criteriaApplications.add(Restrictions.in(PropertyIds.OBJECT_ID, applicationsId.toArray())));
long result = 0;
ItemIterable<QueryResult> applications;
if (applicationsId.stream().filter(string -> !string.isEmpty()).findAny().filter(s -> s.length() > 0).isPresent()) {
applications = criteriaApplications.executeQuery(session, false, session.getDefaultContext());
} else {
applications = session.query(query, false, session.getDefaultContext());
}
for (QueryResult application : applications.getPage(Integer.MAX_VALUE)) {
Folder applicationObject = (Folder) session.getObject((String) application.getPropertyById(PropertyIds.OBJECT_ID).getFirstValue());
List<String> proveConseguite = new ArrayList<String>();
boolean flPunteggioTitoli = Optional.ofNullable(applicationObject.<Boolean>getPropertyValue("jconon_application:fl_punteggio_titoli")).orElse(false), flPunteggioScritto = Optional.ofNullable(applicationObject.<Boolean>getPropertyValue("jconon_application:fl_punteggio_scritto")).orElse(false), flPunteggioSecondoScritto = Optional.ofNullable(applicationObject.<Boolean>getPropertyValue("jconon_application:fl_punteggio_secondo_scritto")).orElse(false), flPunteggioColloquio = Optional.ofNullable(applicationObject.<Boolean>getPropertyValue("jconon_application:fl_punteggio_colloquio")).orElse(false), flPunteggioProvaPratica = Optional.ofNullable(applicationObject.<Boolean>getPropertyValue("jconon_application:fl_punteggio_prova_pratica")).orElse(false), flPunteggio6 = Optional.ofNullable(applicationObject.<Boolean>getPropertyValue("jconon_application:fl_punteggio_6")).orElse(false);
result++;
if (flPunteggioTitoli)
proveConseguite.add(call.getPropertyValue(PrintService.JCONON_CALL_PUNTEGGIO_1));
if (flPunteggioScritto)
proveConseguite.add(call.getPropertyValue(PrintService.JCONON_CALL_PUNTEGGIO_2));
if (flPunteggioSecondoScritto)
proveConseguite.add(call.getPropertyValue(PrintService.JCONON_CALL_PUNTEGGIO_3));
if (flPunteggioColloquio)
proveConseguite.add(call.getPropertyValue(PrintService.JCONON_CALL_PUNTEGGIO_4));
if (flPunteggioProvaPratica)
proveConseguite.add(call.getPropertyValue(PrintService.JCONON_CALL_PUNTEGGIO_5));
if (flPunteggio6)
proveConseguite.add(call.getPropertyValue(PrintService.JCONON_CALL_PUNTEGGIO_6));
final Optional<String> attachmentId = Optional.ofNullable(competitionService.findAttachmentId(session, applicationObject.getId(), JCONONDocumentType.JCONON_ATTACHMENT_ESCLUSIONE));
if (attachmentId.isPresent()) {
if (Optional.ofNullable(session.getObject(attachmentId.get()).<String>getPropertyValue(JCONON_ESCLUSIONE_STATO)).filter(s -> s.equalsIgnoreCase(StatoComunicazione.GENERATO.name())).isPresent()) {
continue;
}
}
StrSubstitutor sub = formatPlaceHolder(applicationObject, applicationObject.getFolderParent());
byte[] bytes = printService.printEsclusione(session, applicationObject, contextURL, locale, stampaPunteggi, sub.replace(note), firma, proveConseguite.stream().collect(Collectors.joining(", ")));
String name = "ESCLUSIONE_" + 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";
Map<String, Object> properties = new HashMap<String, Object>();
properties.put(PropertyIds.OBJECT_TYPE_ID, JCONONDocumentType.JCONON_ATTACHMENT_ESCLUSIONE.value());
properties.put(PropertyIds.NAME, name);
properties.put(JCONONPropertyIds.ATTACHMENT_USER.value(), applicationObject.getPropertyValue(JCONONPropertyIds.APPLICATION_USER.value()));
properties.put(JCONON_ESCLUSIONE_STATO, StatoComunicazione.GENERATO.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()));
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.cool.cmis.model.ACLType in project cool-jconon by consiglionazionaledellericerche.
the class CallService method publish.
public Folder publish(Session cmisSession, BindingSession currentBindingSession, String userId, String objectId, boolean publish, String contextURL, Locale locale) {
final Folder call = (Folder) cmisSession.getObject(objectId);
CMISUser user = userService.loadUserForConfirm(userId);
if (!(user.isAdmin() || isMemberOfConcorsiGroup(user) || call.getPropertyValue(PropertyIds.CREATED_BY).equals(userId)))
throw new ClientMessageException("message.error.call.cannot.publish");
Map<String, ACLType> aces = new HashMap<String, ACLType>();
aces.put(JcononGroups.EVERYONE.group(), ACLType.Consumer);
GregorianCalendar dataInizioInvioDomande = call.getPropertyValue(JCONONPropertyIds.CALL_DATA_INIZIO_INVIO_DOMANDE.value());
if (!publish && !(user.isAdmin() || isMemberOfConcorsiGroup(user))) {
if (!dataInizioInvioDomande.after(Calendar.getInstance()))
throw new ClientMessageException("message.error.call.cannot.publish");
}
if (JCONONPolicyType.isIncomplete(call))
throw new ClientMessageException("message.error.call.incomplete");
if (call.getType().getId().equalsIgnoreCase(JCONONFolderType.JCONON_CALL_MOBILITY.value()) || call.getType().getId().equalsIgnoreCase(JCONONFolderType.JCONON_CALL_MOBILITY_OPEN.value())) {
if (!isCallAttachmentPresent(cmisSession, call, JCONONDocumentType.JCONON_ATTACHMENT_CALL_MOBILITY)) {
throw new ClientMessageException("message.error.call.mobility.incomplete.attachment");
}
} else if (call.getType().getId().equalsIgnoreCase(JCONONFolderType.JCONON_CALL_MAN_INTESESSE.value())) {
if (!isCallAttachmentPresent(cmisSession, call, JCONONDocumentType.JCONON_ATTACHMENT_CALL_MANIFESTAZIONE_INTERESSE)) {
throw new ClientMessageException("message.error.call.man.intesse.incomplete.attachment");
}
} else {
if (!isCallAttachmentPresent(cmisSession, call, JCONONDocumentType.JCONON_ATTACHMENT_CALL_IT))
throw new ClientMessageException("message.error.call.incomplete.attachment");
}
if (dataInizioInvioDomande != null && call.getParentId().equals(competitionService.getCompetitionFolder().get("id"))) {
moveCall(cmisSession, dataInizioInvioDomande, call);
}
if (publish && call.<List<String>>getPropertyValue(JCONONPropertyIds.CALL_ELENCO_SEZIONI_DOMANDA.value()).stream().filter(s -> s.equalsIgnoreCase("affix_tabDichiarazioni")).findAny().isPresent() && Optional.ofNullable(call.<List<String>>getPropertyValue(JCONONPropertyIds.CALL_ELENCO_ASPECTS.value())).map(List::isEmpty).orElse(Boolean.TRUE)) {
throw new ClientMessageException("message.error.call.incomplete.section.affix_tabDichiarazioni");
}
if (publish && call.<List<String>>getPropertyValue(JCONONPropertyIds.CALL_ELENCO_SEZIONI_DOMANDA.value()).stream().filter(s -> s.equalsIgnoreCase("affix_tabUlterioriDati")).findAny().isPresent() && Optional.ofNullable(call.<List<String>>getPropertyValue(JCONONPropertyIds.CALL_ELENCO_ASPECTS_ULTERIORI_DATI.value())).map(List::isEmpty).orElse(Boolean.TRUE)) {
throw new ClientMessageException("message.error.call.incomplete.section.affix_tabUlterioriDati");
}
if (publish && call.<List<String>>getPropertyValue(JCONONPropertyIds.CALL_ELENCO_SEZIONI_DOMANDA.value()).stream().filter(s -> s.equalsIgnoreCase("affix_tabDatiCNR")).findAny().isPresent() && Optional.ofNullable(call.<List<String>>getPropertyValue(JCONONPropertyIds.CALL_ELENCO_ASPECTS_SEZIONE_CNR.value())).map(List::isEmpty).orElse(Boolean.TRUE)) {
throw new ClientMessageException("message.error.call.incomplete.section.affix_tabDatiCNR");
}
if (publish && call.<List<String>>getPropertyValue(JCONONPropertyIds.CALL_ELENCO_SEZIONI_DOMANDA.value()).stream().filter(s -> s.equalsIgnoreCase("affix_tabTitoli")).findAny().isPresent() && Optional.ofNullable(call.<List<String>>getPropertyValue(JCONONPropertyIds.CALL_ELENCO_ASSOCIATIONS.value())).map(List::isEmpty).orElse(Boolean.TRUE)) {
throw new ClientMessageException("message.error.call.incomplete.section.affix_tabTitoli");
}
if (publish && call.<List<String>>getPropertyValue(JCONONPropertyIds.CALL_ELENCO_SEZIONI_DOMANDA.value()).stream().filter(s -> s.equalsIgnoreCase("affix_tabCurriculum")).findAny().isPresent() && Optional.ofNullable(call.<List<String>>getPropertyValue(JCONONPropertyIds.CALL_ELENCO_SEZIONE_CURRICULUM.value())).map(List::isEmpty).orElse(Boolean.TRUE)) {
throw new ClientMessageException("message.error.call.incomplete.section.affix_tabCurriculum");
}
if (publish && call.<List<String>>getPropertyValue(JCONONPropertyIds.CALL_ELENCO_SEZIONI_DOMANDA.value()).stream().filter(s -> s.equalsIgnoreCase("affix_tabElencoProdotti")).findAny().isPresent() && Optional.ofNullable(call.<List<String>>getPropertyValue(JCONONPropertyIds.CALL_ELENCO_SEZIONE_PRODOTTI.value())).map(List::isEmpty).orElse(Boolean.TRUE)) {
throw new ClientMessageException("message.error.call.incomplete.section.affix_tabElencoProdotti");
}
Map<String, Object> properties = new HashMap<String, Object>();
properties.put(JCONONPropertyIds.CALL_PUBBLICATO.value(), publish);
if (publish) {
creaGruppoCommissione(call, userId);
if (call.getPropertyValue(JCONONPropertyIds.CALL_ID_CATEGORIA_TECNICO_HELPDESK.value()) == null) {
Integer idCategoriaCallType = helpdeskService.getCategoriaMaster(call.getType().getId());
Integer idCategoriaHelpDESK = helpdeskService.createCategoria(idCategoriaCallType, "BANDO " + getCodiceBandoTruncated(call), "BANDO " + call.getPropertyValue(JCONONPropertyIds.CALL_CODICE.value()));
Integer idCategoriaTecnicoHelpDESK = helpdeskService.createCategoria(idCategoriaHelpDESK, "Problema Tecnico", "Problema Tecnico");
Integer idCategoriaNormativaHelpDESK = helpdeskService.createCategoria(idCategoriaHelpDESK, "Problema Normativo", "Problema Normativo");
properties.put(JCONONPropertyIds.CALL_ID_CATEGORIA_TECNICO_HELPDESK.value(), idCategoriaTecnicoHelpDESK);
properties.put(JCONONPropertyIds.CALL_ID_CATEGORIA_NORMATIVA_HELPDESK.value(), idCategoriaNormativaHelpDESK);
}
aces.put(JcononGroups.CONCORSI.group(), ACLType.Coordinator);
aclService.addAcl(currentBindingSession, call.getProperty(CoolPropertyIds.ALFCMIS_NODEREF.value()).getValueAsString(), aces);
} else {
aclService.removeAcl(currentBindingSession, call.getProperty(CoolPropertyIds.ALFCMIS_NODEREF.value()).getValueAsString(), aces);
}
call.updateProperties(properties, true);
return call;
}
use of it.cnr.cool.cmis.model.ACLType in project cool-jconon by consiglionazionaledellericerche.
the class CallService method creaGruppoCommissione.
private void creaGruppoCommissione(final Folder call, String userId) {
if (call.getPropertyValue(JCONONPropertyIds.CALL_COMMISSIONE.value()) != null)
return;
// Creazione del gruppo per la commissione di Concorso
final String groupRdPName = getCallGroupRdPName(call);
final String groupCommissioneName = createGroupCommissioneName(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.COMMISSIONI_CONCORSO.group() + "\",");
groupJson = groupJson.concat("\"group_name\":\"" + groupCommissioneName + "\",");
groupJson = groupJson.concat("\"display_name\":\"" + "COMMISSIONE 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 nodeRef = jsonObject.optString("nodeRef");
if (nodeRef == "")
return;
/**
* Aggiorno il bando con il NodeRef del gruppo commissione
*/
Map<String, Object> propertiesCommissione = new HashMap<String, Object>();
propertiesCommissione.put(JCONONPropertyIds.CALL_COMMISSIONE.value(), groupCommissioneName);
call.updateProperties(propertiesCommissione, true);
/**
* Il Gruppo della Commissione deve avere il ruolo di contributor sul bando
*/
addContibutorCommission(groupCommissioneName, call.getProperty(CoolPropertyIds.ALFCMIS_NODEREF.value()).getValueAsString());
Map<String, ACLType> acesGroup = new HashMap<String, ACLType>();
acesGroup.put(JcononGroups.CONCORSI.group(), ACLType.FullControl);
acesGroup.put("GROUP_" + groupRdPName, ACLType.FullControl);
aclService.addAcl(cmisService.getAdminSession(), nodeRef, acesGroup);
} catch (Exception e) {
LOGGER.error("ACL error", e);
}
}
Aggregations