@Test
  public void testFolder() {
    List<String> cmisObjsNames = new ArrayList<String>();
    List<String> cmisObjsIds = new ArrayList<String>();

    try {
      CollectionIterable<CmisObject> cmisObjs =
          (CollectionIterable<CmisObject>)
              getConnector()
                  .folder(
                      null, folderObjectId.getId(), NavigationOptions.CHILDREN, 100, null, null);
      AbstractIterator<CmisObject> ai = cmisObjs.iterator();

      while (ai.hasNext()) {
        CmisObject cmisObj = ai.next();
        cmisObjsNames.add(cmisObj.getName());
        cmisObjsIds.add(cmisObj.getId());
      }

      assertTrue(cmisObjsNames.containsAll(subFoldersNames));
      assertTrue(cmisObjsIds.containsAll(subFoldersIds));
      assertEquals(cmisObjsNames.size(), subFoldersNames.size());

    } catch (Exception e) {
      fail(e.getMessage());
    }
  }
예제 #2
0
 /**
  * Remove aspect from document or folder
  *
  * @param userName login username
  * @param password login password
  * @param siteName site name
  * @param contentName file or folder name
  * @param aspectToRemove aspect to be removed
  * @throws Exception if error
  */
 public void removeAspect(
     final String userName,
     final String password,
     final String siteName,
     final String contentName,
     DocumentAspect aspectToRemove)
     throws Exception {
   try {
     String contentNodeRef = getNodeRef(userName, password, siteName, contentName);
     Session session = getCMISSession(userName, password);
     CmisObject contentObj = session.getObject(contentNodeRef);
     List<SecondaryType> secondaryTypesList = contentObj.getSecondaryTypes();
     List<String> secondaryTypes = new ArrayList<String>();
     for (SecondaryType secondaryType : secondaryTypesList) {
       secondaryTypes.add(secondaryType.getId());
     }
     secondaryTypes.remove(aspectToRemove.getProperty());
     Map<String, Object> properties = new HashMap<String, Object>();
     {
       properties.put(PropertyIds.SECONDARY_OBJECT_TYPE_IDS, secondaryTypes);
     }
     contentObj.updateProperties(properties);
   } catch (CmisInvalidArgumentException ia) {
     throw new CmisRuntimeException("Invalid content " + contentName, ia);
   }
 }
예제 #3
0
  public static void listTopFolderWithPagingAndPropFilter(Session session) {
    Folder root = session.getRootFolder();

    Set<String> propertyFilter = new HashSet<String>();
    propertyFilter.add(PropertyIds.CREATED_BY);
    propertyFilter.add(PropertyIds.NAME);

    OperationContext operationContext = new OperationContextImpl();
    int maxItemsPerPage = 5;
    operationContext.setMaxItemsPerPage(maxItemsPerPage);
    operationContext.setFilter(propertyFilter);
    ItemIterable<CmisObject> contentItems = root.getChildren(operationContext);
    long numerOfPages = Math.abs(contentItems.getTotalNumItems() / maxItemsPerPage);
    int pageNumber = 1;
    boolean finishedPaging = false;
    int count = 0;
    while (!finishedPaging) {
      logger.info("Page " + pageNumber + " (" + numerOfPages + ")");
      ItemIterable<CmisObject> currentPage = contentItems.skipTo(count).getPage();
      for (CmisObject contentItem : currentPage) {
        logger.info(
            contentItem.getName() + " [type=" + contentItem.getType().getDisplayName() + "]");
        count++;
      }
      pageNumber++;
      if (!currentPage.getHasMoreItems()) {
        finishedPaging = true;
      }
    }
  }
 @Test
 public void testGetObjectByPath() {
   try {
     CmisObject cmisObj = getConnector().getObjectByPath(path);
     assertNotNull(cmisObj);
     assertEquals(testData.get("filename"), cmisObj.getName());
     assertEquals(documentObjectId.getId(), cmisObj.getId());
   } catch (Exception e) {
     fail(e.getMessage());
   }
 }
