Package ca.carleton.gcrc.couch.client

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


    }
   
    // Load properties for atlas
    AtlasProperties atlasProperties = AtlasProperties.fromAtlasDir(atlasDir);
   
    CouchDb couchDb = CommandSupport.createCouchDb(gs, atlasProperties);
   
    if( selectSkeletonDocuments ){
      SkeletonDocumentsDetector docFinder = new SkeletonDocumentsDetector(couchDb,gs);
      docIds.addAll( docFinder.getSkeletonDocIds() );
    }
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

  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

  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

  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

         <value> a value provided by the submitter
     */
   
    try {
      // Get CouchDb instance on behalf of the user
      CouchDb userCouchDb = getUserCouchDbFromCookies(cookies);
      CouchUserContext 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

        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( fileDic.containsKey(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( fileDic.containsKey(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

    return elements;
  }

  @Override
  public boolean treeExists() throws Exception {
    CouchDb db = atlasDesign.getDatabase();
    boolean exists = false;
   
    try {
      exists = db.documentExists(DATE_CLUSTER_DOC_ID);
     
    } catch (Exception e) {
      // Ignore for now
      throw new Exception("Unable to verify cluster document existence", e);
    }
View Full Code Here

    return exists;
  }

  @Override
  public Tree loadTree() throws Exception {
    CouchDb db = atlasDesign.getDatabase();
    JSONObject jsonDoc = null;
    try {
      jsonDoc = db.getDocument(DATE_CLUSTER_DOC_ID);
    } catch (Exception e) {
      // Ignore for now
      throw new Exception("Unable to retrieve date cluster information", e);
    }
   
View Full Code Here

  }

  @Override
  public void saveTree(Tree tree) throws Exception {
   
    CouchDb db = atlasDesign.getDatabase();

    boolean exists = db.documentExists(DATE_CLUSTER_DOC_ID);
   
    JSONObject jsonDoc = null;
    if( exists ) {
      jsonDoc = db.getDocument(DATE_CLUSTER_DOC_ID);
    } else {
      jsonDoc = new JSONObject();
      jsonDoc.put("_id", "org.nunaliit.date_clusters");
    }

    jsonDoc.put("nunaliit_date_clusters", tree.toJSON());
    CouchAuthenticationContext authContext = db.getClient().getSession().getAuthenticationContext();
    CouchNunaliitUtils.adjustDocumentForStorage(jsonDoc, authContext);
    if( exists ){
      db.updateDocument(jsonDoc);
    } else {
      db.createDocument(jsonDoc);
    }
  }
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.