Search in sources :

Example 1 with RestModelMetadata

use of org.glassfish.admin.rest.composite.metadata.RestModelMetadata in project Payara by payara.

the class RestCollection method put.

public void put(String id, T model) {
    models.add(model);
    metadata.add(new RestModelMetadata(id));
}
Also used : RestModelMetadata(org.glassfish.admin.rest.composite.metadata.RestModelMetadata)

Example 2 with RestModelMetadata

use of org.glassfish.admin.rest.composite.metadata.RestModelMetadata in project Payara by payara.

the class RestCollectionProvider method getContent.

/**
 * Converts a {@link RestCollection} into a Json object and then returns it as as String representation.
 * @param proxy
 * @return
 */
@Override
public String getContent(RestCollection proxy) {
    StringBuilder sb = new StringBuilder();
    final List<String> wrapObjectHeader = requestHeaders.get().getRequestHeader("X-Wrap-Object");
    final List<String> skipMetadataHeader = requestHeaders.get().getRequestHeader("X-Skip-Metadata");
    boolean wrapObject = ((wrapObjectHeader != null) && (wrapObjectHeader.size() > 0));
    boolean skipMetadata = ((skipMetadataHeader != null) && (skipMetadataHeader.get(0).equalsIgnoreCase("true")));
    JsonArrayBuilder models = Json.createArrayBuilder();
    JsonArrayBuilder metadata = Json.createArrayBuilder();
    for (Map.Entry<RestModelMetadata, RestModel> entry : (Set<Map.Entry<RestModelMetadata, RestModel>>) proxy.entrySet()) {
        try {
            models.add(JsonUtil.getJsonValue(entry.getValue()));
            RestModelMetadata md = entry.getKey();
            JsonObjectBuilder mdo = Json.createObjectBuilder();
            mdo.add("id", md.getId());
            metadata.add(mdo.build());
        } catch (JsonException e) {
            Logger.getLogger(RestCollectionProvider.class.getName()).log(Level.SEVERE, "Unable to parse create Json", e);
        }
    }
    JsonObjectBuilder response = Json.createObjectBuilder();
    try {
        response.add("items", models.build());
        if (!skipMetadata) {
            response.add("metadata", metadata.build());
        }
        sb.append(response.toString());
    } catch (JsonException e) {
        Logger.getLogger(RestCollectionProvider.class.getName()).log(Level.SEVERE, "Unable to parse create Json", e);
    }
    return (wrapObject ? " { items : " : "") + sb.toString() + (wrapObject ? "}" : "");
}
Also used : JsonException(javax.json.JsonException) Set(java.util.Set) RestModel(org.glassfish.admin.rest.composite.RestModel) RestModelMetadata(org.glassfish.admin.rest.composite.metadata.RestModelMetadata) JsonArrayBuilder(javax.json.JsonArrayBuilder) JsonObjectBuilder(javax.json.JsonObjectBuilder) Map(java.util.Map)

Example 3 with RestModelMetadata

use of org.glassfish.admin.rest.composite.metadata.RestModelMetadata in project Payara by payara.

the class RestCollection method get.

public T get(Object key) {
    checkClass(RestModelMetadata.class, key.getClass());
    RestModelMetadata desired = (RestModelMetadata) key;
    T result = null;
    for (int index = 0, total = metadata.size(); index < total; index++) {
        if (metadata.get(index).equals(desired)) {
            result = models.get(index);
            break;
        }
    }
    return result;
}
Also used : RestModelMetadata(org.glassfish.admin.rest.composite.metadata.RestModelMetadata)

Example 4 with RestModelMetadata

use of org.glassfish.admin.rest.composite.metadata.RestModelMetadata in project Payara by payara.

the class RestCollection method remove.

public T remove(Object key) {
    checkClass(RestModelMetadata.class, key.getClass());
    RestModelMetadata desired = (RestModelMetadata) key;
    T result = null;
    for (int index = 0, total = metadata.size(); index < total; index++) {
        if (metadata.get(index).equals(desired)) {
            result = models.get(index);
            models.remove(index);
            metadata.remove(index);
            break;
        }
    }
    return result;
}
Also used : RestModelMetadata(org.glassfish.admin.rest.composite.metadata.RestModelMetadata)

Example 5 with RestModelMetadata

use of org.glassfish.admin.rest.composite.metadata.RestModelMetadata in project Payara by payara.

the class RestCollection method containsKey.

public boolean containsKey(Object key) {
    checkClass(RestModelMetadata.class, key.getClass());
    RestModelMetadata desired = (RestModelMetadata) key;
    boolean found = false;
    for (RestModelMetadata md : metadata) {
        if (md.equals(desired)) {
            found = true;
            break;
        }
    }
    return found;
}
Also used : RestModelMetadata(org.glassfish.admin.rest.composite.metadata.RestModelMetadata)

Aggregations

RestModelMetadata (org.glassfish.admin.rest.composite.metadata.RestModelMetadata)5 Map (java.util.Map)1 Set (java.util.Set)1 JsonArrayBuilder (javax.json.JsonArrayBuilder)1 JsonException (javax.json.JsonException)1 JsonObjectBuilder (javax.json.JsonObjectBuilder)1 RestModel (org.glassfish.admin.rest.composite.RestModel)1