예제 #5
0
  @Override
  public void create() {
    super.create();

    this.objectToBeRenamed = CmisNavigatorSelectionHolder.getInstance().getSelectedObjects().get(0);
    if (objectToBeRenamed.getName() != null) {
      nameText.setText(objectToBeRenamed.getName());
    }

    String type = ((objectToBeRenamed instanceof Folder) ? " folder" : " file");
    setTitle("Rename " + type);
    setMessage(
        "Fill in the new name of " + type + " '" + objectToBeRenamed.getName() + "'",
        IMessageProvider.INFORMATION);
  }
  /** Performs the update. */
  private boolean doUpdate() {
    try {
      setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));

      Map<String, Object> properties = new HashMap<String, Object>();
      for (PropertyInputPanel propertyPanel : propertyPanels) {
        if (propertyPanel.includeInUpdate()) {
          properties.put(propertyPanel.getId(), propertyPanel.getValue());
        }
      }

      if (properties.isEmpty()) {
        return false;
      }

      ObjectId newId = object.updateProperties(properties, false);

      if ((newId != null) && newId.getId().equals(model.getCurrentObject().getId())) {
        try {
          model.reloadObject();
          model.reloadFolder();
        } catch (Exception ex) {
          ClientHelper.showError(null, ex);
        }
      }

      return true;
    } catch (Exception ex) {
      ClientHelper.showError(this, ex);
      return false;
    } finally {
      setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
    }
  }
예제 #7
0
  private String getDocumentURL(final CmisObject document, final Session session) {
    if (!(document instanceof Document)) {
      return null;
    }

    if (session.getBinding().getObjectService() instanceof LinkAccess) {
      return ((LinkAccess) session.getBinding().getObjectService())
          .loadContentLink(session.getRepositoryInfo().getId(), document.getId());
    }

    return null;
  }
  private void createGUI() {
    setTitle(WINDOW_TITLE);
    setPreferredSize(new Dimension(800, 600));
    setMinimumSize(new Dimension(300, 120));

    setLayout(new BorderLayout());

    final JPanel panel = new JPanel();
    panel.setLayout(new BoxLayout(panel, BoxLayout.PAGE_AXIS));

    final Font labelFont = UIManager.getFont("Label.font");
    final Font boldFont = labelFont.deriveFont(Font.BOLD, labelFont.getSize2D() * 1.2f);

    final JPanel topPanel = new JPanel();
    topPanel.setLayout(new BoxLayout(topPanel, BoxLayout.Y_AXIS));
    topPanel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
    final JLabel nameLabel = new JLabel(object.getName());
    nameLabel.setFont(boldFont);
    topPanel.add(nameLabel);
    topPanel.add(new JLabel(object.getId()));
    add(topPanel, BorderLayout.PAGE_START);

    JScrollPane scrollPane = new JScrollPane(panel);
    add(scrollPane, BorderLayout.CENTER);

    propertyPanels = new ArrayList<PropertyEditorFrame.PropertyInputPanel>();

    int position = 0;
    for (PropertyDefinition<?> propDef : object.getType().getPropertyDefinitions().values()) {
      boolean isUpdatable =
          (propDef.getUpdatability() == Updatability.READWRITE)
              || (propDef.getUpdatability() == Updatability.WHENCHECKEDOUT
                  && object
                      .getAllowableActions()
                      .getAllowableActions()
                      .contains(Action.CAN_CHECK_IN));

      if (isUpdatable) {
        PropertyInputPanel propertyPanel =
            new PropertyInputPanel(propDef, object.getPropertyValue(propDef.getId()), position++);

        propertyPanels.add(propertyPanel);
        panel.add(propertyPanel);
      }
    }

    JButton updateButton = new JButton("Update");
    updateButton.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
    updateButton.setDefaultCapable(true);
    updateButton.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent event) {
            if (doUpdate()) {
              dispose();
            }
          }
        });

    add(updateButton, BorderLayout.PAGE_END);

    setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    pack();
    setLocationRelativeTo(null);
    setVisible(true);
  }
예제 #9
0
 public static Object getObjectTypeId(CmisObject child) {
   return child.getPropertyValue(PropertyIds.OBJECT_TYPE_ID); // BASE_TYPE_ID?
 }
