agave-metadata/metadata-api/src/main/java/org/iplantc/service/metadata/resources/MetadataCollection.java
/**
     * This method represents the HTTP GET action. The input files for the authenticated user are
     * retrieved from the database and sent to the user as a {@link JSONArray JSONArray}
     * of {@link JSONObject JSONObject}.
     */
This method represents the HTTP GET action. The input files for the authenticated user are
retrieved from the database and sent to the user as a  JSONArray JSONArray
of  JSONObject JSONObject.
This method represents the HTTP GET action . The input files for the authenticated user are retrieved from the database and sent to the user as a JSONArray JSONArray of JSONObject JSONObject .
@Override
    public Representation represent(Variant variant) throws ResourceException {
        List<String> str_permittedResults = new ArrayList<>();
        log.log(Level.DEBUG, "Starting GET request");
        System.setProperty("DEBUG.MONGO", "true");
        System.setProperty("DB.TRACE", "true");
        Logger mongoLog = Logger.getLogger("org.mongodb.driver.protocol.query");
        try {
            MetadataSearch search = new MetadataSearch(this.username);
            if (includeRecordsWithImplicitPermissions)
                search.setAccessibleOwnersImplicit();
            else
                search.setAccessibleOwnersExplicit();
            try {
                List<String> sortableFields = Arrays.asList("uuid",
                        "tenantId",
                        "schemaId",
                        "internalUsername",
                        "lastUpdated",
                        "name",
                        "value",
                        "created",
                        "owner");
                String orderField = getOrderBy("lastUpdated");
                if (StringUtils.isBlank(orderField) || !sortableFields.contains(orderField)) {
                    throw new SortSyntaxException("Invalid order field. Please specify one of " +
                            StringUtils.join(sortableFields, ","), new MetadataException("Invalid sort field"));
                }
                int orderDirection = getOrder(AgaveResourceResultOrdering.DESC).isAscending() ? 1 : -1;
                search.setOrderField(orderField);
                search.setOrderDirection(orderDirection);
                search.setLimit(limit);
                search.setOffset(offset);
                Document docUserQuery;
                try {
                    JsonHandler jsonHandler = new JsonHandler();
                    docUserQuery = jsonHandler.parseUserQueryToDocument(userQuery);
                } catch (MetadataQueryException e) {
                    throw new MetadataQueryException(e.getMessage());
                }
                if (hasJsonPathFilters()) {
                    try {
                        List<Document> userResults = search.filterFind(docUserQuery, jsonPathFilters);
                        for (Document metadataDoc : userResults) {
                            str_permittedResults.add(metadataDoc.toJson());
                        }
                    } catch (Exception e) {
                        throw new ResourceException(Status.SERVER_ERROR_INTERNAL,
                                "Unable to find matching items based on filters: ", e);
                    }
                } else {
                    List<MetadataItem> userResults = new ArrayList<>();
                    try {
                        userResults = search.find(docUserQuery);
                    } catch (Exception e) {
                        throw new ResourceException(Status.SERVER_ERROR_INTERNAL,
                                "Unable to find matching items ", e);
                    }
                    try {
                        MetadataItemSerializer metadataItemSerializer = new MetadataItemSerializer();
                        for (MetadataItem metadataItem : userResults) {
                            str_permittedResults.add(metadataItemSerializer.formatMetadataItemJsonResult(metadataItem).toString());
                        }
                    } catch (Exception e) {
                        throw new ResourceException(Status.SERVER_ERROR_INTERNAL,
                                "Unable to serialize response", e);
                    }
                }
            } catch (MetadataQueryException e) {
                throw new ResourceException(Status.CLIENT_ERROR_BAD_REQUEST, "Malformed JSON Query, " + e);
            }
            return new IplantSuccessRepresentation(str_permittedResults.toString());
        } catch (SortSyntaxException e) {
            throw new ResourceException(Status.CLIENT_ERROR_BAD_REQUEST, e.getMessage(), e);
        } catch (ResourceException e) {
            throw e;
        } catch (Throwable e) {
            throw new ResourceException(org.restlet.data.Status.SERVER_ERROR_INTERNAL,
                    "An error occurred while fetching the metadata item. " +
                            "If this problem persists, " +
                            "please contact the system administrators. ", e);
        }
    }
