Package org.apache.chemistry.opencmis.client.api

Examples of org.apache.chemistry.opencmis.client.api.Document


    String[] rval = new String[documentIdentifiers.length];
    int i = 0;
    while (i < rval.length){
      CmisObject cmisObject = session.getObject(documentIdentifiers[i]);
      if (cmisObject.getBaseType().getId().equals(CMIS_DOCUMENT_BASE_TYPE)) {
        Document document = (Document) cmisObject;
       
        //we have to check if this CMIS repository support versioning
        // or if the versioning is disabled for this content
        if(StringUtils.isNotEmpty(document.getVersionLabel())){
          rval[i] = document.getVersionLabel();
        } else {
        //a CMIS document that doesn't contain versioning information will always be processed
          rval[i] = StringUtils.EMPTY;
        }
      } else {
View Full Code Here


      } else if(baseTypeId.equals(CMIS_DOCUMENT_BASE_TYPE)){

        // content ingestion

        Document document = (Document) cmisObject;
        long fileLength = document.getContentStreamLength();
        InputStream is = null;
       
        try {
          RepositoryDocument rd = new RepositoryDocument();
          Date createdDate = document.getCreationDate().getTime();
          Date modifiedDate = document.getLastModificationDate().getTime();
         
          rd.setFileName(document.getContentStreamFileName());
          rd.setMimeType(document.getContentStreamMimeType());
          rd.setCreatedDate(createdDate);
          rd.setModifiedDate(modifiedDate);
         
          //binary
          if(fileLength>0 && document.getContentStream()!=null){
            is = document.getContentStream().getStream();
            rd.setBinary(is, fileLength);
          }

          //properties
          List<Property<?>> properties = document.getProperties();
          String id = StringUtils.EMPTY;
          for (Property<?> property : properties) {
            String propertyId = property.getId();
            if (propertyId.endsWith(Constants.PARAM_OBJECT_ID))
              id = (String) property.getValue();

            if (property.getValue() !=null
                || property.getValues() != null) {
              PropertyType propertyType = property.getType();

              switch (propertyType) {

              case STRING:
              case ID:
              case URI:
              case HTML:
                if(property.isMultiValued()){
                  List<String> htmlPropertyValues = (List<String>) property.getValues();
                  for (String htmlPropertyValue : htmlPropertyValues) {
                    rd.addField(propertyId, htmlPropertyValue);
                  }
                } else {
                  String stringValue = (String) property.getValue();
                  if(StringUtils.isNotEmpty(stringValue)){
                    rd.addField(propertyId, stringValue);
                  }
                }
                break;
    
              case BOOLEAN:
                if(property.isMultiValued()){
                  List<Boolean> booleanPropertyValues = (List<Boolean>) property.getValues();
                  for (Boolean booleanPropertyValue : booleanPropertyValues) {
                    rd.addField(propertyId, booleanPropertyValue.toString());
                  }
                } else {
                  Boolean booleanValue = (Boolean) property.getValue();
                  if(booleanValue!=null){
                    rd.addField(propertyId, booleanValue.toString());
                  }
                }
                break;

              case INTEGER:
                if(property.isMultiValued()){
                  List<BigInteger> integerPropertyValues = (List<BigInteger>) property.getValues();
                  for (BigInteger integerPropertyValue : integerPropertyValues) {
                    rd.addField(propertyId, integerPropertyValue.toString());
                  }
                } else {
                  BigInteger integerValue = (BigInteger) property.getValue();
                  if(integerValue!=null){
                    rd.addField(propertyId, integerValue.toString());
                  }
                }
                break;

              case DECIMAL:
                if(property.isMultiValued()){
                  List<BigDecimal> decimalPropertyValues = (List<BigDecimal>) property.getValues();
                  for (BigDecimal decimalPropertyValue : decimalPropertyValues) {
                    rd.addField(propertyId, decimalPropertyValue.toString());
                  }
                } else {
                  BigDecimal decimalValue = (BigDecimal) property.getValue();
                  if(decimalValue!=null){
                    rd.addField(propertyId, decimalValue.toString());
                  }
                }
                break;

              case DATETIME:
                if(property.isMultiValued()){
                  List<GregorianCalendar> datePropertyValues = (List<GregorianCalendar>) property.getValues();
                  for (GregorianCalendar datePropertyValue : datePropertyValues) {
                    rd.addField(propertyId,
                        ISO8601_DATE_FORMATTER.format(datePropertyValue.getTime()));
                  }
                } else {
                  GregorianCalendar dateValue = (GregorianCalendar) property.getValue();
                  if(dateValue!=null){
                    rd.addField(propertyId, ISO8601_DATE_FORMATTER.format(dateValue.getTime()));
                  }
                }
                break;

              default:
                break;
              }
            }
          }
         
          //ingestion
         
          //version label
          String version = document.getVersionLabel();
          if(StringUtils.isEmpty(version))
            version = StringUtils.EMPTY;
         
          //documentURI
          String documentURI = CmisRepositoryConnectorUtils.getDocumentURL(document, session);
View Full Code Here

      } else if(baseTypeId.equals(CMIS_DOCUMENT_BASE_TYPE)){

        // content ingestion

        Document document = (Document) cmisObject;
        long fileLength = document.getContentStreamLength();
        InputStream is = null;
       
        try {
          RepositoryDocument rd = new RepositoryDocument();
          Date createdDate = document.getCreationDate().getTime();
          Date modifiedDate = document.getLastModificationDate().getTime();
         
          rd.setFileName(document.getContentStreamFileName());
          rd.setMimeType(document.getContentStreamMimeType());
          rd.setCreatedDate(createdDate);
          rd.setModifiedDate(modifiedDate);
         
          //binary
          if(fileLength>0 && document.getContentStream()!=null){
            is = document.getContentStream().getStream();
            rd.setBinary(is, fileLength);
          }

          //properties
          List<Property<?>> properties = document.getProperties();
          String id = StringUtils.EMPTY;
          for (Property<?> property : properties) {
            String propertyId = property.getId();
            if (propertyId.endsWith(Constants.PARAM_OBJECT_ID))
              id = (String) property.getValue();

            if (property.getValue() !=null
                || property.getValues() != null) {
              PropertyType propertyType = property.getType();

              switch (propertyType) {

              case STRING:
              case ID:
              case URI:
              case HTML:
                if(property.isMultiValued()){
                  List<String> htmlPropertyValues = (List<String>) property.getValues();
                  for (String htmlPropertyValue : htmlPropertyValues) {
                    rd.addField(propertyId, htmlPropertyValue);
                  }
                } else {
                  String stringValue = (String) property.getValue();
                  if(StringUtils.isNotEmpty(stringValue)){
                    rd.addField(propertyId, stringValue);
                  }
                }
                break;
    
              case BOOLEAN:
                if(property.isMultiValued()){
                  List<Boolean> booleanPropertyValues = (List<Boolean>) property.getValues();
                  for (Boolean booleanPropertyValue : booleanPropertyValues) {
                    rd.addField(propertyId, booleanPropertyValue.toString());
                  }
                } else {
                  Boolean booleanValue = (Boolean) property.getValue();
                  if(booleanValue!=null){
                    rd.addField(propertyId, booleanValue.toString());
                  }
                }
                break;

              case INTEGER:
                if(property.isMultiValued()){
                  List<BigInteger> integerPropertyValues = (List<BigInteger>) property.getValues();
                  for (BigInteger integerPropertyValue : integerPropertyValues) {
                    rd.addField(propertyId, integerPropertyValue.toString());
                  }
                } else {
                  BigInteger integerValue = (BigInteger) property.getValue();
                  if(integerValue!=null){
                    rd.addField(propertyId, integerValue.toString());
                  }
                }
                break;

              case DECIMAL:
                if(property.isMultiValued()){
                  List<BigDecimal> decimalPropertyValues = (List<BigDecimal>) property.getValues();
                  for (BigDecimal decimalPropertyValue : decimalPropertyValues) {
                    rd.addField(propertyId, decimalPropertyValue.toString());
                  }
                } else {
                  BigDecimal decimalValue = (BigDecimal) property.getValue();
                  if(decimalValue!=null){
                    rd.addField(propertyId, decimalValue.toString());
                  }
                }
                break;

              case DATETIME:
                if(property.isMultiValued()){
                  List<GregorianCalendar> datePropertyValues = (List<GregorianCalendar>) property.getValues();
                  for (GregorianCalendar datePropertyValue : datePropertyValues) {
                    rd.addField(propertyId,
                        ISO8601_DATE_FORMATTER.format(datePropertyValue.getTime()));
                  }
                } else {
                  GregorianCalendar dateValue = (GregorianCalendar) property.getValue();
                  if(dateValue!=null){
                    rd.addField(propertyId, ISO8601_DATE_FORMATTER.format(dateValue.getTime()));
                  }
                }
                break;

              default:
                break;
              }
            }
          }
         
          //ingestion
         
          //version label
          String version = document.getVersionLabel();
          if(StringUtils.isEmpty(version))
            version = StringUtils.EMPTY;
         
          //documentURI
          String documentURI = CmisRepositoryConnectorUtils.getDocumentURL(document, session);
View Full Code Here

    String[] rval = new String[documentIdentifiers.length];
    int i = 0;
    while (i < rval.length){
      CmisObject cmisObject = session.getObject(documentIdentifiers[i]);
      if (cmisObject.getBaseType().getId().equals(CMIS_DOCUMENT_BASE_TYPE)) {
        Document document = (Document) cmisObject;
       
        //we have to check if this CMIS repository support versioning
        // or if the versioning is disabled for this content
        if(StringUtils.isNotEmpty(document.getVersionLabel())){
          rval[i] = document.getVersionLabel();
        } else {
        //a CMIS document that doesn't contain versioning information will always be processed
          rval[i] = StringUtils.EMPTY;
        }
      } else {
View Full Code Here

                nameField.setText(object.getName());
                idField.setText(object.getId());
                typeField.setText(object.getType().getId());
                basetypeField.setText(object.getBaseTypeId().toString());
                if (object instanceof Document) {
                    Document doc = (Document) object;

                    try {
                        versionLabelField.setText(doc.getVersionLabel());
                    } catch (Exception e) {
                        versionLabelField.setText("???");
                    }

                    if (doc.isVersionSeriesCheckedOut() == null) {
                        pwcField.setText("");
                    } else if (doc.isVersionSeriesCheckedOut().booleanValue()) {
                        pwcField.setText(doc.getVersionSeriesCheckedOutId());
                    } else {
                        pwcField.setText("(not checked out)");
                    }
                } else {
                    pwcField.setText("");
View Full Code Here

        scriptOpenButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                try {
                    setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
                    Document doc = (Document) getClientModel().getCurrentObject();

                    String name = doc.getName().toLowerCase();
                    if (name.endsWith(".groovy")) {
                        File file = ClientHelper.createTempFileFromDocument(doc, null);
                        Console console = ClientHelper.openConsole(ObjectPanel.this, getClientModel(), null);
                        if (console != null) {
                            console.loadScriptFile(file);
                        }
                    } else {
                        ClientHelper.open(ObjectPanel.this, doc, null);
                    }
                } catch (Exception ex) {
                    ClientHelper.showError(null, ex);
                } finally {
                    setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
                }
            }
        });

        scriptRunButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                try {
                    setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
                    Document doc = (Document) getClientModel().getCurrentObject();
                    File file = ClientHelper.createTempFileFromDocument(doc, null);
                    String name = doc.getName().toLowerCase();
                    String ext = name.substring(name.lastIndexOf('.') + 1);

                    scriptOutput.setText("");
                    scriptOutput.setVisible(true);
                    scriptOutput.invalidate();
View Full Code Here

        } finally {
            lock.writeLock().unlock();
        }

        if (getObject() instanceof Document) {
            final Document doc = (Document) getObject();

            if (doc.getAllowableActions().getAllowableActions().contains(Action.CAN_GET_ALL_VERSIONS)) {
                SwingUtilities.invokeLater(new Runnable() {
                    @Override
                    public void run() {
                        try {
                            setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
                            List<Document> newVersions = doc.getAllVersions(getClientModel().getClientSession()
                                    .geVersionOperationContext());

                            lock.writeLock().lock();
                            try {
                                versions = newVersions;
View Full Code Here

        }
    }

    @Override
    public Object getDetailValueAt(int rowIndex, int columnIndex) {
        Document version = null;

        lock.readLock().lock();
        try {
            version = versions.get(rowIndex);
        } finally {
            lock.readLock().unlock();
        }

        switch (columnIndex) {
        case 0:
            return version.getName();
        case 1:
            return version.getVersionLabel();
        case 2:
            return version.isLatestVersion();
        case 3:
            return version.isMajorVersion();
        case 4:
            return version.isLatestMajorVersion();
        case 5:
            return version;
        case 6:
            return version.getContentStreamFileName();
        case 7:
            return version.getContentStreamMimeType();
        case 8:
            return version.getContentStreamLength() == -1 ? null : version.getContentStreamLength();
        }

        return null;
    }
View Full Code Here

            if ((row > -1) && (row < model.getCurrentChildren().size())) {
                String id = getValueAt(row, ID_COLUMN).toString();
                CmisObject object = model.getFromCurrentChildren(id);

                if (object instanceof Document) {
                    Document doc = (Document) object;

                    File tempFile = null;
                    try {
                        tempFile = ClientHelper.createTempFileFromDocument(doc, null);
                    } catch (Exception e) {
View Full Code Here

        CmisTestResult f;

        try {
            // create folder and document
            Folder testFolder = createTestFolder(session);
            Document doc = createDocument(session, testFolder, "versioningtest.txt", "versioning");
            DocumentTypeDefinition docType = (DocumentTypeDefinition) doc.getType();

            if (!docType.isVersionable()) {
                addResult(createResult(SKIPPED, "Test type is not versionable. Test skipped!"));
                doc.delete(true);
                return;
            }

            // check out
            ObjectId pwcId = doc.checkOut();
            Document pwc = (Document) session.getObject(pwcId, SELECT_ALL_NO_CACHE_OC);

            addResult(checkObject(session, pwc, getAllProperties(pwc), "PWC spec compliance - test 1"));

            checkCheckedOut(pwc);

            // cancel checkout
            pwc.cancelCheckOut();

            doc.refresh();
            checkCheckedIn(doc);

            // check out again
            pwcId = doc.checkOut();
            pwc = (Document) session.getObject(pwcId, SELECT_ALL_NO_CACHE_OC);

            addResult(checkObject(session, pwc, getAllProperties(pwc), "PWC spec compliance - test 2"));

            checkCheckedOut(pwc);

            // check in
            ObjectId newVersionId = pwc.checkIn(true, null, null, "Test Version 2");
            Document newVersion = (Document) session.getObject(newVersionId, SELECT_ALL_NO_CACHE_OC);

            addResult(checkObject(session, newVersion, getAllProperties(newVersion), "New version compliance"));

            checkCheckedIn(newVersion);

            // check version history
            List<Document> versions = newVersion.getAllVersions();
            f = createResult(FAILURE, "Version series should have 2 versions but has " + versions.size() + "!");
            addResult(assertEquals(2, versions.size(), null, f));

            if (versions.size() > 0) {
                f = createResult(FAILURE,
                        "Version history order is incorrect! The first version should be the new version.");
                addResult(assertEquals(newVersion.getId(), versions.get(0).getId(), null, f));
            }

            if (versions.size() > 1) {
                f = createResult(FAILURE,
                        "Version history order is incorrect! The second version should be the origin document.");
View Full Code Here

TOP

Related Classes of org.apache.chemistry.opencmis.client.api.Document

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.