예제 #10
0
 public static Map<String, Object> objectProperties(CmisObject cmisObject) {
   List<Property<?>> propertyList = cmisObject.getProperties();
   return propertyDataToMap(propertyList);
 }
  @Override
  public void run(Session session) {
    CmisTestResult f;

    int numOfFolders = 20;

    // create a test folder
    Folder testFolder = createTestFolder(session);

    try {
      Map<String, Folder> folders = new HashMap<String, Folder>();

      // create folders
      for (int i = 0; i < numOfFolders; i++) {
        Folder newFolder = createFolder(session, testFolder, "folder" + i);
        folders.put(newFolder.getId(), newFolder);
      }

      // simple children test
      addResult(checkChildren(session, testFolder, "Test folder children check"));

      // check if all folders are there
      ItemIterable<CmisObject> children = testFolder.getChildren(SELECT_ALL_NO_CACHE_OC);
      List<String> childrenIds = new ArrayList<String>();
      for (CmisObject child : children) {
        if (child != null) {
          childrenIds.add(child.getId());
          Folder folder = folders.get(child.getId());

          f =
              createResult(
                  FAILURE, "Folder and test folder child don't match! Id: " + child.getId());
          addResult(assertShallowEquals(folder, child, null, f));
        }
      }

      f =
          createResult(
              FAILURE, "Number of created folders does not match the number of existing folders!");
      addResult(assertEquals(numOfFolders, childrenIds.size(), null, f));

      for (Folder folder : folders.values()) {
        if (!childrenIds.contains(folder.getId())) {
          addResult(
              createResult(
                  FAILURE,
                  "Created folder not found in test folder children! Id: " + folder.getId()));
        }
      }

      // delete all folders
      for (Folder folder : folders.values()) {
        // empty folders should be deleteable like this
        folder.delete(true);

        f =
            createResult(
                FAILURE,
                "Folder should not exist anymore but it is still there! Id: " + folder.getId());
        addResult(assertIsFalse(exists(folder), null, f));
      }
    } finally {
      // delete the test folder
      deleteTestFolder();
    }

    addResult(
        createInfoResult("Tested the creation and deletion of " + numOfFolders + " folders."));
  }
예제 #12
0
  public void objectLoaded(ClientModelEvent event) {
    CmisObject object = getClientModel().getCurrentObject();

    if (object == null) {
      nameField.setText("");
      idField.setText("");
      typeField.setText("");
      basetypeField.setText("");
      versionLabelField.setText("");
      pwcField.setText("");
      paths.removeAll();
      contentUrlField.setText("");
      allowableActionsList.removeAll();
      refreshButton.setEnabled(false);
      checkButton.setEnabled(false);
      scriptPanel.setVisible(false);
    } else {
      try {
        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("");
          versionLabelField.setText("");
        }

        if (object instanceof FileableCmisObject) {
          if (object instanceof Folder) {
            paths.setList(Collections.singletonList(((Folder) object).getPath()));
          } else {
            paths.setList(Collections.singletonList(""));
            final FileableCmisObject pathObject = (FileableCmisObject) object;
            SwingUtilities.invokeLater(
                new Runnable() {
                  @Override
                  public void run() {
                    try {
                      List<String> pathsList = pathObject.getPaths();
                      if ((pathsList == null) || (pathsList.size() == 0)) {
                        paths.setList(Collections.singletonList("(unfiled)"));
                      } else {
                        paths.setList(pathsList);
                      }
                    } catch (Exception e) {
                      paths.setList(Collections.singletonList("(???)"));
                      // ClientHelper.showError(null, e);
                    }
                    ObjectPanel.this.revalidate();
                  }
                });
          }
        } else {
          paths.setList(Collections.singletonList("(not filable)"));
        }

        String docUrl = getDocumentURL(object, getClientModel().getClientSession().getSession());
        if (docUrl != null) {
          contentUrlField.setText(docUrl);
        } else {
          contentUrlField.setText("(not available)");
        }

        if (object.getAllowableActions() != null) {
          allowableActionsList.setList(object.getAllowableActions().getAllowableActions());
        } else {
          allowableActionsList.setList(Collections.singletonList("(missing)"));
        }

        refreshButton.setEnabled(true);
        checkButton.setEnabled(true);

        if (object instanceof Document) {
          String name = object.getName().toLowerCase(Locale.ENGLISH);
          int x = name.lastIndexOf('.');
          if ((x > -1) && (scriptExtensions.contains(name.substring(x + 1)))) {
            scriptPanel.setVisible(true);
            scriptOutput.setVisible(false);
          } else {
            scriptPanel.setVisible(false);
          }
        }
      } catch (Exception e) {
        ClientHelper.showError(this, e);
      }
    }

    revalidate();
  }