Search in sources :

Example 6 with ACLType

use of it.cnr.cool.cmis.model.ACLType 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;
}
Also used : Order(it.cnr.si.opencmis.criteria.Order) ByteArrayDataSource(javax.mail.util.ByteArrayDataSource) InlineResponse201(it.cnr.si.cool.jconon.io.model.InlineResponse201) ApplicationService(it.cnr.si.cool.jconon.service.application.ApplicationService) Autowired(org.springframework.beans.factory.annotation.Autowired) CallRepository(it.cnr.si.cool.jconon.repository.CallRepository) StringUtils(org.apache.commons.lang3.StringUtils) BigDecimal(java.math.BigDecimal) CriteriaFactory(it.cnr.si.opencmis.criteria.CriteriaFactory) OperationContextUtils(org.apache.chemistry.opencmis.client.util.OperationContextUtils) HSSFSheet(org.apache.poi.hssf.usermodel.HSSFSheet) CoolPropertyIds(it.cnr.cool.cmis.model.CoolPropertyIds) ObjectIdImpl(org.apache.chemistry.opencmis.client.runtime.ObjectIdImpl) BigInteger(java.math.BigInteger) HttpStatus(org.apache.commons.httpclient.HttpStatus) PrintParameterModel(it.cnr.si.cool.jconon.model.PrintParameterModel) PropertyDefinition(org.apache.chemistry.opencmis.commons.definitions.PropertyDefinition) CompetitionFolderService(it.cnr.si.cool.jconon.service.cache.CompetitionFolderService) JCONONPolicyType(it.cnr.si.cool.jconon.cmis.model.JCONONPolicyType) org.apache.chemistry.opencmis.commons.enums(org.apache.chemistry.opencmis.commons.enums) ZoneId(java.time.ZoneId) CMISUser(it.cnr.cool.security.service.impl.alfresco.CMISUser) MailService(it.cnr.cool.mail.MailService) Stream(java.util.stream.Stream) MessageContent2(it.cnr.si.cool.jconon.io.model.MessageContent2) HSSFWorkbook(org.apache.poi.hssf.usermodel.HSSFWorkbook) VerificaPECTask(it.cnr.si.cool.jconon.dto.VerificaPECTask) it.cnr.si.cool.jconon.util(it.cnr.si.cool.jconon.util) java.util(java.util) MimeTypes(it.cnr.cool.util.MimeTypes) CmisRuntimeException(org.apache.chemistry.opencmis.commons.exceptions.CmisRuntimeException) LocalDateTime(java.time.LocalDateTime) SimpleDateFormat(java.text.SimpleDateFormat) JsonParser(com.google.gson.JsonParser) NumberFormat(java.text.NumberFormat) InternetAddress(javax.mail.internet.InternetAddress) HttpServletRequest(javax.servlet.http.HttpServletRequest) GroupsEnum(it.cnr.cool.security.GroupsEnum) Service(org.springframework.stereotype.Service) StreamSupport(java.util.stream.StreamSupport) Restrictions(it.cnr.si.opencmis.criteria.restrictions.Restrictions) UrlBuilder(org.apache.chemistry.opencmis.commons.impl.UrlBuilder) org.apache.chemistry.opencmis.client.api(org.apache.chemistry.opencmis.client.api) JSONTokener(org.json.JSONTokener) PropertyData(org.apache.chemistry.opencmis.commons.data.PropertyData) JCONONFolderType(it.cnr.si.cool.jconon.cmis.model.JCONONFolderType) StrServ(it.cnr.cool.util.StrServ) HelpdeskService(it.cnr.si.cool.jconon.service.helpdesk.HelpdeskService) ProtocolRepository(it.cnr.si.cool.jconon.repository.ProtocolRepository) UserService(it.cnr.cool.security.service.UserService) Message(javax.mail.Message) JsonObject(com.google.gson.JsonObject) PermissionServiceImpl(it.cnr.cool.web.PermissionServiceImpl) URLName(javax.mail.URLName) LoggerFactory(org.slf4j.LoggerFactory) MultipartHttpServletRequest(org.springframework.web.multipart.MultipartHttpServletRequest) CmisObjectNotFoundException(org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException) MessagingException(javax.mail.MessagingException) JSONObject(org.json.JSONObject) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Cell(org.apache.poi.ss.usermodel.Cell) ParseException(java.text.ParseException) Store(javax.mail.Store) CmisBindingsHelper(org.apache.chemistry.opencmis.client.bindings.impl.CmisBindingsHelper) Response(org.apache.chemistry.opencmis.client.bindings.spi.http.Response) AddressException(javax.mail.internet.AddressException) NewMessage(it.cnr.si.cool.jconon.io.model.NewMessage) QueueService(it.cnr.si.cool.jconon.service.QueueService) StringUtil(it.cnr.cool.util.StringUtil) SubjectTerm(javax.mail.search.SubjectTerm) ACLType(it.cnr.cool.cmis.model.ACLType) Collectors(java.util.stream.Collectors) Environment(org.springframework.core.env.Environment) PropertyIds(org.apache.chemistry.opencmis.commons.PropertyIds) LocalDate(java.time.LocalDate) EmailException(org.apache.commons.mail.EmailException) CoolUserFactoryException(it.cnr.cool.exception.CoolUserFactoryException) JCONONPropertyIds(it.cnr.si.cool.jconon.cmis.model.JCONONPropertyIds) Async(org.springframework.scheduling.annotation.Async) PECConfiguration(it.cnr.si.cool.jconon.configuration.PECConfiguration) ContentStreamImpl(org.apache.chemistry.opencmis.commons.impl.dataobjects.ContentStreamImpl) CommonsMultipartResolver(org.springframework.web.multipart.commons.CommonsMultipartResolver) IO(it.cnr.si.cool.jconon.io.repository.IO) PrintService(it.cnr.si.cool.jconon.service.PrintService) Inject(javax.inject.Inject) SearchTerm(javax.mail.search.SearchTerm) it.cnr.cool.cmis.service(it.cnr.cool.cmis.service) EmailAttachment(org.apache.commons.mail.EmailAttachment) Criteria(it.cnr.si.opencmis.criteria.Criteria) Util(it.cnr.cool.rest.util.Util) JCONONDocumentType(it.cnr.si.cool.jconon.cmis.model.JCONONDocumentType) TypeService(it.cnr.si.cool.jconon.service.TypeService) CacheRepository(it.cnr.si.cool.jconon.repository.CacheRepository) Logger(org.slf4j.Logger) BindingSession(org.apache.chemistry.opencmis.client.bindings.spi.BindingSession) ClientMessageException(it.cnr.cool.web.scripts.exception.ClientMessageException) Output(org.apache.chemistry.opencmis.client.bindings.spi.http.Output) StrSubstitutor(org.apache.commons.text.StrSubstitutor) ApplicationContext(org.springframework.context.ApplicationContext) EmailMessage(it.cnr.cool.mail.model.EmailMessage) java.io(java.io) DateTimeFormatter(java.time.format.DateTimeFormatter) Row(org.apache.poi.ss.usermodel.Row) MultipartFile(org.springframework.web.multipart.MultipartFile) CMISGroup(it.cnr.cool.security.service.impl.alfresco.CMISGroup) CMISUtil(it.cnr.cool.util.CMISUtil) I18nService(it.cnr.cool.service.I18nService) ContentStreamImpl(org.apache.chemistry.opencmis.commons.impl.dataobjects.ContentStreamImpl) ACLType(it.cnr.cool.cmis.model.ACLType) Criteria(it.cnr.si.opencmis.criteria.Criteria) BigInteger(java.math.BigInteger) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) StrSubstitutor(org.apache.commons.text.StrSubstitutor) ClientMessageException(it.cnr.cool.web.scripts.exception.ClientMessageException) JsonObject(com.google.gson.JsonObject) JSONObject(org.json.JSONObject)

