use of it.cnr.si.opencmis.criteria.Criteria in project cool-jconon by consiglionazionaledellericerche.
the class CallService method deleteApplicationInitial.
public void deleteApplicationInitial(Session session) {
Calendar midNight = Calendar.getInstance();
midNight.set(Calendar.HOUR, 0);
midNight.set(Calendar.MINUTE, 0);
midNight.set(Calendar.SECOND, 0);
Criteria criteria = CriteriaFactory.createCriteria(JCONONFolderType.JCONON_CALL.queryName());
criteria.add(Restrictions.le(JCONONPropertyIds.CALL_DATA_FINE_INVIO_DOMANDE.value(), ISO8601DATEFORMAT.format(Calendar.getInstance().getTime())));
criteria.add(Restrictions.ge(JCONONPropertyIds.CALL_DATA_FINE_INVIO_DOMANDE.value(), ISO8601DATEFORMAT.format(midNight.getTime())));
ItemIterable<QueryResult> bandi = criteria.executeQuery(session, false, session.getDefaultContext());
for (QueryResult queryResult : bandi.getPage(Integer.MAX_VALUE)) {
Folder call = (Folder) session.getObject((String) queryResult.getPropertyValueById(PropertyIds.OBJECT_ID));
Criteria criteriaDomande = CriteriaFactory.createCriteria(JCONONFolderType.JCONON_APPLICATION.queryName());
criteriaDomande.add(Restrictions.inFolder(call.getId()));
criteriaDomande.add(Restrictions.eq(JCONONPropertyIds.APPLICATION_STATO_DOMANDA.value(), ApplicationService.StatoDomanda.INIZIALE.getValue()));
ItemIterable<QueryResult> domande = criteriaDomande.executeQuery(session, false, session.getDefaultContext());
if (domande.getTotalNumItems() != 0) {
for (QueryResult queryResultDomande : domande.getPage(Integer.MAX_VALUE)) {
Folder domanda = (Folder) session.getObject((String) queryResultDomande.getPropertyValueById(PropertyIds.OBJECT_ID));
LOGGER.info("Delete application initial: {}", domanda.getName());
domanda.delete();
}
}
}
}
use of it.cnr.si.opencmis.criteria.Criteria in project cool-jconon by consiglionazionaledellericerche.
the class ApplicationService method findApplications.
public Map<String, Object> findApplications(Session session, boolean inTree, Integer page, Integer offset, String user, boolean fetchCall, String type, FilterType filterType, String callCode, LocalDate inizioScadenza, LocalDate fineScadenza, String applicationStatus, String firstname, String lastname, String codicefiscale, String callId) {
Map<String, Object> model = new HashMap<String, Object>();
final OperationContext defaultContext = OperationContextUtils.copyOperationContext(session.getDefaultContext());
defaultContext.setMaxItemsPerPage(offset);
Criteria criteriaApplications = CriteriaFactory.createCriteria(JCONONFolderType.JCONON_APPLICATION.queryName(), "root");
criteriaApplications.addColumn(PropertyIds.OBJECT_ID);
criteriaApplications.addColumn(PropertyIds.PARENT_ID);
if (inTree) {
criteriaApplications.add(Restrictions.inTree(Optional.ofNullable(callId).filter(s -> !s.isEmpty()).orElseGet(() -> competitionService.getCompetitionFolder().getString("id"))));
}
criteriaApplications.add(Restrictions.ne(JCONONPropertyIds.APPLICATION_STATO_DOMANDA.value(), StatoDomanda.INIZIALE.value));
if (Optional.ofNullable(user).filter(s -> s.length() > 0).isPresent()) {
criteriaApplications.add(Restrictions.eq(JCONONPropertyIds.APPLICATION_USER.value(), user));
}
final Optional<String> applicationStatusOpt = Optional.ofNullable(applicationStatus).filter(s -> !s.isEmpty()).filter(s -> !s.equalsIgnoreCase("all"));
final Optional<String> typeOpt = Optional.ofNullable(type).filter(s -> !s.isEmpty());
final Optional<String> firstnameOpt = Optional.ofNullable(firstname).filter(s -> !s.isEmpty());
final Optional<String> lastnameOpt = Optional.ofNullable(lastname).filter(s -> !s.isEmpty());
final Optional<String> codicefiscaleOpt = Optional.ofNullable(codicefiscale).filter(s -> !s.isEmpty());
if (applicationStatusOpt.isPresent()) {
switch(applicationStatusOpt.get()) {
case "P":
criteriaApplications.add(Restrictions.eq(JCONONPropertyIds.APPLICATION_STATO_DOMANDA.value(), StatoDomanda.PROVVISORIA.value));
break;
case "C":
criteriaApplications.add(Restrictions.eq(JCONONPropertyIds.APPLICATION_STATO_DOMANDA.value(), StatoDomanda.CONFERMATA.value));
break;
case "active":
criteriaApplications.add(Restrictions.eq(JCONONPropertyIds.APPLICATION_STATO_DOMANDA.value(), StatoDomanda.CONFERMATA.value));
criteriaApplications.add(Restrictions.isNull(JCONONPropertyIds.APPLICATION_ESCLUSIONE_RINUNCIA.value()));
break;
case "excluded":
criteriaApplications.add(Restrictions.isNotNull(JCONONPropertyIds.APPLICATION_ESCLUSIONE_RINUNCIA.value()));
break;
}
}
if (firstnameOpt.isPresent()) {
criteriaApplications.add(Restrictions.contains(JCONONPropertyIds.APPLICATION_NOME.value(), firstnameOpt.map(s -> s.replace("'", "''")).map(s -> "\'*".concat(s).concat("*\''")).orElse("")));
}
if (lastnameOpt.isPresent()) {
criteriaApplications.add(Restrictions.contains(JCONONPropertyIds.APPLICATION_COGNOME.value(), lastnameOpt.map(s -> s.replace("'", "''")).map(s -> "\'*".concat(s).concat("*\''")).orElse("")));
}
if (codicefiscaleOpt.isPresent()) {
criteriaApplications.add(Restrictions.like(JCONONPropertyIds.APPLICATION_CODICE_FISCALE.value(), codicefiscaleOpt.map(String::toUpperCase).map(s -> "%".concat(s).concat("%")).orElse("")));
}
List<Map<String, Object>> items = new ArrayList<>();
ItemIterable<QueryResult> applications = criteriaApplications.executeQuery(session, false, defaultContext);
long totalNumItems = applications.getTotalNumItems();
for (QueryResult result : applications.skipTo(page * defaultContext.getMaxItemsPerPage()).getPage(defaultContext.getMaxItemsPerPage())) {
final Map<String, Object> applicationMap = CMISUtil.convertToProperties(session.getObject(result.<String>getPropertyValueById(PropertyIds.OBJECT_ID), defaultContext));
if (fetchCall) {
final Folder call = Optional.ofNullable(session.getObject(result.<String>getPropertyValueById(PropertyIds.PARENT_ID), defaultContext)).filter(Folder.class::isInstance).map(Folder.class::cast).orElseThrow(() -> new CmisInvalidArgumentException("Parent object is not folder!"));
if (typeOpt.isPresent() && !call.getType().getQueryName().equals(typeOpt.get())) {
totalNumItems--;
continue;
}
if (Optional.ofNullable(filterType).isPresent()) {
if ((filterType.equals(FilterType.active) && !callService.isBandoInCorso(call)) || (filterType.equals(FilterType.expire) && callService.isBandoInCorso(call))) {
totalNumItems--;
continue;
}
}
if (Optional.ofNullable(callCode).filter(s -> s.length() > 0).isPresent()) {
if (Optional.ofNullable(call.<String>getPropertyValue(JCONONPropertyIds.CALL_CODICE.value())).map(s -> s.toUpperCase()).filter(s -> !s.contains(callCode.toUpperCase())).isPresent()) {
totalNumItems--;
continue;
}
}
if (Optional.ofNullable(inizioScadenza).isPresent()) {
if (Optional.ofNullable(call.<Calendar>getPropertyValue(JCONONPropertyIds.CALL_DATA_FINE_INVIO_DOMANDE.value())).map(cal -> LocalDateTime.ofInstant(cal.toInstant(), ZoneId.systemDefault())).filter(dateTime -> dateTime.isBefore(inizioScadenza.atStartOfDay())).isPresent()) {
totalNumItems--;
continue;
}
}
if (Optional.ofNullable(fineScadenza).isPresent()) {
if (Optional.ofNullable(call.<Calendar>getPropertyValue(JCONONPropertyIds.CALL_DATA_FINE_INVIO_DOMANDE.value())).map(cal -> LocalDateTime.ofInstant(cal.toInstant(), ZoneId.systemDefault())).filter(dateTime -> dateTime.isAfter(fineScadenza.atStartOfDay())).isPresent()) {
totalNumItems--;
continue;
}
}
applicationMap.put("call", CMISUtil.convertToProperties(call));
}
items.add(applicationMap);
}
model.put("count", totalNumItems);
model.put("page", page);
model.put("offset", defaultContext.getMaxItemsPerPage());
model.put("items", items);
return model;
}
use of it.cnr.si.opencmis.criteria.Criteria 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;
}
use of it.cnr.si.opencmis.criteria.Criteria in project cool-jconon by consiglionazionaledellericerche.
the class CallService method inviaAllegato.
public List<String> inviaAllegato(Session session, BindingSession bindingSession, String objectId, String contexURL, String userId, String callId, String userName, String password) throws IOException {
List<String> result = new ArrayList<String>();
Folder call = (Folder) session.getObject(callId);
Document doc = (Document) session.getObject(objectId);
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()));
ItemIterable<QueryResult> attive = criteriaApplications.executeQuery(session, false, session.getDefaultContext());
for (QueryResult domanda : attive.getPage(Integer.MAX_VALUE)) {
Folder domandaObject = (Folder) session.getObject((String) domanda.getPropertyById(PropertyIds.OBJECT_ID).getFirstValue());
String address = Optional.ofNullable(domandaObject.getProperty(JCONONPropertyIds.APPLICATION_EMAIL_PEC_COMUNICAZIONI.value()).getValueAsString()).orElse(domandaObject.getProperty(JCONONPropertyIds.APPLICATION_EMAIL_COMUNICAZIONI.value()).getValueAsString());
if (env.acceptsProfiles(Profile.DEVELOPMENT.value())) {
address = env.getProperty("mail.to.error.message");
}
SimplePECMail simplePECMail = new SimplePECMail(userName, password);
simplePECMail.setHostName(pecConfiguration.getHostSmtp());
simplePECMail.setSubject(i18NService.getLabel("subject-info", Locale.ITALIAN) + i18NService.getLabel("subject-confirm-comunicazione", Locale.ITALIAN, call.getProperty(JCONONPropertyIds.CALL_CODICE.value()).getValueAsString()));
String content = "Con riferimento alla Sua domanda di partecipazione al concorso indicato in oggetto, si invia in allegato il provvedimento contenente \"" + doc.getType().getDisplayName() + "\"<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(doc.getContentStream().getStream(), doc.getContentStreamMimeType()), doc.getName(), doc.getName());
simplePECMail.send();
result.add(address);
} catch (EmailException | AddressException e) {
LOGGER.error("Cannot send email to {}", address, e);
}
}
return result;
}
use of it.cnr.si.opencmis.criteria.Criteria in project cool-jconon by consiglionazionaledellericerche.
the class CallService method getTotalNumApplication.
public long getTotalNumApplication(Session cmisSession, Folder macroCall, Folder application, String userId, String statoDomanda) {
if (macroCall != null) {
Criteria criteria = CriteriaFactory.createCriteria(JCONONFolderType.JCONON_APPLICATION.queryName());
criteria.addColumn(PropertyIds.OBJECT_ID);
criteria.addColumn(PropertyIds.NAME);
criteria.add(Restrictions.inTree(macroCall.getId()));
if (userId != null) {
criteria.add(Restrictions.eq(JCONONPropertyIds.APPLICATION_USER.value(), userId));
}
if (statoDomanda != null) {
criteria.add(Restrictions.eq(JCONONPropertyIds.APPLICATION_STATO_DOMANDA.value(), statoDomanda));
}
if (application != null) {
criteria.add(Restrictions.ne(PropertyIds.OBJECT_ID, application.getId()));
}
ItemIterable<QueryResult> iterable = criteria.executeQuery(cmisSession, false, cmisSession.getDefaultContext());
return iterable.getTotalNumItems();
} else {
return 0;
}
}
Aggregations