Search in sources :

Example 1 with ACLType

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;
}
Also used : ContentStreamImpl(org.apache.chemistry.opencmis.commons.impl.dataobjects.ContentStreamImpl) ACLType(it.cnr.cool.cmis.model.ACLType) LocalDate(java.time.LocalDate) MultipartFile(org.springframework.web.multipart.MultipartFile) ClientMessageException(it.cnr.cool.web.scripts.exception.ClientMessageException) JsonObject(com.google.gson.JsonObject) JSONObject(org.json.JSONObject) MultipartHttpServletRequest(org.springframework.web.multipart.MultipartHttpServletRequest)

Example 2 with ACLType

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;
}
Also used : ACLType(it.cnr.cool.cmis.model.ACLType) CMISUser(it.cnr.cool.security.service.impl.alfresco.CMISUser) ClientMessageException(it.cnr.cool.web.scripts.exception.ClientMessageException) JsonObject(com.google.gson.JsonObject) JSONObject(org.json.JSONObject) ObjectIdImpl(org.apache.chemistry.opencmis.client.runtime.ObjectIdImpl)

Example 3 with ACLType

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;
}
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) InternetAddress(javax.mail.internet.InternetAddress) MessageContent2(it.cnr.si.cool.jconon.io.model.MessageContent2) NewMessage(it.cnr.si.cool.jconon.io.model.NewMessage) InlineResponse201(it.cnr.si.cool.jconon.io.model.InlineResponse201) AddressException(javax.mail.internet.AddressException) EmailException(org.apache.commons.mail.EmailException) ByteArrayDataSource(javax.mail.util.ByteArrayDataSource) ACLType(it.cnr.cool.cmis.model.ACLType) CmisRuntimeException(org.apache.chemistry.opencmis.commons.exceptions.CmisRuntimeException) CmisObjectNotFoundException(org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException) MessagingException(javax.mail.MessagingException) ParseException(java.text.ParseException) AddressException(javax.mail.internet.AddressException) EmailException(org.apache.commons.mail.EmailException) CoolUserFactoryException(it.cnr.cool.exception.CoolUserFactoryException) ClientMessageException(it.cnr.cool.web.scripts.exception.ClientMessageException) JsonObject(com.google.gson.JsonObject) JSONObject(org.json.JSONObject)

Example 4 with ACLType

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);
    }
}
Also used : ACLType(it.cnr.cool.cmis.model.ACLType) CmisRuntimeException(org.apache.chemistry.opencmis.commons.exceptions.CmisRuntimeException) CmisObjectNotFoundException(org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException) MessagingException(javax.mail.MessagingException) ParseException(java.text.ParseException) AddressException(javax.mail.internet.AddressException) EmailException(org.apache.commons.mail.EmailException) CoolUserFactoryException(it.cnr.cool.exception.CoolUserFactoryException) ClientMessageException(it.cnr.cool.web.scripts.exception.ClientMessageException) Response(org.apache.chemistry.opencmis.client.bindings.spi.http.Response) JSONObject(org.json.JSONObject) Output(org.apache.chemistry.opencmis.client.bindings.spi.http.Output) JsonObject(com.google.gson.JsonObject) JSONObject(org.json.JSONObject) UrlBuilder(org.apache.chemistry.opencmis.commons.impl.UrlBuilder)

Example 5 with ACLType

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;
}
Also used : ACLType(it.cnr.cool.cmis.model.ACLType) Criteria(it.cnr.si.opencmis.criteria.Criteria) ClientMessageException(it.cnr.cool.web.scripts.exception.ClientMessageException) JsonObject(com.google.gson.JsonObject) JSONObject(org.json.JSONObject) UnfileObject(org.apache.chemistry.opencmis.commons.enums.UnfileObject)

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