Example 7 with ACLType

use of it.cnr.cool.cmis.model.ACLType 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());
}
Also used : ObjectTypeCache(it.cnr.si.cool.jconon.repository.dto.ObjectTypeCache) Cacheable(org.springframework.cache.annotation.Cacheable) LoggerFactory(org.slf4j.LoggerFactory) CmisObjectNotFoundException(org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException) Autowired(org.springframework.beans.factory.annotation.Autowired) CacheEvict(org.springframework.cache.annotation.CacheEvict) BulkInfoCool(it.cnr.bulkinfo.cool.BulkInfoCool) JcononGroups(it.cnr.si.cool.jconon.util.JcononGroups) CriteriaFactory(it.cnr.si.opencmis.criteria.CriteriaFactory) CoolPropertyIds(it.cnr.cool.cmis.model.CoolPropertyIds) Repository(org.springframework.stereotype.Repository) PropertyDefinition(org.apache.chemistry.opencmis.commons.definitions.PropertyDefinition) CmisBindingsHelper(org.apache.chemistry.opencmis.client.bindings.impl.CmisBindingsHelper) Response(org.apache.chemistry.opencmis.client.bindings.spi.http.Response) ACLService(it.cnr.cool.cmis.service.ACLService) JCONONPolicyType(it.cnr.si.cool.jconon.cmis.model.JCONONPolicyType) ACLType(it.cnr.cool.cmis.model.ACLType) Collectors(java.util.stream.Collectors) CMISUser(it.cnr.cool.security.service.impl.alfresco.CMISUser) IOUtils(org.apache.commons.io.IOUtils) Stream(java.util.stream.Stream) PropertyIds(org.apache.chemistry.opencmis.commons.PropertyIds) CoolUserFactoryException(it.cnr.cool.exception.CoolUserFactoryException) CMISService(it.cnr.cool.cmis.service.CMISService) JasperCompileManager(net.sf.jasperreports.engine.JasperCompileManager) JasperReport(net.sf.jasperreports.engine.JasperReport) java.util(java.util) MimeTypes(it.cnr.cool.util.MimeTypes) ByteArrayOutputStream(java.io.ByteArrayOutputStream) JRException(net.sf.jasperreports.engine.JRException) ClassPathResource(org.springframework.core.io.ClassPathResource) BaseTypeId(org.apache.chemistry.opencmis.commons.enums.BaseTypeId) CmisObjectCache(it.cnr.si.cool.jconon.repository.dto.CmisObjectCache) Value(org.springframework.beans.factory.annotation.Value) GroupsEnum(it.cnr.cool.security.GroupsEnum) Charset(java.nio.charset.Charset) Criteria(it.cnr.si.opencmis.criteria.Criteria) CacheManager(org.springframework.cache.CacheManager) SiperService(it.cnr.si.cool.jconon.service.SiperService) UrlBuilder(org.apache.chemistry.opencmis.commons.impl.UrlBuilder) JCONONDocumentType(it.cnr.si.cool.jconon.cmis.model.JCONONDocumentType) TypeService(it.cnr.si.cool.jconon.service.TypeService) org.apache.chemistry.opencmis.client.api(org.apache.chemistry.opencmis.client.api) OutputStream(java.io.OutputStream) Logger(org.slf4j.Logger) BulkInfoRepository(it.cnr.cool.BulkInfoRepository) Output(org.apache.chemistry.opencmis.client.bindings.spi.http.Output) JCONONFolderType(it.cnr.si.cool.jconon.cmis.model.JCONONFolderType) BulkInfoCoolService(it.cnr.cool.service.BulkInfoCoolService) UserService(it.cnr.cool.security.service.UserService) I18nService(it.cnr.cool.service.I18nService) InputStream(java.io.InputStream) ACLType(it.cnr.cool.cmis.model.ACLType) CMISUser(it.cnr.cool.security.service.impl.alfresco.CMISUser) Criteria(it.cnr.si.opencmis.criteria.Criteria) CmisObjectCache(it.cnr.si.cool.jconon.repository.dto.CmisObjectCache) CoolUserFactoryException(it.cnr.cool.exception.CoolUserFactoryException) Cacheable(org.springframework.cache.annotation.Cacheable)

