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));
}
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 ? "}" : "");
}
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;
}
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;
}
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;
}
Aggregations