Advertisement
Coriic

Untitled

Jan 14th, 2017
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.97 KB | None | 0 0
  1. //FolderController
  2. public FolderMetadata handleCreateNewFolder(Request request, Response response){
  3.         try{
  4.             PathManager pathManager = new PathManager(request.params(":path"));
  5.             if(folderMetadataRepostiory.fetchByPathDisplay(pathManager.getPath()).isEmpty()){
  6.                 Integer parentID = folderMetadataRepostiory.fetchByPathDisplay(pathManager.getParentPath()).get(0).getFolderId();
  7.                 System.out.println(parentID);
  8.                 FolderMetadata folderMetadata = new FolderMetadata(null,
  9.                         pathManager.getFileName(),
  10.                         pathManager.pathToLowerCase(),
  11.                         pathManager.getPath(),
  12.                         parentID,
  13.                         new Date().toString(),
  14.                         10); // TO DO
  15.                 FolderMetadata inserted = folderMetadataRepostiory.insertFolder(folderMetadata);
  16.                 folderFolderContentsRepository.insertFolder(new FolderFolderContents(parentID, folderMetadata.getFolderId()));
  17.                 response.status(CREATED);
  18.                 return inserted;
  19.             }
  20.             else{
  21.                 response.status(FOLDEREXISTS);
  22.                 throw new FolderAlreadyExists("Folder with path: " + pathManager.getPath() + " already exists");
  23.             }
  24.         }
  25.         catch(WrongPathFormat ex){
  26.             response.status(INVALIDPATHPARAMETER);
  27.             throw ex;
  28.         }
  29.     }
  30.  
  31. //FolderMetadataDAO
  32. public pl.edu.agh.kis.florist.db.tables.pojos.FolderMetadata insertFolder(pl.edu.agh.kis.florist.db.tables.pojos.FolderMetadata folderMetadata){
  33.         try (DSLContext create = DSL.using(DB_URL)){
  34.             FolderMetadataRecord record=create.newRecord(FOLDER_METADATA, folderMetadata);
  35.             record.store();
  36.             pl.edu.agh.kis.florist.db.tables.pojos.FolderMetadata retrieved=record.into(pl.edu.agh.kis.florist.db.tables.pojos.FolderMetadata.class);
  37.             return retrieved;
  38.         }
  39.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement