Search in sources :

Example 1 with UrlBuilder

use of org.apache.chemistry.opencmis.commons.impl.UrlBuilder in project cool-jconon by consiglionazionaledellericerche.

the class ApplicationService method reopenApplication.

public void reopenApplication(Session currentCMISSession, final String applicationSourceId, final String contextURL, Locale locale, String userId) {
    /**
     * Load application source with user session if user cannot access to application
     * throw an exception
     */
    try {
        OperationContext oc = new OperationContextImpl(currentCMISSession.getDefaultContext());
        oc.setFilterString(PropertyIds.OBJECT_ID);
        currentCMISSession.getObject(applicationSourceId, oc);
    } catch (CmisPermissionDeniedException _ex) {
        throw new ClientMessageException("user.cannot.access.to.application", _ex);
    }
    final Folder newApplication = loadApplicationById(currentCMISSession, applicationSourceId, null);
    final Folder call = loadCallById(currentCMISSession, newApplication.getParentId(), null);
    if (newApplication.getPropertyValue(JCONONPropertyIds.APPLICATION_DATA_DOMANDA.value()) == null || !newApplication.getPropertyValue(JCONONPropertyIds.APPLICATION_STATO_DOMANDA.value()).equals(StatoDomanda.CONFERMATA.getValue())) {
        throw new ClientMessageException("message.error.domanda.no.confermata");
    }
    try {
        callService.isBandoInCorso(call, userService.loadUserForConfirm(userId));
    } catch (CoolUserFactoryException e) {
        throw new CMISApplicationException("Error loading user: " + userId, e);
    }
    String link = cmisService.getBaseURL().concat("service/cnr/jconon/manage-application/reopen");
    UrlBuilder url = new UrlBuilder(link);
    Response resp = cmisService.getHttpInvoker(cmisService.getAdminSession()).invokePOST(url, MimeTypes.JSON.mimetype(), new Output() {

        @Override
        public void write(OutputStream out) throws Exception {
            JSONObject jsonObject = new JSONObject();
            jsonObject.put("applicationSourceId", newApplication.getProperty(CoolPropertyIds.ALFCMIS_NODEREF.value()).getValueAsString());
            jsonObject.put("groupRdP", "GROUP_" + call.getPropertyValue(JCONONPropertyIds.CALL_RDP.value()));
            jsonObject.put("groupConsumer", JcononGroups.APPLICATION_CONSUMER.group());
            out.write(jsonObject.toString().getBytes());
        }
    }, cmisService.getAdminSession());
    int status = resp.getResponseCode();
    if (status == HttpStatus.SC_NOT_FOUND || status == HttpStatus.SC_BAD_REQUEST || status == HttpStatus.SC_INTERNAL_SERVER_ERROR) {
        throw new CMISApplicationException("Reopen Application error. Exception: " + resp.getErrorContent());
    }
    addToQueueForPrint(applicationSourceId, contextURL, emailOnReopen);
}
Also used : OperationContextImpl(org.apache.chemistry.opencmis.client.runtime.OperationContextImpl) CMISApplicationException(it.cnr.cool.web.scripts.exception.CMISApplicationException) JSONException(org.json.JSONException) CMISApplicationException(it.cnr.cool.web.scripts.exception.CMISApplicationException) 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) ClientMessageException(it.cnr.cool.web.scripts.exception.ClientMessageException) Output(org.apache.chemistry.opencmis.client.bindings.spi.http.Output) UrlBuilder(org.apache.chemistry.opencmis.commons.impl.UrlBuilder) CoolUserFactoryException(it.cnr.cool.exception.CoolUserFactoryException)

Example 2 with UrlBuilder

use of org.apache.chemistry.opencmis.commons.impl.UrlBuilder in project cool-jconon by consiglionazionaledellericerche.

the class ApplicationService method paste.

