Search in sources :

Example 1 with ObjectIdImpl

use of org.apache.chemistry.opencmis.client.runtime.ObjectIdImpl 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 2 with ObjectIdImpl

use of org.apache.chemistry.opencmis.client.runtime.ObjectIdImpl 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);
}
Also used : MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) Calendar(java.util.Calendar) OperationContextImpl(org.apache.chemistry.opencmis.client.runtime.OperationContextImpl) Criteria(it.cnr.si.opencmis.criteria.Criteria) BindingSession(org.apache.chemistry.opencmis.client.bindings.spi.BindingSession) ObjectIdImpl(org.apache.chemistry.opencmis.client.runtime.ObjectIdImpl) BindingSession(org.apache.chemistry.opencmis.client.bindings.spi.BindingSession) BeforeEach(org.junit.jupiter.api.BeforeEach) Disabled(org.junit.jupiter.api.Disabled)

Example 3 with ObjectIdImpl

use of org.apache.chemistry.opencmis.client.runtime.ObjectIdImpl in project cool-jconon by consiglionazionaledellericerche.

the class DocumentController method delete.

@DeleteMapping(value = "/delete")
public ResponseEntity<Boolean> delete(HttpServletRequest req, @RequestParam("objectId") String objectId) {
    Session session = cmisService.getCurrentCMISSession(req);
    session.delete(new ObjectIdImpl(objectId));
    return ResponseEntity.ok(Boolean.TRUE);
}
Also used : ObjectIdImpl(org.apache.chemistry.opencmis.client.runtime.ObjectIdImpl) Session(org.apache.chemistry.opencmis.client.api.Session)

Example 4 with ObjectIdImpl

use of org.apache.chemistry.opencmis.client.runtime.ObjectIdImpl in project cool-jconon by consiglionazionaledellericerche.

the class ManageCall method copyLabels.

@GET
@Path("copy-labels")
public Response copyLabels(@Context HttpServletRequest request, @QueryParam("callFrom") String callFrom, @QueryParam("callId") String callId, @CookieParam("__lang") String __lang) {
    ResponseBuilder rb;
    Properties labels = new Properties();
    try {
        final Session currentCMISSession = cmisService.getCurrentCMISSession(request);
        competitionService.copyLabels(currentCMISSession, callFrom, callId);
        labels = competitionService.getDynamicLabels(new ObjectIdImpl(callId), currentCMISSession);
        rb = Response.ok(labels);
    } catch (ClientMessageException e) {
        LOGGER.error("error loading labels {}", callId, e);
        rb = Response.status(Status.INTERNAL_SERVER_ERROR).entity(Collections.singletonMap("message", e.getMessage()));
    }
    return rb.build();
}
Also used : ClientMessageException(it.cnr.cool.web.scripts.exception.ClientMessageException) ResponseBuilder(javax.ws.rs.core.Response.ResponseBuilder) ObjectIdImpl(org.apache.chemistry.opencmis.client.runtime.ObjectIdImpl) Session(org.apache.chemistry.opencmis.client.api.Session)

Example 5 with ObjectIdImpl

use of org.apache.chemistry.opencmis.client.runtime.ObjectIdImpl in project manifoldcf by apache.

the class CmisOutputConnector method addOrReplaceDocumentWithException.

