@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());
    }
  }
 @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());
   }
 }
Beispiel #3
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);
  }
  @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."));
  }
  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();
  }