public String paste(Session currentCMISSession, final String applicationSourceId, final String callTargetId, String userId) {
    /**
     * Load application source with user session if user cannot access to application
     * throw an exception
     */
    try {
        OperationContext oc = new OperationContextImpl(currentCMISSession.getDefaultContext());
        oc.setFilterString(PropertyIds.OBJECT_ID);
        currentCMISSession.getObject(applicationSourceId, oc);
    } catch (CmisPermissionDeniedException _ex) {
        throw new ClientMessageException("user.cannot.access.to.application", _ex);
    }
    final Folder application = loadApplicationById(currentCMISSession, applicationSourceId, null);
    final Folder call = loadCallById(currentCMISSession, callTargetId, null);
    try {
        callService.isBandoInCorso(call, userService.loadUserForConfirm(userId));
    } catch (CoolUserFactoryException e) {
        throw new CMISApplicationException("Error loading user: " + userId, e);
    }
    String link = cmisService.getBaseURL().concat("service/cnr/jconon/manage-application/paste");
    UrlBuilder url = new UrlBuilder(link);
    Response resp = cmisService.getHttpInvoker(cmisService.getAdminSession()).invokePOST(url, MimeTypes.JSON.mimetype(), new Output() {

        @Override
        public void write(OutputStream out) throws Exception {
            JSONObject jsonObject = new JSONObject();
            jsonObject.put("applicationSourceId", application.getProperty(CoolPropertyIds.ALFCMIS_NODEREF.value()).getValueAsString());
            jsonObject.put("callTargetId", call.getProperty(CoolPropertyIds.ALFCMIS_NODEREF.value()).getValueAsString());
            out.write(jsonObject.toString().getBytes());
        }
    }, cmisService.getAdminSession());
    int stato = resp.getResponseCode();
    if (stato == HttpStatus.SC_BAD_REQUEST || stato == HttpStatus.SC_INTERNAL_SERVER_ERROR) {
        try {
            JSONObject jsonObject = new JSONObject(resp.getErrorContent());
            throw new ClientMessageException(jsonObject.getString("message"));
        } catch (JSONException e) {
            throw new ClientMessageException("message.application.for.copy.alredy.exists", e);
        }
    }
    if (stato == HttpStatus.SC_NOT_FOUND) {
        throw new ClientMessageException("Paste Application error. Exception: " + resp.getErrorContent());
    }
    try {
        JSONObject jsonObject = new JSONObject(StringUtil.convertStreamToString(resp.getStream()));
        return jsonObject.getString("cmis:objectId");
    } catch (JSONException e) {
        throw new ClientMessageException("Paste Application error. Exception: " + resp.getErrorContent(), e);
    }
}
Also used : OperationContextImpl(org.apache.chemistry.opencmis.client.runtime.OperationContextImpl) JSONException(org.json.JSONException) CMISApplicationException(it.cnr.cool.web.scripts.exception.CMISApplicationException) JSONException(org.json.JSONException) CMISApplicationException(it.cnr.cool.web.scripts.exception.CMISApplicationException) 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) ClientMessageException(it.cnr.cool.web.scripts.exception.ClientMessageException) Output(org.apache.chemistry.opencmis.client.bindings.spi.http.Output) UrlBuilder(org.apache.chemistry.opencmis.commons.impl.UrlBuilder) CoolUserFactoryException(it.cnr.cool.exception.CoolUserFactoryException)

Example 3 with UrlBuilder

use of org.apache.chemistry.opencmis.commons.impl.UrlBuilder 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 4 with UrlBuilder

use of org.apache.chemistry.opencmis.commons.impl.UrlBuilder in project cool-jconon by consiglionazionaledellericerche.

the class PrintService method checkInPrint.

