agave-metadata/metadata-api/src/main/java/org/iplantc/service/metadata/resources/MetadataSchemaResource.java
/**
     * This method represents the HTTP GET action. The schema is
     * retrieved from the database and sent to the user as a {@link MetadataSchemaItem}
     *
     */
This method represents the HTTP GET action. The schema is
retrieved from the database and sent to the user as a  MetadataSchemaItem
This method represents the HTTP GET action . The schema is retrieved from the database and sent to the user as a MetadataSchemaItem
@Override
    public Representation represent(Variant variant) throws ResourceException
    {
        DBCursor cursor = null;
        MetadataSchemaPermissionManager pm;
        try 
        {
        	if (collection == null) {
                throw new ResourceException(Status.SERVER_ERROR_INTERNAL, 
                		"Unable to connect to metadata store. If this problem persists, "
                		+ "please contact the system administrators.");
            }
	        BasicDBObject query;
            if (StringUtils.isEmpty(uuid))
            {
            	throw new ResourceException(Status.CLIENT_ERROR_NOT_FOUND, 
            			"Please provide a metadata schemata uuid", 
            			new NullPointerException("Metadata Schemata UUID cannot be null"));
            } 
            else {
            	AgaveLogServiceClient.log(METADATA02.name(), SchemaGetById.name(), username, "", getRequest().getClientInfo().getUpstreamAddress());
            	query = new BasicDBObject("uuid", uuid);
            	query.append("tenantId", TenancyHelper.getCurrentTenantId());
            }
	        cursor = collection.find(query, new BasicDBObject("_id", false));
            if (cursor.hasNext())  {
            	DBObject firstResult, formattedResult;
            	firstResult = cursor.next();
				pm = new MetadataSchemaPermissionManager((String)firstResult.get("uuid"), (String)firstResult.get("owner"));
        		if (pm.canRead(username)) {
                	formattedResult = formatMetadataSchemaObject(firstResult);
	        	    return new IplantSuccessRepresentation(ServiceUtils.unescapeSchemaRefFieldNames(formattedResult.toString()));
                }
                else {
                	throw new ResourceException(Status.CLIENT_ERROR_FORBIDDEN,
            			"User does not have permission to read metadata for uuid");
                }
            }
            else {
            	throw new ResourceException(Status.CLIENT_ERROR_NOT_FOUND,
                        "No metadata schema item found for user with id " + uuid);
            }
        } 
        catch (ResourceException e) {
        	log.error("Failed to fetch metadata schema " + uuid + ". " + e.getMessage());
        	throw e;
        } 
        catch (Throwable e) {
        	log.error("Failed to fetch metadata schema " + uuid, e);
        	throw new ResourceException(Status.SERVER_ERROR_INTERNAL, 
        			"Failed to retrieve metadata schema information.", e);
        }
	    finally {
	    	try {
				assert cursor != null;
				cursor.close();
	    	} catch (Exception ignore) {}
	    }
    }
@ Override public Representation represent ( Variant variant ) throws ResourceException { DBCursor cursor = null ; MetadataSchemaPermissionManager pm ; try { if ( collection == null ) { throw new ResourceException ( Status . SERVER_ERROR_INTERNAL , "Unable to connect to metadata store. If this problem persists, " + "please contact the system administrators." ) ; } BasicDBObject query ; if ( StringUtils . isEmpty ( uuid ) ) { throw new ResourceException ( Status . CLIENT_ERROR_NOT_FOUND , "Please provide a metadata schemata uuid" , new NullPointerException ( "Metadata Schemata UUID cannot be null" ) ) ; } else { AgaveLogServiceClient . log ( METADATA02 . name ( ) , SchemaGetById . name ( ) , username , "" , getRequest ( ) . getClientInfo ( ) . getUpstreamAddress ( ) ) ; query = new BasicDBObject ( "uuid" , uuid ) ; query . append ( "tenantId" , TenancyHelper . getCurrentTenantId ( ) ) ; } cursor = collection . find ( query , new BasicDBObject ( "_id" , false ) ) ; if ( cursor . hasNext ( ) ) { DBObject firstResult , formattedResult ; firstResult = cursor . next ( ) ; pm = new MetadataSchemaPermissionManager ( ( String ) firstResult . get ( "uuid" ) , ( String ) firstResult . get ( "owner" ) ) ; if ( pm . canRead ( username ) ) { formattedResult = formatMetadataSchemaObject ( firstResult ) ; return new IplantSuccessRepresentation ( ServiceUtils . unescapeSchemaRefFieldNames ( formattedResult . toString ( ) ) ) ; } else { throw new ResourceException ( Status . CLIENT_ERROR_FORBIDDEN , "User does not have permission to read metadata for uuid" ) ; } } else { throw new ResourceException ( Status . CLIENT_ERROR_NOT_FOUND , "No metadata schema item found for user with id " + uuid ) ; } } catch ( ResourceException e ) { log . error ( "Failed to fetch metadata schema " + uuid + ". " + e . getMessage ( ) ) ; throw e ; } catch ( Throwable e ) { log . error ( "Failed to fetch metadata schema " + uuid , e ) ; throw new ResourceException ( Status . SERVER_ERROR_INTERNAL , "Failed to retrieve metadata schema information." , e ) ; } finally { try { assert cursor != null ; cursor . close ( ) ; } catch ( Exception ignore ) { } } }
This method represents the HTTP GET action.
This method represents the HTTP GET action .
// Include user defined query clauses given within the URL as q=<clauses> // do we not want to support general collection queries?  // How would one browse all their metadata? // does that even make sense?