Package ca.carleton.gcrc.couch.client

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


  @Override
  public CouchUserContext getUserFromName(String userName) throws Exception {
    try{
      JSONObject userDoc = getDocument("org.couchdb.user:"+userName);
     
      CouchUserContext userCtx = CouchUtils.userContextFromDocument(userDoc);
     
      return userCtx;
     
    } catch(Exception e) {
      throw new Exception("Error obtaining document for user: "+userName);
View Full Code Here


      }
    } catch(Exception e) {
      throw new Exception("Error parsing session context response",e);
    }
   
    CouchUserContext userCtx = new CouchUserContext();
    userCtx.setName(name);
    userCtx.setRoles(roles);
   
    return userCtx;
  }
View Full Code Here

      }
    } catch(Exception e) {
      throw new Exception("Error parsing user document",e);
    }
   
    CouchUserContext userCtx = new CouchUserContext();
    userCtx.setName(name);
    userCtx.setRoles(roles);
   
    return userCtx;
  }
View Full Code Here

      }
    }
   
    // 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
View Full Code Here

  public void setSubmitterName(String originalName) throws Exception {
    setStringAttribute(UploadConstants.SUBMITTER_KEY,originalName);
  }
 
  public CouchUserContext getSubmitter() throws Exception {
    CouchUserContext submitter = null;
   
    String submitterName = getSubmitterName();
    if( null != submitterName ) {
      try {
        CouchUserDb userDb = context.getClient().getUserDatabase();
View Full Code Here

        throw new Exception("Analysis required but original object is not present");
      }
      OriginalFileDescriptor originalObj = attDescription.getOriginalFileDescription();
     
      // Verify if a submitter is specified
      CouchUserContext submitter = attDescription.getSubmitter();

      boolean pluginFound = false;
      String fileClass = attDescription.getFileClass();
      for(FileConversionPlugin fcp : this.fileConverters) {
        if( fcp.handlesFileClass(fileClass, FileConversionPlugin.WORK_ANALYZE) ) {
View Full Code Here

  }

  public void analyzeFile(FileConversionContext conversionContext) throws Exception {
    AttachmentDescriptor attDescription = conversionContext.getAttachmentDescription();
    OriginalFileDescriptor originalObj = attDescription.getOriginalFileDescription();
    CouchUserContext submitter = attDescription.getSubmitter();
   
    // Figure out media file located on disk
    File originalFile = originalObj.getMediaFile();
    String mimeType = originalObj.getContentType();
View Full Code Here

  @Override
  public CouchUserContext getUserFromName(String userName) throws Exception {
    try{
      JSONObject userDoc = getDocument("org.couchdb.user:"+userName);
     
      CouchUserContext userCtx = CouchUtils.userContextFromDocument(userDoc);
     
      return userCtx;
     
    } catch(Exception e) {
      throw new Exception("Error obtaining document for user: "+userName);
View Full Code Here

      }
    } catch(Exception e) {
      throw new Exception("Error parsing session context response",e);
    }
   
    CouchUserContext userCtx = new CouchUserContext();
    userCtx.setName(name);
    userCtx.setRoles(roles);
   
    return userCtx;
  }
View Full Code Here

      }
    } catch(Exception e) {
      throw new Exception("Error parsing user document",e);
    }
   
    CouchUserContext userCtx = new CouchUserContext();
    userCtx.setName(name);
    userCtx.setRoles(roles);
   
    return userCtx;
  }
View Full Code Here

TOP

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

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.