@Override
public int addOrReplaceDocumentWithException(String documentURI, VersionContext pipelineDescription, RepositoryDocument document, String authorityNameString, IOutputAddActivity activities) throws ManifoldCFException, ServiceInterruption, IOException {
    getSession();
    boolean isDropZoneFolder = isDropZoneFolder(cmisQuery);
    long startTime = System.currentTimeMillis();
    String resultDescription = StringUtils.EMPTY;
    Folder leafParent = null;
    String fileName = StringUtils.EMPTY;
    InputStream inputStream = null;
    ReplayableInputStream replayableInputStream = null;
    ContentStream contentStream = null;
    // properties
    // (minimal set: name and object type id)
    Map<String, Object> properties = new HashMap<String, Object>();
    Long binaryLength = null;
    String mimeType = StringUtils.EMPTY;
    try {
        if (isDropZoneFolder) {
            // Creation of the new Repository Node
            fileName = document.getFileName();
            Date creationDate = document.getCreatedDate();
            Date lastModificationDate = document.getModifiedDate();
            String objectId = StringUtils.EMPTY;
            mimeType = document.getMimeType();
            binaryLength = document.getBinaryLength();
            // check if the repository connector includes the content path
            String primaryPath = StringUtils.EMPTY;
            List<String> sourcePath = document.getSourcePath();
            if (sourcePath != null && !sourcePath.isEmpty()) {
                primaryPath = sourcePath.get(0);
            }
            // if the source is CMIS Repository Connector we override the objectId for synchronizing with removeDocument method
            if (isSourceRepoCmisCompliant(document)) {
                String[] cmisObjectIdArray = (String[]) document.getField(PropertyIds.OBJECT_ID);
                if (cmisObjectIdArray != null && cmisObjectIdArray.length > 0) {
                    objectId = cmisObjectIdArray[0];
                }
            // Mapping all the CMIS properties ...
            /*
          Iterator<String> fields = document.getFields();
          while (fields.hasNext()) {
            String field = (String) fields.next();
            if(!StringUtils.equals(field, "cm:lastThumbnailModification")
                || !StringUtils.equals(field, "cmis:secondaryObjectTypeIds")) {
              String[] valuesArray = (String[]) document.getField(field);
              properties.put(field,valuesArray);
            }
          }
          */
            }
            // Agnostic metadata
            properties.put(PropertyIds.OBJECT_TYPE_ID, EnumBaseObjectTypeIds.CMIS_DOCUMENT.value());
            properties.put(PropertyIds.NAME, fileName);
            properties.put(PropertyIds.CREATION_DATE, creationDate);
            properties.put(PropertyIds.LAST_MODIFICATION_DATE, lastModificationDate);
            // check objectId
            if (StringUtils.isNotEmpty(objectId)) {
                ObjectId objId = new ObjectIdImpl(objectId);
                properties.put(PropertyIds.OBJECT_ID, objId);
            }
            // Content Stream
            inputStream = document.getBinaryStream();
            replayableInputStream = new ReplayableInputStream(inputStream);
            contentStream = new ContentStreamImpl(fileName, BigInteger.valueOf(binaryLength), mimeType, replayableInputStream);
            // create a new content
            leafParent = getOrCreateLeafParent(parentDropZoneFolder, creationDate, Boolean.valueOf(createTimestampTree), primaryPath);
            leafParent.createDocument(properties, contentStream, versioningState);
            resultDescription = DOCUMENT_STATUS_ACCEPTED_DESC;
            return DOCUMENT_STATUS_ACCEPTED;
        } else {
            resultDescription = DOCUMENT_STATUS_REJECTED_DESC;
            return DOCUMENT_STATUS_REJECTED;
        }
    } catch (CmisContentAlreadyExistsException | CmisNameConstraintViolationException e) {
        // updating the existing content
        if (leafParent != null) {
            String documentFullPath = leafParent.getPath() + CmisOutputConnectorUtils.SLASH + fileName;
            String newFileName = fileName + System.currentTimeMillis();
            Document currentContent = (Document) session.getObjectByPath(documentFullPath);
            currentContent.updateProperties(properties);
            replayableInputStream.restart(true);
            contentStream = new ContentStreamImpl(newFileName, BigInteger.valueOf(binaryLength), mimeType, replayableInputStream);
            currentContent.setContentStream(contentStream, true);
            Logging.connectors.warn("CMIS: Document already exists - Updating: " + documentFullPath);
        }
        resultDescription = DOCUMENT_STATUS_ACCEPTED_DESC;
        return DOCUMENT_STATUS_ACCEPTED;
    } catch (Exception e) {
        resultDescription = DOCUMENT_STATUS_REJECTED_DESC;
        throw new ManifoldCFException(e.getMessage(), e);
    } finally {
        if (inputStream != null) {
            inputStream.close();
        }
        activities.recordActivity(startTime, ACTIVITY_INJECTION, document.getBinaryLength(), documentURI, resultDescription, resultDescription);
    }
}
Also used : ContentStreamImpl(org.apache.chemistry.opencmis.commons.impl.dataobjects.ContentStreamImpl) HashMap(java.util.HashMap) ObjectId(org.apache.chemistry.opencmis.client.api.ObjectId) ReplayableInputStream(org.apache.manifoldcf.connectorcommon.fuzzyml.ReplayableInputStream) InputStream(java.io.InputStream) Folder(org.apache.chemistry.opencmis.client.api.Folder) RepositoryDocument(org.apache.manifoldcf.agents.interfaces.RepositoryDocument) Document(org.apache.chemistry.opencmis.client.api.Document) Date(java.util.Date) CmisContentAlreadyExistsException(org.apache.chemistry.opencmis.commons.exceptions.CmisContentAlreadyExistsException) URISyntaxException(java.net.URISyntaxException) CmisObjectNotFoundException(org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException) NotBoundException(java.rmi.NotBoundException) ManifoldCFException(org.apache.manifoldcf.core.interfaces.ManifoldCFException) RemoteException(java.rmi.RemoteException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) CmisPermissionDeniedException(org.apache.chemistry.opencmis.commons.exceptions.CmisPermissionDeniedException) InterruptedIOException(java.io.InterruptedIOException) CmisNameConstraintViolationException(org.apache.chemistry.opencmis.commons.exceptions.CmisNameConstraintViolationException) CmisConnectionException(org.apache.chemistry.opencmis.commons.exceptions.CmisConnectionException) IOException(java.io.IOException) CmisNameConstraintViolationException(org.apache.chemistry.opencmis.commons.exceptions.CmisNameConstraintViolationException) ContentStream(org.apache.chemistry.opencmis.commons.data.ContentStream) ManifoldCFException(org.apache.manifoldcf.core.interfaces.ManifoldCFException) ReplayableInputStream(org.apache.manifoldcf.connectorcommon.fuzzyml.ReplayableInputStream) CmisContentAlreadyExistsException(org.apache.chemistry.opencmis.commons.exceptions.CmisContentAlreadyExistsException) ObjectIdImpl(org.apache.chemistry.opencmis.client.runtime.ObjectIdImpl)

