@Ignore // git based vfs does not yet support move
  @Test
  public void testMoveEmptyDirectory() throws NoSuchFileException {
    Repository repository = new VFSRepository(producer.getIoService());
    ((VFSRepository) repository).setDescriptor(descriptor);
    Directory sourceDir = repository.createDirectory("/source");

    boolean directoryExists =
        repository.directoryExists(sourceDir.getLocation() + sourceDir.getName());
    assertTrue(directoryExists);
    Collection<Asset> foundAsset = repository.listAssets("/source", new FilterByExtension("bpmn2"));

    assertNotNull(foundAsset);
    assertEquals(0, foundAsset.size());

    boolean copied = repository.moveDirectory("/source", "/", "target");
    assertTrue(copied);

    boolean movedDirectoryExists = repository.directoryExists("/source");
    assertFalse(movedDirectoryExists);
    movedDirectoryExists = repository.directoryExists("/target");
    assertTrue(movedDirectoryExists);

    foundAsset = repository.listAssets("/target", new FilterByExtension("bpmn2"));

    assertNotNull(foundAsset);
    assertEquals(0, foundAsset.size());
  }
Ejemplo n.º 2
0
  public static void main(String[] args) throws FileNotFoundException {
    ArrayList<File> files = new ArrayList<>();
    Directory directory = new Directory(files);

    Scanner scanner = new Scanner(System.in);
    directory.setName("dir1");
    System.out.println("You created a directory '" + directory.getName() + "'");

    directory.addFiles(new TextFile());
    directory.getFiles().get(0).setName("File1");
    System.out.println("'" + directory.getFiles().get(0).getName() + "' file has been created");

    directory.addFiles(new TextFile());
    directory.getFiles().get(1).setName("File2");
    System.out.println("'" + directory.getFiles().get(1).getName() + "' file has been created");

    directory.addFiles(new TextFile());
    directory.getFiles().get(2).setName("File3");
    System.out.println("'" + directory.getFiles().get(2).getName() + "' file has been created");

    // Візьмемо файл за іменем
    System.out.print("Enter the file name you want to get: ");
    String fileName = scanner.next();
    directory.getFileByName(fileName);
  }
  @Test
  public void testDirectoryExists() {
    Repository repository = new VFSRepository(producer.getIoService());
    ((VFSRepository) repository).setDescriptor(descriptor);
    boolean rootFolderExists = repository.directoryExists("/test");
    assertFalse(rootFolderExists);

    Directory directoryId = repository.createDirectory("/test");
    assertNotNull(directoryId);
    assertEquals("test", directoryId.getName());
    assertEquals("/", directoryId.getLocation());
    assertNotNull(directoryId.getUniqueId());

    rootFolderExists = repository.directoryExists("/test");
    assertTrue(rootFolderExists);

    AssetBuilder builder = AssetBuilderFactory.getAssetBuilder(Asset.AssetType.Byte);
    builder.content("simple content".getBytes()).type("png").name("test").location("/test");

    String id = repository.createAsset(builder.getAsset());

    assertNotNull(id);

    boolean assetPathShouldNotExists = repository.directoryExists("/test/test.png");
    assertFalse(assetPathShouldNotExists);
  }
Ejemplo n.º 4
0
 @Override
 public void configure(Map<String, String> parameters)
     throws IllegalArgumentException, IllegalStateException {
   if (this.parameters != null) {
     throw new IllegalStateException(
         "cannot change configuration, may be already in use somewhere");
   }
   directoryName = parameters.get(PARAM_DIRECTORY);
   if (directoryName != null) {
     directoryName = directoryName.trim();
   }
   if (directoryName == null || directoryName.isEmpty()) {
     throw new IllegalArgumentException(
         "missing directory parameter. A directory name is necessary");
   }
   fetchDirectory();
   idField = directory.getIdField();
   schema = directory.getSchema();
   if (schema.endsWith("xvocabulary")) {
     hierarchical = true;
     parentField = "parent";
     separator = "/";
   }
   String parentFieldParam = StringUtils.trim(parameters.get(PARAM_PARENT_FIELD));
   String separatorParam = StringUtils.trim(parameters.get(PARAM_SEPARATOR));
   if (!StringUtils.isBlank(parentFieldParam) && !StringUtils.isBlank(separatorParam)) {
     hierarchical = true;
     parentField = parentFieldParam;
     separator = separatorParam;
   }
   this.parameters = new HashMap<String, Serializable>();
   this.parameters.put(PARAM_DIRECTORY, directory.getName());
 }
Ejemplo n.º 5
0
  public String toString() {
    if (path != null) {
      StringBuffer sb = new StringBuffer();
      int size = path.size();
      for (int i = (size - 1); i >= 0; i--) {
        Directory d = (Directory) path.elementAt(i);

        sb.append(d.getName());

        if (i != size - 1) sb.append(PATH_SEPARATOR);
      }
      return sb.toString();
    } else return directory + itemName;
  }
  @Test
  public void testCreateDirectory() {

    Repository repository = new VFSRepository(producer.getIoService());
    ((VFSRepository) repository).setDescriptor(descriptor);
    boolean rootFolderExists = repository.directoryExists("/test");
    assertFalse(rootFolderExists);

    Directory directoryId = repository.createDirectory("/test");
    assertNotNull(directoryId);
    assertEquals("test", directoryId.getName());
    assertEquals("/", directoryId.getLocation());
    assertNotNull(directoryId.getUniqueId());

    rootFolderExists = repository.directoryExists("/test");
    assertTrue(rootFolderExists);
  }
Ejemplo n.º 7
0
 @Override
 public Object fetch(Object value) throws IllegalStateException {
   checkConfig();
   if (value != null && value instanceof String) {
     String id = (String) value;
     if (hierarchical) {
       String[] ids = StringUtils.split(id, separator);
       if (ids.length > 0) {
         id = ids[ids.length - 1];
       } else {
         return null;
       }
     }
     try (Session session = directory.getSession()) {
       DocumentModel doc = session.getEntry(id);
       if (doc != null) {
         return new DirectoryEntry(directory.getName(), doc);
       }
       return null;
     }
   }
   return null;
 }
Ejemplo n.º 8
0
 @Override
 public String getConstraintErrorMessage(Object invalidValue, Locale locale) {
   checkConfig();
   return Helper.getConstraintErrorMessage(this, invalidValue, locale, directory.getName());
 }