Example 8 with ACLType

use of it.cnr.cool.cmis.model.ACLType in project cool-jconon by consiglionazionaledellericerche.

the class PrintService method printSchedaValutazione.

public String printSchedaValutazione(Session cmisSession, String nodeRef, String contextURL, String userId, Locale locale) throws IOException {
    Folder application = (Folder) cmisSession.getObject(nodeRef);
    Folder call = (Folder) cmisSession.getObject(application.getParentId());
    application.refresh();
    InputStream is = new ByteArrayInputStream(getSchedaValutazione(cmisSession, application, contextURL, locale));
    String nameRicevutaReportModel = getSchedaValutazioneName(cmisSession, application);
    ContentStream contentStream = new ContentStreamImpl(nameRicevutaReportModel, BigInteger.valueOf(is.available()), "application/vnd.ms-excel", is);
    Map<String, Object> properties = new HashMap<String, Object>();
    properties.put(PropertyIds.OBJECT_TYPE_ID, JCONONDocumentType.JCONON_ATTACHMENT_SCHEDA_VALUTAZIONE.value());
    properties.put(PropertyIds.NAME, nameRicevutaReportModel);
    properties.put(JCONONPropertyIds.ATTACHMENT_USER.value(), userId);
    properties.put(JCONONPropertyIds.ATTACHMENT_SCHEDA_VALUTAZIONE_COMMENTO.value(), "Scheda vuota");
    Document doc = application.createDocument(properties, contentStream, VersioningState.MAJOR);
    Map<String, ACLType> aces = new HashMap<String, ACLType>();
    aces.put(GroupsEnum.CONCORSI.value(), ACLType.Coordinator);
    aces.put("GROUP_" + call.getPropertyValue(JCONONPropertyIds.CALL_RDP.value()), ACLType.Consumer);
    aces.put("GROUP_" + call.getPropertyValue(JCONONPropertyIds.CALL_COMMISSIONE.value()), ACLType.Coordinator);
    Folder macroCall = competitionService.getMacroCall(cmisService.createAdminSession(), call);
    if (macroCall != null) {
        String groupNameMacroCall = competitionService.getCallGroupCommissioneName(macroCall);
        aces.put("GROUP_" + groupNameMacroCall, ACLType.Coordinator);
    }
    aclService.addAcl(cmisService.getAdminSession(), doc.getProperty(CoolPropertyIds.ALFCMIS_NODEREF.value()).getValueAsString(), aces);
    aclService.setInheritedPermission(cmisService.getAdminSession(), doc.getProperty(CoolPropertyIds.ALFCMIS_NODEREF.value()).getValueAsString(), false);
    nodeVersionService.addAutoVersion(doc, false);
    return doc.getId();
}
Also used : ContentStreamImpl(org.apache.chemistry.opencmis.commons.impl.dataobjects.ContentStreamImpl) ContentStream(org.apache.chemistry.opencmis.commons.data.ContentStream) PDPageContentStream(org.apache.pdfbox.pdmodel.PDPageContentStream) ACLType(it.cnr.cool.cmis.model.ACLType) PDImageXObject(org.apache.pdfbox.pdmodel.graphics.image.PDImageXObject) JSONObject(org.json.JSONObject) PDDocument(org.apache.pdfbox.pdmodel.PDDocument)