Aggregations

ObjectIdImpl (org.apache.chemistry.opencmis.client.runtime.ObjectIdImpl)14 ClientMessageException (it.cnr.cool.web.scripts.exception.ClientMessageException)5 JsonObject (com.google.gson.JsonObject)4 ResponseBuilder (javax.ws.rs.core.Response.ResponseBuilder)4 Session (org.apache.chemistry.opencmis.client.api.Session)4 ContentStreamImpl (org.apache.chemistry.opencmis.commons.impl.dataobjects.ContentStreamImpl)4 JsonParser (com.google.gson.JsonParser)2 Criteria (it.cnr.si.opencmis.criteria.Criteria)2 IOException (java.io.IOException)2 CmisContentAlreadyExistsException (org.apache.chemistry.opencmis.commons.exceptions.CmisContentAlreadyExistsException)2 CmisPermissionDeniedException (org.apache.chemistry.opencmis.commons.exceptions.CmisPermissionDeniedException)2 JSONObject (org.json.JSONObject)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 ACLType (it.cnr.cool.cmis.model.ACLType)1 CMISUser (it.cnr.cool.security.service.impl.alfresco.CMISUser)1 SpringI18NError (it.cnr.si.cool.jconon.rest.openapi.utils.SpringI18NError)1 CommonServiceTest (it.cnr.si.cool.jconon.util.CommonServiceTest)1 InputStream (java.io.InputStream)1 InterruptedIOException (java.io.InterruptedIOException)1 Serializable (java.io.Serializable)1