Package ca.carleton.gcrc.couch.client

Examples of ca.carleton.gcrc.couch.client.CouchDb


      if( atlasProperties.isCouchDbSubmissionDbEnabled() ){

        // Submission DB name
        String submissionDbName = atlasProperties.getCouchDbSubmissionDbName();

        CouchDb submissionDb = couchClient.getDatabase(submissionDbName);
        CouchDesignDocument submissionDesign = submissionDb.getDesignDocument("submission");

        CouchUserDb userDb = couchClient.getUserDatabase();
       
        SubmissionRobotSettings settings = new SubmissionRobotSettings();
        settings.setAtlasName(atlasProperties.getAtlasName());
View Full Code Here


  private void initExport(ServletContext servletContext) throws ServletException {

    try {
      ExportConfiguration config = new ExportConfiguration();
      CouchDb couchDb = couchDd.getDatabase();
      config.setCouchDb(couchDb);
      CouchDesignDocument atlasDesign = couchDb.getDesignDocument("atlas");
      config.setAtlasDesignDocument(atlasDesign);
      servletContext.setAttribute(ExportConfiguration.CONFIGURATION_KEY, config);

    } catch(Exception e) {
      logger.error("Error configuring export service",e);
View Full Code Here

    File atlasDir = gs.getAtlasDir();

    // Load properties for atlas
    AtlasProperties atlasProperties = AtlasProperties.fromAtlasDir(atlasDir);

    CouchDb couchDb = CommandSupport.createCouchDb(gs, atlasProperties);
   
   
    // Prepare update process
    DocumentUpdateProcess updateProcess =
        CommandUpdate.createDocumentUpdateProcess(gs, couchDb);
   
    // Update site design document
    try {
      pushSiteDesign(gs, atlasDir, atlasProperties, updateProcess);
    } catch(Exception e) {
      throw new Exception("Unable to upload site design document", e);
    }
   
    // Update atlas design document
    try {
      pushAtlasDesign(gs, atlasDir, atlasProperties, updateProcess);
    } catch(Exception e) {
      throw new Exception("Unable to upload atlas design document", e);
    }
   
    // Update mobile design document
    try {
      pushMobileDesign(gs, atlasDir, atlasProperties, updateProcess);
    } catch(Exception e) {
      throw new Exception("Unable to upload mobile design document", e);
    }
   
    // Update submission database with design document
    if( atlasProperties.isCouchDbSubmissionDbEnabled() ) {
      try {
        CouchDb submissionCouchDb = CommandSupport.createCouchDbSubmission(gs, atlasProperties);
 
        DocumentUpdateProcess updateProcessForSubmissionDb =
            CommandUpdate.createDocumentUpdateProcess(gs, submissionCouchDb);
       
        pushSubmissionDesign(gs, atlasDir, atlasProperties, updateProcessForSubmissionDb);
View Full Code Here

        throw new ServletException("Unable to find design document source for user auth");
      }
    }
   
    try {
      CouchDb userDb = couchClient.getDatabase("_users");
      DocumentUpdateProcess updateProcess = new DocumentUpdateProcess(userDb);
      updateProcess.setListener(UpdateListener._singleton);
     
      FSEntry fileEntry = new FSEntryFile(ddDir);
      Document doc = DocumentFile.createDocument(fileEntry);
View Full Code Here

         <value> a value provided by the submitter
     */
   
    try {
      // Get CouchDb instance on behalf of the user
      CouchDb userCouchDb = getUserCouchDbFromCookies(cookies);
      CouchAuthenticationContext userContext = getUserFromClient(userCouchDb.getClient());
     
      // Create an upload request
      JSONObject doc = new JSONObject();
     
      JSONObject uploadRequest = new JSONObject();
      doc.put("nunaliit_upload_request", uploadRequest);
      uploadRequest.put("docId", docId);
      uploadRequest.put("revision", revision);
      uploadRequest.put("uploadId", uploadId);

      JSONArray files = new JSONArray();
      uploadRequest.put("files", files);
     
      Set<String> fileNames = new HashSet<String>();
      for(LoadedFile uploadedFile : uploadedFiles) {
        File actualFile = uploadedFile.getFile();
        String originalName = uploadedFile.getOriginalFileName();
       
        // Compute name for attachment
        String attachmentName = null;
        {
          File tempFile = new File(originalName);
          attachmentName = tempFile.getName();
          if( fileNames.contains(attachmentName) ) {
            // Select a different file name
            String prefix = "";
            String suffix = "";
            int pos = attachmentName.indexOf('.', 1);
            if( pos < 0 ) {
              prefix = attachmentName;
            } else {
              prefix = attachmentName.substring(0, pos-1);
              suffix = attachmentName.substring(pos);
            }
            int counter = 0;
            while( fileNames.contains(attachmentName) ) {
              attachmentName = prefix + counter + suffix;
              ++counter;
            }
          }
        }
        fileNames.add(attachmentName);
       
        JSONObject file = new JSONObject();
        files.put(file);
        file.put("attachmentName", attachmentName);
        file.put("originalName", originalName);
        file.put("submitter", userContext.getName());
       
        JSONObject original = new JSONObject();
        file.put("original", original);
        original.put("mediaFile", actualFile.getName());
       
        // Add user data
        JSONObject data = new JSONObject();
        file.put("data", data);
        for(String key : parameters.keySet()) {
          if( "id".equals(key)
           || "rev".equals(key)
           || "uploadId".equals(key)
           ) {
            // Drop already processed parameters
          } else {
            List<String> values = parameters.get(key);
            if( values.size() > 0 ) {
              data.put(key, values.get(0));
            }
          }
        }
      }
     
      // Update document before saving
      CouchNunaliitUtils.adjustDocumentForStorage(doc, userContext);
   
      userCouchDb.createDocument(doc);
     
      logger.info("onLoad update: "+doc.optString("_id")+" -> "+fileNames);
    } catch(Exception e) {
      logger.error("Unable to create an upload request",e);
    }
View Full Code Here

        throw new ServletException("Unable to find design document source for user auth");
      }
    }
   
    try {
      CouchDb userDb = couchClient.getDatabase("_users");
      DesignDocumentPush ddPush = new DesignDocumentPush(userDb, USER_DESIGN_AUTH, ddDir);
      ddPush.push();
    } catch(Exception e) {
      throw new ServletException("Problem pushing design document: "+USER_DESIGN_AUTH, e);
    }
View Full Code Here

  static public UserDesignDocumentImpl getUserDesignDocument(CouchClient couchClient) throws Exception {
    if( false == couchClient.databaseExists("_users") ) {
      throw new Exception("_users database not found");
    }
   
    CouchDb userDb = couchClient.getDatabase("_users");
    return getUserDesignDocument(userDb);
  }
View Full Code Here

        revision = parameters.get("rev").get(0);
      }
    }
   
    // Get CouchDb instance on behalf of the user
    CouchDb userCouchDb = getUserCouchDbFromCookies(cookies);
    CouchUserContext userContext = getUserFromClient(userCouchDb.getClient());
   
    if( null != docId
     && null != revision
     && uploadedFiles.size() > 0 ) {
      // This is uploading to an existing document
      JSONObject doc = null;
      try {
        doc = userCouchDb.getDocument(docId);
       
        logger.info("onLoad fetched: "+doc.optString("_id")+" -> "+doc.optString("_rev")
            + " for: " + userContext.getName() );
      } catch(Exception e) {
        logger.error("Unable to load document for id: "+docId,e);
      }

      if( null != doc ) {
        for(LoadedFile uploadedFile : uploadedFiles) {
          File actualFile = uploadedFile.getFile();
          String originalName = uploadedFile.getOriginalFileName();
         
          JSONObject nunaliitAttachments = doc.optJSONObject(UploadConstants.ATTACHMENTS_KEY);
          if( null == nunaliitAttachments ) {
            nunaliitAttachments = new JSONObject();
            nunaliitAttachments.put("nunaliit_type", "attachment_descriptions");
            nunaliitAttachments.put("files", new JSONObject());
            doc.put(UploadConstants.ATTACHMENTS_KEY, nunaliitAttachments);
          }
          JSONObject fileDic = nunaliitAttachments.optJSONObject("files");
          if( null == fileDic ) {
            fileDic = new JSONObject();
            nunaliitAttachments.put("files",fileDic);
          }

          // Compute name for attachment
          String attachmentName = null;
          {
            File tempFile = new File(originalName);
            attachmentName = tempFile.getName();
            if( JSONSupport.containsKey(fileDic, attachmentName) ) {
              // Select a different file name
              String prefix = "";
              String suffix = "";
              int pos = attachmentName.indexOf('.', 1);
              if( pos < 0 ) {
                prefix = attachmentName;
              } else {
                prefix = attachmentName.substring(0, pos-1);
                suffix = attachmentName.substring(pos);
              }
              int counter = 0;
              while( JSONSupport.containsKey(fileDic, attachmentName) ) {
                attachmentName = prefix + counter + suffix;
                ++counter;
              }
            }
          }

          FileConversionContext conversionContext = new FileConversionContext(doc, dd, attachmentName, mediaDir);
         
          AttachmentDescriptor fileDescription = conversionContext.getAttachmentDescription();
         
          fileDescription.setAttachmentName(attachmentName);
          fileDescription.setStatus(UploadConstants.UPLOAD_STATUS_SUBMITTED);
          fileDescription.setOriginalName(originalName);
          fileDescription.setSubmitterName(userContext.getName());
         
          OriginalFileDescriptor originalJson = fileDescription.getOriginalFileDescription();
          originalJson.setMediaFileName(actualFile.getName());

          // Add user data
          UserDataDescriptor userData = fileDescription.getUserDataDescription();
          for(String key : parameters.keySet()) {
            if( "id".equals(key)
             || "rev".equals(key)
             ) {
              // Drop already processed parameters
            } else {
              List<String> values = parameters.get(key);
              if( values.size() > 0 ) {
                userData.setStringAttribute(key, values.get(0));
              }
            }
          }
         
          // Update document before saving
          CouchNunaliitUtils.adjustDocumentForStorage(doc, userContext);
         
          try {
            userCouchDb.updateDocument(doc);
           
            logger.info("onLoad update: "+doc.optString("_id")+" -> "+actualFile);
          } catch(Exception e) {
            logger.error("Unable to save information about file: "+actualFile.getName(),e);
          }
View Full Code Here

    ) throws Exception {
   
    CouchClient couchClient = createCouchClient(gs, atlasProperties);
   
    // Get database from Couch Client
    CouchDb couchDb = null;
    {
      String dbName = atlasProperties.getCouchDbName();
      if( false == couchClient.databaseExists(dbName) ) {
        couchClient.createDatabase(dbName);
      }
View Full Code Here

    File atlasDir = gs.getAtlasDir();

    // Load properties for atlas
    AtlasProperties atlasProperties = AtlasProperties.fromAtlasDir(atlasDir);

    CouchDb couchDb = CommandSupport.createCouchDb(gs, atlasProperties);
   
    // Prepare update process
    DocumentUpdateProcess updateProcess =
        CommandUpdate.createDocumentUpdateProcess(gs, couchDb);
   
    // Update site design document
    try {
      pushSiteDesign(gs, atlasDir, atlasProperties, updateProcess);
    } catch(Exception e) {
      throw new Exception("Unable to upload site design document", e);
    }
   
    // Update atlas design document
    try {
      pushAtlasDesign(gs, atlasDir, atlasProperties, updateProcess);
    } catch(Exception e) {
      throw new Exception("Unable to upload atlas design document", e);
    }
   
    // Update mobile design document
    try {
      pushMobileDesign(gs, atlasDir, atlasProperties, updateProcess);
    } catch(Exception e) {
      throw new Exception("Unable to upload mobile design document", e);
    }
   
    // Update submission database with design document
    if( atlasProperties.isCouchDbSubmissionDbEnabled() ) {
      CouchDb submissionCouchDb = null;

      try {
        submissionCouchDb = CommandSupport.createCouchDbSubmission(gs, atlasProperties);
 
        DocumentUpdateProcess updateProcessForSubmissionDb =
            CommandUpdate.createDocumentUpdateProcess(gs, submissionCouchDb);
       
        pushSubmissionDesign(gs, atlasDir, atlasProperties, updateProcessForSubmissionDb);
      } catch(Exception e) {
        throw new Exception("Unable to upload submission design document", e);
      }

      // Fix member roles on submission database
      try {
        CouchDbSecurityDocument secDoc = submissionCouchDb.getSecurityDocument();
       
        boolean updateRequired = false;
       
        // Administrator role
        {
          String adminRole = atlasProperties.getAtlasName() + "_administrator";
          if( false == secDoc.getAdminRoles().contains(adminRole) ) {
            secDoc.addAdminRole(adminRole);
            updateRequired = true;
          }
        }
       
        // Vetter role
        {
          String vetterRole = atlasProperties.getAtlasName() + "_vetter";
          if( false == secDoc.getMemberRoles().contains(vetterRole) ) {
            secDoc.addMemberRole(vetterRole);
            updateRequired = true;
          }
        }
       
        if( updateRequired ){
          submissionCouchDb.setSecurityDocument(secDoc);
        }
      } catch(Exception e) {
        throw new ServletException("Error while adjusting member roles on submission database", e);
      }
    }
View Full Code Here

TOP

Related Classes of ca.carleton.gcrc.couch.client.CouchDb

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.