Example 9 with ACLType

use of it.cnr.cool.cmis.model.ACLType in project cool-jconon by consiglionazionaledellericerche.

the class PrintService method printSchedaAnonimaDiValutazione.

public String printSchedaAnonimaDiValutazione(Session cmisSession, String nodeRef, String contextURL, String userId, Locale locale, int index) throws IOException {
    Folder application = (Folder) cmisSession.getObject(nodeRef);
    Folder call = (Folder) cmisSession.getObject(application.getParentId());
    application.refresh();
    InputStream is = new ByteArrayInputStream(getSchedaAnonimaSintetica(cmisSession, application, contextURL, locale, index));
    String nameRicevutaReportModel = getSchedaAnonimaSinteticaName(cmisSession, application, index);
    ContentStream contentStream = new ContentStreamImpl(nameRicevutaReportModel, BigInteger.valueOf(is.available()), "application/pdf", is);
    Map<String, Object> properties = new HashMap<String, Object>();
    properties.put(PropertyIds.OBJECT_TYPE_ID, JCONONDocumentType.JCONON_ATTACHMENT_SCHEDA_ANONIMA_SINTETICA_GENERATED.value());
    properties.put(PropertyIds.NAME, nameRicevutaReportModel);
    properties.put(JCONONPropertyIds.ATTACHMENT_USER.value(), userId);
    properties.put(PropertyIds.SECONDARY_OBJECT_TYPE_IDS, Arrays.asList("P:jconon_scheda_anonima:valutazione"));
    String schedaAnonima = competitionService.findAttachmentId(cmisSession, nodeRef, JCONONDocumentType.JCONON_ATTACHMENT_SCHEDA_ANONIMA_SINTETICA_GENERATED);
    if (schedaAnonima != null)
        cmisSession.delete(cmisSession.createObjectId(schedaAnonima));
    Document doc = application.createDocument(properties, contentStream, VersioningState.MAJOR);
    Map<String, ACLType> aces = new HashMap<String, ACLType>();
    aces.put(JcononGroups.CONCORSI.group(), ACLType.Coordinator);
    aces.put("GROUP_" + call.getPropertyValue(JCONONPropertyIds.CALL_COMMISSIONE.value()), ACLType.Editor);
    aces.put("GROUP_" + call.getPropertyValue(JCONONPropertyIds.CALL_RDP.value()), ACLType.Editor);
    Folder macroCall = competitionService.getMacroCall(cmisService.createAdminSession(), call);
    if (macroCall != null) {
        String groupNameMacroCall = competitionService.getCallGroupCommissioneName(macroCall);
        aces.put("GROUP_" + groupNameMacroCall, ACLType.Editor);
    }
    aclService.addAcl(cmisService.getAdminSession(), doc.getProperty(CoolPropertyIds.ALFCMIS_NODEREF.value()).getValueAsString(), aces);
    aclService.setInheritedPermission(cmisService.getAdminSession(), doc.getProperty(CoolPropertyIds.ALFCMIS_NODEREF.value()).getValueAsString(), false);
    nodeVersionService.addAutoVersion(doc, false);
    return doc.getId();
}
Also used : ContentStreamImpl(org.apache.chemistry.opencmis.commons.impl.dataobjects.ContentStreamImpl) ContentStream(org.apache.chemistry.opencmis.commons.data.ContentStream) PDPageContentStream(org.apache.pdfbox.pdmodel.PDPageContentStream) ACLType(it.cnr.cool.cmis.model.ACLType) PDImageXObject(org.apache.pdfbox.pdmodel.graphics.image.PDImageXObject) JSONObject(org.json.JSONObject) PDDocument(org.apache.pdfbox.pdmodel.PDDocument)