@ Override public Representation represent ( Variant variant ) throws ResourceException { List < String > str_permittedResults = new ArrayList < > ( ) ; log . log ( Level . DEBUG , "Starting GET request" ) ; System . setProperty ( "DEBUG.MONGO" , "true" ) ; System . setProperty ( "DB.TRACE" , "true" ) ; Logger mongoLog = Logger . getLogger ( "org.mongodb.driver.protocol.query" ) ; try { MetadataSearch search = new MetadataSearch ( this . username ) ; if ( includeRecordsWithImplicitPermissions ) search . setAccessibleOwnersImplicit ( ) ; else search . setAccessibleOwnersExplicit ( ) ; try { List < String > sortableFields = Arrays . asList ( "uuid" , "tenantId" , "schemaId" , "internalUsername" , "lastUpdated" , "name" , "value" , "created" , "owner" ) ; String orderField = getOrderBy ( "lastUpdated" ) ; if ( StringUtils . isBlank ( orderField ) || ! sortableFields . contains ( orderField ) ) { throw new SortSyntaxException ( "Invalid order field. Please specify one of " + StringUtils . join ( sortableFields , "," ) , new MetadataException ( "Invalid sort field" ) ) ; } int orderDirection = getOrder ( AgaveResourceResultOrdering . DESC ) . isAscending ( ) ? 1 : - 1 ; search . setOrderField ( orderField ) ; search . setOrderDirection ( orderDirection ) ; search . setLimit ( limit ) ; search . setOffset ( offset ) ; Document docUserQuery ; try { JsonHandler jsonHandler = new JsonHandler ( ) ; docUserQuery = jsonHandler . parseUserQueryToDocument ( userQuery ) ; } catch ( MetadataQueryException e ) { throw new MetadataQueryException ( e . getMessage ( ) ) ; } if ( hasJsonPathFilters ( ) ) { try { List < Document > userResults = search . filterFind ( docUserQuery , jsonPathFilters ) ; for ( Document metadataDoc : userResults ) { str_permittedResults . add ( metadataDoc . toJson ( ) ) ; } } catch ( Exception e ) { throw new ResourceException ( Status . SERVER_ERROR_INTERNAL , "Unable to find matching items based on filters: " , e ) ; } } else { List < MetadataItem > userResults = new ArrayList < > ( ) ; try { userResults = search . find ( docUserQuery ) ; } catch ( Exception e ) { throw new ResourceException ( Status . SERVER_ERROR_INTERNAL , "Unable to find matching items " , e ) ; } try { MetadataItemSerializer metadataItemSerializer = new MetadataItemSerializer ( ) ; for ( MetadataItem metadataItem : userResults ) { str_permittedResults . add ( metadataItemSerializer . formatMetadataItemJsonResult ( metadataItem ) . toString ( ) ) ; } } catch ( Exception e ) { throw new ResourceException ( Status . SERVER_ERROR_INTERNAL , "Unable to serialize response" , e ) ; } } } catch ( MetadataQueryException e ) { throw new ResourceException ( Status . CLIENT_ERROR_BAD_REQUEST , "Malformed JSON Query, " + e ) ; } return new IplantSuccessRepresentation ( str_permittedResults . toString ( ) ) ; } catch ( SortSyntaxException e ) { throw new ResourceException ( Status . CLIENT_ERROR_BAD_REQUEST , e . getMessage ( ) , e ) ; } catch ( ResourceException e ) { throw e ; } catch ( Throwable e ) { throw new ResourceException ( org . restlet . data . Status . SERVER_ERROR_INTERNAL , "An error occurred while fetching the metadata item. " + "If this problem persists, " + "please contact the system administrators. " , e ) ; } }
This method represents the HTTP GET action.
This method represents the HTTP GET action .