Package ca.carleton.gcrc.couch.client

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


  }

  private void initUser(ServletContext servletContext) throws ServletException {
   
    try {
      CouchDb userDb = couchClient.getDatabase("_users");
      servletContext.setAttribute(UserServlet.ConfigAttributeName_UserDb, userDb);
      servletContext.setAttribute(UserServlet.ConfigAttributeName_AtlasName, atlasName);
    } catch(Exception e) {
      logger.error("Error configuring user service",e);
      throw new ServletException("Error configuring user service",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 DocumentUpdateProcess createDocumentUpdateProcess(
    GlobalSettings gs
    ,AtlasProperties atlasProperties
    ) throws Exception {
   
    CouchDb couchDb = CommandSupport.createCouchDb(gs, atlasProperties);
   
    DocumentUpdateProcess updateProcess = new DocumentUpdateProcess(couchDb);
    DocumentUpdateListener l = new UpdateProgress(gs);
    updateProcess.setListener(l);
   
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

  }

  private void initUserDesignDocument(ServletContext servletContext) throws ServletException {
    // Update document
    try {
      CouchDb userDb = couchClient.getDatabase("_users");
      UserDesignDocumentImpl.updateDesignDocument(userDb);
    } catch(Exception e) {
      throw new ServletException("Error while updating user design document",e);
    }
  }
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

  }

  private void initUser(ServletContext servletContext) throws ServletException {
   
    try {
      CouchDb userDb = couchClient.getDatabase("_users");
      servletContext.setAttribute(UserServlet.ConfigAttributeName_UserDb, userDb);
      servletContext.setAttribute(UserServlet.ConfigAttributeName_AtlasName, atlasName);
    } catch(Exception e) {
      logger.error("Error configuring user service",e);
      throw new ServletException("Error configuring user service",e);
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

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.