Example 10 with ACLType

use of it.cnr.cool.cmis.model.ACLType in project cool-jconon by consiglionazionaledellericerche.

the class CallService method convocazioni.

protected Long convocazioni(Session session, MultipartHttpServletRequest mRequest, BindingSession bindingSession, String contextURL, Locale locale, String userId) throws IOException {
    String callId = mRequest.getParameter("callId");
    String tipoSelezione = mRequest.getParameter("tipoSelezione");
    Boolean testoLibero = Boolean.valueOf(mRequest.getParameter("testoLibero"));
    String luogo = mRequest.getParameter("luogo");
    Calendar data = Optional.ofNullable(mRequest.getParameter("data")).filter(s -> s.length() > 0).map(s -> {
        try {
            return DateUtils.parse(s);
        } catch (ParseException e) {
            return null;
        }
    }).orElse(null);
    String note = mRequest.getParameter("note");
    String firma = mRequest.getParameter("firma");
    List<String> applicationsId = Arrays.asList(Optional.ofNullable(mRequest.getParameterValues("application")).orElse(new String[0]));
    Integer numeroConvocazione = Optional.ofNullable(mRequest.getParameter("numeroConvocazione")).map(map -> Integer.valueOf(map)).orElse(1);
    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 index = 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());
        StrSubstitutor sub = formatPlaceHolder(applicationObject, applicationObject.getFolderParent());
        byte[] bytes = printService.printConvocazione(session, applicationObject, contextURL, locale, Optional.ofNullable(tipoSelezione).map(s -> call.<String>getPropertyValue(s)).map(s -> maleFemale(s, " il ", " la ") + s + maleFemale(s, " previsto ", " prevista ")).orElse(null), luogo, data, testoLibero, sub.replace(note), firma);
        String name = "CONV_" + applicationObject.getPropertyValue(JCONONPropertyIds.APPLICATION_COGNOME.value()) + " " + applicationObject.getPropertyValue(JCONONPropertyIds.APPLICATION_NOME.value()) + "_" + applicationObject.getPropertyValue(JCONONPropertyIds.APPLICATION_USER.value()) + "_" + StrServ.lpad(String.valueOf(numeroConvocazione), 4) + ".pdf";
        Map<String, Object> properties = new HashMap<String, Object>();
        properties.put(PropertyIds.OBJECT_TYPE_ID, JCONONDocumentType.JCONON_ATTACHMENT_CONVOVCAZIONE.value());
        properties.put(PropertyIds.NAME, name);
        properties.put(JCONONPropertyIds.ATTACHMENT_USER.value(), applicationObject.getPropertyValue(JCONONPropertyIds.APPLICATION_USER.value()));
        properties.put("jconon_convocazione:numero", numeroConvocazione);
        properties.put("jconon_convocazione:stato", StatoComunicazione.GENERATO.name());
        properties.put("jconon_convocazione:data", data);
        properties.put("jconon_convocazione:luogo", luogo);
        properties.put("jconon_convocazione:tipoSelezione", Optional.ofNullable(tipoSelezione).map(s -> call.<String>getPropertyValue(s)).orElse(null));
        properties.put("jconon_convocazione:email", applicationObject.getPropertyValue(JCONONPropertyIds.APPLICATION_EMAIL_COMUNICAZIONI.value()));
        properties.put("jconon_convocazione: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) {
            index++;
            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);
            if (doc.getPropertyValue("jconon_convocazione:stato").equals(StatoComunicazione.GENERATO.name())) {
                index++;
                doc.updateProperties(properties);
                doc.setContentStream(contentStream, true);
            }
        }
    }
    if (numeroConvocazione >= Optional.ofNullable(call.getPropertyValue("jconon_call:numero_convocazione")).map(map -> Integer.valueOf(map.toString())).orElse(1)) {
        Map<String, Object> callProperties = new HashMap<String, Object>();
        callProperties.put("jconon_call:numero_convocazione", numeroConvocazione);
        call.updateProperties(callProperties);
    }
    return index;
}
Also used : Order(it.cnr.si.opencmis.criteria.Order) ByteArrayDataSource(javax.mail.util.ByteArrayDataSource) InlineResponse201(it.cnr.si.cool.jconon.io.model.InlineResponse201) ApplicationService(it.cnr.si.cool.jconon.service.application.ApplicationService) Autowired(org.springframework.beans.factory.annotation.Autowired) CallRepository(it.cnr.si.cool.jconon.repository.CallRepository) StringUtils(org.apache.commons.lang3.StringUtils) BigDecimal(java.math.BigDecimal) CriteriaFactory(it.cnr.si.opencmis.criteria.CriteriaFactory) OperationContextUtils(org.apache.chemistry.opencmis.client.util.OperationContextUtils) HSSFSheet(org.apache.poi.hssf.usermodel.HSSFSheet) CoolPropertyIds(it.cnr.cool.cmis.model.CoolPropertyIds) ObjectIdImpl(org.apache.chemistry.opencmis.client.runtime.ObjectIdImpl) BigInteger(java.math.BigInteger) HttpStatus(org.apache.commons.httpclient.HttpStatus) PrintParameterModel(it.cnr.si.cool.jconon.model.PrintParameterModel) PropertyDefinition(org.apache.chemistry.opencmis.commons.definitions.PropertyDefinition) CompetitionFolderService(it.cnr.si.cool.jconon.service.cache.CompetitionFolderService) JCONONPolicyType(it.cnr.si.cool.jconon.cmis.model.JCONONPolicyType) org.apache.chemistry.opencmis.commons.enums(org.apache.chemistry.opencmis.commons.enums) ZoneId(java.time.ZoneId) CMISUser(it.cnr.cool.security.service.impl.alfresco.CMISUser) MailService(it.cnr.cool.mail.MailService) Stream(java.util.stream.Stream) MessageContent2(it.cnr.si.cool.jconon.io.model.MessageContent2) HSSFWorkbook(org.apache.poi.hssf.usermodel.HSSFWorkbook) VerificaPECTask(it.cnr.si.cool.jconon.dto.VerificaPECTask) it.cnr.si.cool.jconon.util(it.cnr.si.cool.jconon.util) java.util(java.util) MimeTypes(it.cnr.cool.util.MimeTypes) CmisRuntimeException(org.apache.chemistry.opencmis.commons.exceptions.CmisRuntimeException) LocalDateTime(java.time.LocalDateTime) SimpleDateFormat(java.text.SimpleDateFormat) JsonParser(com.google.gson.JsonParser) NumberFormat(java.text.NumberFormat) InternetAddress(javax.mail.internet.InternetAddress) HttpServletRequest(javax.servlet.http.HttpServletRequest) GroupsEnum(it.cnr.cool.security.GroupsEnum) Service(org.springframework.stereotype.Service) StreamSupport(java.util.stream.StreamSupport) Restrictions(it.cnr.si.opencmis.criteria.restrictions.Restrictions) UrlBuilder(org.apache.chemistry.opencmis.commons.impl.UrlBuilder) org.apache.chemistry.opencmis.client.api(org.apache.chemistry.opencmis.client.api) JSONTokener(org.json.JSONTokener) PropertyData(org.apache.chemistry.opencmis.commons.data.PropertyData) JCONONFolderType(it.cnr.si.cool.jconon.cmis.model.JCONONFolderType) StrServ(it.cnr.cool.util.StrServ) HelpdeskService(it.cnr.si.cool.jconon.service.helpdesk.HelpdeskService) ProtocolRepository(it.cnr.si.cool.jconon.repository.ProtocolRepository) UserService(it.cnr.cool.security.service.UserService) Message(javax.mail.Message) JsonObject(com.google.gson.JsonObject) PermissionServiceImpl(it.cnr.cool.web.PermissionServiceImpl) URLName(javax.mail.URLName) LoggerFactory(org.slf4j.LoggerFactory) MultipartHttpServletRequest(org.springframework.web.multipart.MultipartHttpServletRequest) CmisObjectNotFoundException(org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException) MessagingException(javax.mail.MessagingException) JSONObject(org.json.JSONObject) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Cell(org.apache.poi.ss.usermodel.Cell) ParseException(java.text.ParseException) Store(javax.mail.Store) CmisBindingsHelper(org.apache.chemistry.opencmis.client.bindings.impl.CmisBindingsHelper) Response(org.apache.chemistry.opencmis.client.bindings.spi.http.Response) AddressException(javax.mail.internet.AddressException) NewMessage(it.cnr.si.cool.jconon.io.model.NewMessage) QueueService(it.cnr.si.cool.jconon.service.QueueService) StringUtil(it.cnr.cool.util.StringUtil) SubjectTerm(javax.mail.search.SubjectTerm) ACLType(it.cnr.cool.cmis.model.ACLType) Collectors(java.util.stream.Collectors) Environment(org.springframework.core.env.Environment) PropertyIds(org.apache.chemistry.opencmis.commons.PropertyIds) LocalDate(java.time.LocalDate) EmailException(org.apache.commons.mail.EmailException) CoolUserFactoryException(it.cnr.cool.exception.CoolUserFactoryException) JCONONPropertyIds(it.cnr.si.cool.jconon.cmis.model.JCONONPropertyIds) Async(org.springframework.scheduling.annotation.Async) PECConfiguration(it.cnr.si.cool.jconon.configuration.PECConfiguration) ContentStreamImpl(org.apache.chemistry.opencmis.commons.impl.dataobjects.ContentStreamImpl) CommonsMultipartResolver(org.springframework.web.multipart.commons.CommonsMultipartResolver) IO(it.cnr.si.cool.jconon.io.repository.IO) PrintService(it.cnr.si.cool.jconon.service.PrintService) Inject(javax.inject.Inject) SearchTerm(javax.mail.search.SearchTerm) it.cnr.cool.cmis.service(it.cnr.cool.cmis.service) EmailAttachment(org.apache.commons.mail.EmailAttachment) Criteria(it.cnr.si.opencmis.criteria.Criteria) Util(it.cnr.cool.rest.util.Util) JCONONDocumentType(it.cnr.si.cool.jconon.cmis.model.JCONONDocumentType) TypeService(it.cnr.si.cool.jconon.service.TypeService) CacheRepository(it.cnr.si.cool.jconon.repository.CacheRepository) Logger(org.slf4j.Logger) BindingSession(org.apache.chemistry.opencmis.client.bindings.spi.BindingSession) ClientMessageException(it.cnr.cool.web.scripts.exception.ClientMessageException) Output(org.apache.chemistry.opencmis.client.bindings.spi.http.Output) StrSubstitutor(org.apache.commons.text.StrSubstitutor) ApplicationContext(org.springframework.context.ApplicationContext) EmailMessage(it.cnr.cool.mail.model.EmailMessage) java.io(java.io) DateTimeFormatter(java.time.format.DateTimeFormatter) Row(org.apache.poi.ss.usermodel.Row) MultipartFile(org.springframework.web.multipart.MultipartFile) CMISGroup(it.cnr.cool.security.service.impl.alfresco.CMISGroup) CMISUtil(it.cnr.cool.util.CMISUtil) I18nService(it.cnr.cool.service.I18nService) ContentStreamImpl(org.apache.chemistry.opencmis.commons.impl.dataobjects.ContentStreamImpl) ACLType(it.cnr.cool.cmis.model.ACLType) Criteria(it.cnr.si.opencmis.criteria.Criteria) BigInteger(java.math.BigInteger) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) StrSubstitutor(org.apache.commons.text.StrSubstitutor) ClientMessageException(it.cnr.cool.web.scripts.exception.ClientMessageException) JsonObject(com.google.gson.JsonObject) JSONObject(org.json.JSONObject) ParseException(java.text.ParseException)