protected String checkInPrint(BindingSession cmisSession, final String applicationPrintId, final InputStream is, final String name) {
    String link = cmisService.getBaseURL().concat("service/cnr/jconon/manage-application/checkIn");
    UrlBuilder url = new UrlBuilder(link);
    url = url.addParameter("applicationPrintId", applicationPrintId);
    url = url.addParameter("name", name);
    Response resp = cmisService.getHttpInvoker(cmisSession).invokePOST(url, MimeTypes.JSON.mimetype(), new Output() {

        @Override
        public void write(OutputStream out) throws Exception {
            IOUtils.copy(is, out);
        }
    }, cmisSession);
    int status = resp.getResponseCode();
    if (status == HttpStatus.SC_NOT_FOUND || status == HttpStatus.SC_BAD_REQUEST || status == HttpStatus.SC_INTERNAL_SERVER_ERROR)
        throw new CMISApplicationException("ChechIn Application error. Exception: " + resp.getErrorContent());
    try {
        return new JSONObject(IOUtils.toString(resp.getStream())).getString("objectId");
    } catch (JSONException | IOException e) {
        throw new CMISApplicationException("ChechIn Application error.", e);
    }
}
Also used : JSONException(org.json.JSONException) CMISApplicationException(it.cnr.cool.web.scripts.exception.CMISApplicationException) JSONException(org.json.JSONException) CmisObjectNotFoundException(org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException) WriterException(com.google.zxing.WriterException) ParseException(java.text.ParseException) CMISApplicationException(it.cnr.cool.web.scripts.exception.CMISApplicationException) CoolUserFactoryException(it.cnr.cool.exception.CoolUserFactoryException) NotImplementedException(org.apache.commons.lang3.NotImplementedException) CmisStreamNotSupportedException(org.apache.chemistry.opencmis.commons.exceptions.CmisStreamNotSupportedException) ClientMessageException(it.cnr.cool.web.scripts.exception.ClientMessageException) Response(org.apache.chemistry.opencmis.client.bindings.spi.http.Response) JSONObject(org.json.JSONObject) SimpleOutputStreamExporterOutput(net.sf.jasperreports.export.SimpleOutputStreamExporterOutput) Output(org.apache.chemistry.opencmis.client.bindings.spi.http.Output) UrlBuilder(org.apache.chemistry.opencmis.commons.impl.UrlBuilder)

Example 5 with UrlBuilder

use of org.apache.chemistry.opencmis.commons.impl.UrlBuilder in project cool-jconon by consiglionazionaledellericerche.

the class CacheRepository method createGroup.

protected void createGroup(final String parent_group_name, final String group_name, final String display_name, final String zones, final String extraProperty) {
    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 = "{";
            if (parent_group_name != null) {
                groupJson = groupJson.concat("\"parent_group_name\":\"" + parent_group_name + "\",");
            }
            groupJson = groupJson.concat("\"group_name\":\"" + group_name + "\",");
            groupJson = groupJson.concat("\"display_name\":\"" + display_name + "\",");
            if (extraProperty != null)
                groupJson = groupJson.concat("\"extraProperty\":" + extraProperty + ",");
            if (zones == null)
                groupJson = groupJson.concat("\"zones\":[\"AUTH.ALF\",\"APP.DEFAULT\"]");
            else
                groupJson = groupJson.concat("\"zones\":" + zones);
            groupJson = groupJson.concat("}");
            out.write(groupJson.getBytes());
        }
    }, cmisService.getAdminSession());
    if (response.getErrorContent() != null)
        LOGGER.error(response.getErrorContent());
}
Also used : Response(org.apache.chemistry.opencmis.client.bindings.spi.http.Response) Output(org.apache.chemistry.opencmis.client.bindings.spi.http.Output) ByteArrayOutputStream(java.io.ByteArrayOutputStream) OutputStream(java.io.OutputStream) UrlBuilder(org.apache.chemistry.opencmis.commons.impl.UrlBuilder) CmisObjectNotFoundException(org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException) CoolUserFactoryException(it.cnr.cool.exception.CoolUserFactoryException) JRException(net.sf.jasperreports.engine.JRException)

Aggregations

UrlBuilder (org.apache.chemistry.opencmis.commons.impl.UrlBuilder)19 Response (org.apache.chemistry.opencmis.client.bindings.spi.http.Response)15 Output (org.apache.chemistry.opencmis.client.bindings.spi.http.Output)11 CoolUserFactoryException (it.cnr.cool.exception.CoolUserFactoryException)8 ClientMessageException (it.cnr.cool.web.scripts.exception.ClientMessageException)8 JSONObject (org.json.JSONObject)8 CmisObjectNotFoundException (org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException)5 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)4 CMISApplicationException (it.cnr.cool.web.scripts.exception.CMISApplicationException)4 ParseException (java.text.ParseException)4 Test (org.junit.Test)4 IOException (java.io.IOException)3 MessagingException (javax.mail.MessagingException)3 AddressException (javax.mail.internet.AddressException)3 CmisRuntimeException (org.apache.chemistry.opencmis.commons.exceptions.CmisRuntimeException)3 EmailException (org.apache.commons.mail.EmailException)3 JSONException (org.json.JSONException)3 JsonObject (com.google.gson.JsonObject)2 ACLType (it.cnr.cool.cmis.model.ACLType)2 OutputStream (java.io.OutputStream)2