Search in sources :

Example 11 with Attribute

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();
}
Also used : Metacard(ddf.catalog.data.Metacard) Attribute(ddf.catalog.data.Attribute) AttributeDescriptor(ddf.catalog.data.AttributeDescriptor) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

Example 12 with Attribute

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();
}
Also used : Metacard(ddf.catalog.data.Metacard) Serializable(java.io.Serializable) Attribute(ddf.catalog.data.Attribute) AttributeImpl(ddf.catalog.data.impl.AttributeImpl) UpdateRequestImpl(ddf.catalog.operation.impl.UpdateRequestImpl) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE)

Example 13 with Attribute

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"));
}
Also used : Metacard(ddf.catalog.data.Metacard) Attribute(ddf.catalog.data.Attribute) QueryResponse(ddf.catalog.operation.QueryResponse) ArrayList(java.util.ArrayList) ResultImpl(ddf.catalog.data.impl.ResultImpl) ResourceCacheInterface(ddf.catalog.cache.ResourceCacheInterface) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) Result(ddf.catalog.data.Result) Test(org.junit.Test)

Example 14 with Attribute

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));
}
Also used : Attribute(ddf.catalog.data.Attribute) Test(org.junit.Test)

Example 15 with Attribute

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));
}
Also used : Attribute(ddf.catalog.data.Attribute) Test(org.junit.Test)

Aggregations

Attribute (ddf.catalog.data.Attribute)103 Metacard (ddf.catalog.data.Metacard)39 Test (org.junit.Test)37 ArrayList (java.util.ArrayList)30 AttributeImpl (ddf.catalog.data.impl.AttributeImpl)29 AttributeDescriptor (ddf.catalog.data.AttributeDescriptor)26 Serializable (java.io.Serializable)23 MetacardImpl (ddf.catalog.data.impl.MetacardImpl)15 HashMap (java.util.HashMap)15 Result (ddf.catalog.data.Result)14 List (java.util.List)14 MetacardType (ddf.catalog.data.MetacardType)11 QueryResponse (ddf.catalog.operation.QueryResponse)11 Date (java.util.Date)11 Map (java.util.Map)11 HashSet (java.util.HashSet)10 Optional (java.util.Optional)8 Set (java.util.Set)8 Filter (org.opengis.filter.Filter)8 UpdateRequestImpl (ddf.catalog.operation.impl.UpdateRequestImpl)7