use of it.cnr.si.opencmis.criteria.Criteria 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 it.cnr.si.opencmis.criteria.Criteria in project cool-jconon by consiglionazionaledellericerche.
the class HelpDeskServiceTest method before.
@BeforeEach
@Disabled
public void before() throws ParseException, InterruptedException, CoolUserFactoryException {
// Seleziono uno dei bandi attivi
OperationContext oc = new OperationContextImpl(cmisDefaultOperationContext);
oc.setMaxItemsPerPage(1);
Session adminSession = cmisService.createAdminSession();
Calendar startDate = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
Criteria criteria = CriteriaFactory.createCriteria(JCONONFolderType.JCONON_CALL.queryName());
ItemIterable<QueryResult> queryResult = criteria.executeQuery(adminSession, false, oc);
MockHttpServletRequest req = new MockHttpServletRequest();
BindingSession bindingSession = cmisService.getAdminSession();
cmisUser = userService.loadUser("admin", bindingSession);
for (QueryResult qr : queryResult) {
call = (Folder) adminSession.getObject(new ObjectIdImpl(qr.getPropertyValueById(PropertyIds.OBJECT_ID)));
CALL = call.getName();
break;
}
postMap = new HashMap<String, String>();
postMap.put("firstName", cmisUser.getFirstName());
postMap.put("lastName", cmisUser.getLastName());
postMap.put("phoneNumber", cmisUser.getTelephone());
postMap.put("email", cmisUser.getEmail());
postMap.put("confirmEmail", cmisUser.getEmail());
postMap.put("category", ID_CATEGORY);
postMap.put("subject", SUBJECT);
postMap.put("message", MESSAGE);
postMap.put("problemType", PROBLEM_TYPE);
postMap.put("matricola", MATRICOLA);
postMap.put("call", CALL);
}
use of it.cnr.si.opencmis.criteria.Criteria in project cool-jconon by consiglionazionaledellericerche.
the class CallRepository method findAttachmentLabels.
public String findAttachmentLabels(Session cmisSession, String source) {
Criteria criteria = CriteriaFactory.createCriteria(BaseTypeId.CMIS_DOCUMENT.value());
criteria.addColumn(PropertyIds.OBJECT_ID);
criteria.addColumn(PropertyIds.NAME);
criteria.add(Restrictions.inFolder(source));
criteria.add(Restrictions.eq(PropertyIds.NAME, LABELS_JSON));
ItemIterable<QueryResult> iterable = criteria.executeQuery(cmisSession, false, cmisSession.getDefaultContext());
for (QueryResult queryResult : iterable) {
return queryResult.<String>getPropertyById(PropertyIds.OBJECT_ID).getFirstValue();
}
return null;
}
use of it.cnr.si.opencmis.criteria.Criteria in project cool-jconon by consiglionazionaledellericerche.
the class CacheRepository method getCompetitionFolder.
@Cacheable(COMPETITION)
public CmisObjectCache getCompetitionFolder() {
LOGGER.info("Try to connect to repository base url: {}", baseURL);
Folder competition = null;
Session session = cmisService.createAdminSession();
Criteria criteria = CriteriaFactory.createCriteria(JCONONFolderType.JCONON_COMPETITION.queryName());
ItemIterable<QueryResult> results = criteria.executeQuery(session, false, session.getDefaultContext());
if (results.getTotalNumItems() == 0) {
competition = (Folder) session.getObject(session.createFolder(Collections.unmodifiableMap(Stream.of(new AbstractMap.SimpleEntry<>(PropertyIds.OBJECT_TYPE_ID, JCONONFolderType.JCONON_COMPETITION.value()), new AbstractMap.SimpleEntry<>(PropertyIds.NAME, Optional.ofNullable(i18NService.getLabel("app.name", Locale.ITALIAN)).orElse("Selezioni on-line"))).collect(Collectors.toMap((e) -> e.getKey(), (e) -> e.getValue()))), session.getRootFolder()));
/**
* Creo le folder per i documenti
*/
final ObjectId documents = session.createFolder(Collections.unmodifiableMap(Stream.of(new AbstractMap.SimpleEntry<>(PropertyIds.OBJECT_TYPE_ID, BaseTypeId.CMIS_FOLDER.value()), new AbstractMap.SimpleEntry<>(PropertyIds.NAME, "documents")).collect(Collectors.toMap((e) -> e.getKey(), (e) -> e.getValue()))), competition);
session.createFolder(Collections.unmodifiableMap(Stream.of(new AbstractMap.SimpleEntry<>(PropertyIds.OBJECT_TYPE_ID, BaseTypeId.CMIS_FOLDER.value()), new AbstractMap.SimpleEntry<>(PropertyIds.NAME, "manuali")).collect(Collectors.toMap((e) -> e.getKey(), (e) -> e.getValue()))), documents);
session.createFolder(Collections.unmodifiableMap(Stream.of(new AbstractMap.SimpleEntry<>(PropertyIds.OBJECT_TYPE_ID, BaseTypeId.CMIS_FOLDER.value()), new AbstractMap.SimpleEntry<>(PropertyIds.NAME, "graduatorie")).collect(Collectors.toMap((e) -> e.getKey(), (e) -> e.getValue()))), documents);
/**
* Creo anche i gruppi necessari al funzionamento
*/
createGroup(null, JcononGroups.CONCORSI.name(), JcononGroups.CONCORSI.label());
createGroup(null, JcononGroups.COMMISSIONI_CONCORSO.name(), JcononGroups.COMMISSIONI_CONCORSO.label());
createGroup(null, JcononGroups.RDP_CONCORSO.name(), JcononGroups.RDP_CONCORSO.label());
createGroup(null, JcononGroups.APPLICATION_CONSUMER.name(), JcononGroups.APPLICATION_CONSUMER.label());
createGroup(null, JcononGroups.GESTORI_BANDI.name(), JcononGroups.GESTORI_BANDI.label(), "[\"APP.DEFAULT\", \"AUTH.EXT.gestori\"]");
for (ObjectType objectType : session.getTypeChildren(JCONONFolderType.JCONON_CALL.value(), false)) {
createGroup("GROUP_GESTORI_BANDI", "GESTORI_" + objectType.getId().replace(":", "_").toUpperCase(), "GESTORI " + objectType.getDisplayName(), "[\"APP.DEFAULT\", \"AUTH.EXT.gestori\"]", "{\"jconon_group_gestori:call_type\": \"" + objectType.getId() + "\"}");
}
Map<String, ACLType> aces = new HashMap<String, ACLType>();
aces.put(GroupsEnum.CONCORSI.value(), ACLType.Contributor);
aces.put("GROUP_GESTORI_BANDI", ACLType.Contributor);
aclService.addAcl(cmisService.getAdminSession(), competition.getProperty(CoolPropertyIds.ALFCMIS_NODEREF.value()).getValueAsString(), aces);
try {
CMISUser user = new CMISUser();
user.setFirstName(guestUserName);
user.setLastName(guestUserName);
user.setUserName(guestUserName);
user.setPassword(guestPassword);
user.setEmail("anonymus@anonymus.it");
userService.createUser(user);
userService.enableAccount(user.getUserName());
} catch (CoolUserFactoryException _ex) {
LOGGER.error("Cannot create guest user in repository", _ex);
}
} else {
for (QueryResult queryResult : results) {
ObjectId objectId = session.createObjectId((String) queryResult.getPropertyById(PropertyIds.OBJECT_ID).getFirstValue());
competition = (Folder) session.getObject(objectId);
}
}
return new CmisObjectCache().id(competition.getId()).path(competition.getPath());
}
use of it.cnr.si.opencmis.criteria.Criteria in project cool-jconon by consiglionazionaledellericerche.
the class PrintService method getAllegati.
private List<PrintDetailBulk> getAllegati(Folder application, JCONONPolicyType allegati, Session cmisSession, ApplicationModel applicationModel, boolean printDetail, boolean allAllegati) {
List<PrintDetailBulk> result = new ArrayList<PrintDetailBulk>();
Criteria criteria = CriteriaFactory.createCriteria(allegati.queryName());
criteria.addColumn(PropertyIds.OBJECT_ID);
criteria.add(Restrictions.inFolder(application.getId()));
ItemIterable<QueryResult> queryResults = criteria.executeQuery(cmisSession, false, cmisSession.getDefaultContext());
if (queryResults.getTotalNumItems() > 0) {
for (QueryResult queryResult : queryResults.getPage(Integer.MAX_VALUE)) {
Document riga = (Document) cmisSession.getObject((String) queryResult.getPropertyById(PropertyIds.OBJECT_ID).getFirstValue());
if (Optional.ofNullable(riga).map(document -> document.<List<String>>getPropertyValue(PropertyIds.SECONDARY_OBJECT_TYPE_IDS)).filter(listProperty -> listProperty.contains(JCONONPolicyType.JCONON_ATTACHMENT_FROM_RDP.value())).isPresent())
continue;
if (!allAllegati && Optional.ofNullable(riga).map(Document::getDocumentType).map(DocumentType::getId).filter(type -> Arrays.asList(JCONONDocumentType.JCONON_ATTACHMENT_DOCUMENTO_RICONOSCIMENTO.value(), JCONONDocumentType.JCONON_ATTACHMENT_DIC_SOST.value()).contains(type)).isPresent())
continue;
String link = applicationModel.getContextURL() + "/search/content?nodeRef=" + riga.getId() + "&fileName=" + riga.getContentStreamFileName() + // FIX EXCEL CHARACTER
"&dummy=dummy";
String type = applicationModel.getMessage(riga.getType().getId());
if (type.equals(riga.getType().getId()))
type = riga.getType().getDisplayName();
List<Pair<String, String>> detail;
Pair<String, String> pairName = new Pair<String, String>(riga.getProperty(PropertyIds.NAME).getDisplayName(), riga.getProperty(PropertyIds.NAME).getValueAsString());
if (printDetail) {
detail = getFields(riga, applicationModel);
if (!detail.contains(pairName))
detail.add(pairName);
result.add(new PrintDetailBulk(null, type, link, detail, null));
} else {
result.add(new PrintDetailBulk(null, type, link, riga.getProperty(PropertyIds.NAME).getValueAsString(), null));
}
}
}
return result;
}
Aggregations