use of ddf.catalog.data.Attribute in project ddf by codice.
the class MetacardEditEndpoint method getAttribute.
@GET
@Path("/{id}/{attribute}")
public Response getAttribute(@Context HttpServletResponse response, @PathParam("id") String id, @PathParam("attribute") String attribute) throws Exception {
Metacard metacard = endpointUtil.getMetacard(id);
Attribute metacardAttribute = metacard.getAttribute(attribute);
if (metacardAttribute == null) {
return Response.status(200).build();
}
Optional<AttributeDescriptor> attributeDescriptor = attributeRegistry.lookup(attribute);
if (!attributeDescriptor.isPresent()) {
/* Could not find attribute descriptor for requested attribute */
return Response.status(404).build();
}
AttributeDescriptor descriptor = attributeDescriptor.get();
/* Yes i'm using a raw map. get off my back yo */
Map<String, Object> result = getResponseMap(attribute, metacardAttribute, descriptor);
return Response.ok(endpointUtil.getJson(result), MediaType.APPLICATION_JSON).build();
}
use of ddf.catalog.data.Attribute in project ddf by codice.
the class MetacardEditEndpoint method deleteAttribute.
@DELETE
@Path("/{id}/{attribute}")
public Response deleteAttribute(@Context HttpServletResponse response, @PathParam("id") String id, @PathParam("attribute") String attribute, String value) throws Exception {
Metacard metacard = endpointUtil.getMetacard(id);
Attribute metacardAttribute = metacard.getAttribute(attribute);
if (metacardAttribute == null) {
return Response.ok().build();
}
metacard.setAttribute(new AttributeImpl(attribute, (Serializable) null));
catalogFramework.update(new UpdateRequestImpl(id, metacard));
return Response.ok().build();
}
use of ddf.catalog.data.Attribute in project ddf by codice.
the class TestMetacardResourceSizePlugin method testWhenNoCachedResourceFound.
@Test
public void testWhenNoCachedResourceFound() throws Exception {
ResourceCacheInterface cache = mock(ResourceCacheInterface.class);
when(cache.getValid(anyString(), (Metacard) anyObject())).thenReturn(null);
MetacardImpl metacard = new MetacardImpl();
metacard.setId("abc123");
metacard.setSourceId("ddf-1");
metacard.setResourceSize("N/A");
Result result = new ResultImpl(metacard);
List<Result> results = new ArrayList<Result>();
results.add(result);
QueryResponse input = mock(QueryResponse.class);
when(input.getResults()).thenReturn(results);
MetacardResourceSizePlugin plugin = new MetacardResourceSizePlugin(cache);
QueryResponse queryResponse = plugin.process(input);
assertThat(queryResponse.getResults().size(), is(1));
Metacard resultMetacard = queryResponse.getResults().get(0).getMetacard();
assertThat(metacard, is(notNullValue()));
// Since using Metacard vs. MetacardImpl have to get resource-size as an
// Attribute vs. Long
Attribute resourceSizeAttr = resultMetacard.getAttribute(Metacard.RESOURCE_SIZE);
assertThat((String) resourceSizeAttr.getValue(), equalTo("N/A"));
}
use of ddf.catalog.data.Attribute in project ddf by codice.
the class MetacardResourceStatusTest method testMetacardResourceIsNotLocal4.
/**
* Metacard source id is remote, Metacard contains remote resource uri, Metacard resource is not
* cached
*/
@Test
public void testMetacardResourceIsNotLocal4() throws Exception {
setupCache(false);
setupSingleResultResponseMock(getBasicMetacard(REMOTE_SITE_NAME, REMOTE_RESOURCE_URI));
MetacardResourceStatus plugin = getMetacardResourceStatusPlugin();
Attribute resourceStatusAttribute = getInternalLocalResurceAttribute(plugin.process(queryResponse));
assertThat(resourceStatusAttribute.getValue(), is(false));
}
use of ddf.catalog.data.Attribute in project ddf by codice.
the class MetacardResourceStatusTest method testMetacardResourceIsNotLocal3.
/**
* Metacard source id is remote, Metacard contains content resource uri, Metacard resource is not
* cached
*/
@Test
public void testMetacardResourceIsNotLocal3() throws Exception {
setupCache(false);
setupSingleResultResponseMock(getBasicMetacard(REMOTE_SITE_NAME, CONTENT_RESOURCE_URI));
MetacardResourceStatus plugin = getMetacardResourceStatusPlugin();
Attribute resourceStatusAttribute = getInternalLocalResurceAttribute(plugin.process(queryResponse));
assertThat(resourceStatusAttribute.getValue(), is(false));
}
Aggregations