Aggregations

ACLType (it.cnr.cool.cmis.model.ACLType)13 JSONObject (org.json.JSONObject)12 JsonObject (com.google.gson.JsonObject)10 ClientMessageException (it.cnr.cool.web.scripts.exception.ClientMessageException)10 CoolUserFactoryException (it.cnr.cool.exception.CoolUserFactoryException)7 CMISUser (it.cnr.cool.security.service.impl.alfresco.CMISUser)7 Output (org.apache.chemistry.opencmis.client.bindings.spi.http.Output)7 Response (org.apache.chemistry.opencmis.client.bindings.spi.http.Response)7 CmisObjectNotFoundException (org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException)7 UrlBuilder (org.apache.chemistry.opencmis.commons.impl.UrlBuilder)7 ContentStreamImpl (org.apache.chemistry.opencmis.commons.impl.dataobjects.ContentStreamImpl)7 Criteria (it.cnr.si.opencmis.criteria.Criteria)6 ParseException (java.text.ParseException)6 MessagingException (javax.mail.MessagingException)6 AddressException (javax.mail.internet.AddressException)6 CmisRuntimeException (org.apache.chemistry.opencmis.commons.exceptions.CmisRuntimeException)6 EmailException (org.apache.commons.mail.EmailException)6 CoolPropertyIds (it.cnr.cool.cmis.model.CoolPropertyIds)5 GroupsEnum (it.cnr.cool.security.GroupsEnum)5 UserService (it.cnr.cool.security.service.UserService)5