Search in sources :

Example 16 with Attribute

use of ddf.catalog.data.Attribute in project ddf by codice.

the class RegistryPublicationServiceImplTest method testUnpublish.

@Test
public void testUnpublish() throws Exception {
    String unPublishThisRegistryId = "unPublishThisRegistryId";
    Date now = new Date();
    Date before = new Date(now.getTime() - 100000);
    metacard.setAttribute(new AttributeImpl(RegistryObjectMetacardType.LAST_PUBLISHED, before));
    metacard.setAttribute(new AttributeImpl(RegistryObjectMetacardType.PUBLISHED_LOCATIONS, Collections.singletonList(REGISTRY_STORE_REGISTRY_ID)));
    when(federationAdminService.getRegistryMetacardsByRegistryIds(any(List.class))).thenReturn(Collections.singletonList(metacard));
    registryPublicationService.unpublish(unPublishThisRegistryId, REGISTRY_STORE_REGISTRY_ID);
    verify(federationAdminService).deleteRegistryEntriesByRegistryIds(Collections.singletonList(unPublishThisRegistryId), Collections.singleton(REGISTRY_STORE_ID));
    verify(federationAdminService).updateRegistryEntry(metacard);
    Attribute lastPublished = metacard.getAttribute(RegistryObjectMetacardType.LAST_PUBLISHED);
    assertThat(lastPublished, notNullValue());
    Date lastPublishedDate = (Date) lastPublished.getValue();
    assertThat(lastPublishedDate.after(before), is(equalTo(true)));
    Attribute publicationsAfter = metacard.getAttribute(RegistryObjectMetacardType.PUBLISHED_LOCATIONS);
    assertThat(publicationsAfter.getValue(), is("No_Publications"));
}
Also used : Attribute(ddf.catalog.data.Attribute) AttributeImpl(ddf.catalog.data.impl.AttributeImpl) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) List(java.util.List) Date(java.util.Date) Test(org.junit.Test)

Example 17 with Attribute

use of ddf.catalog.data.Attribute in project ddf by codice.

the class RegistryPolicyPlugin method getWritePolicy.

private PolicyResponse getWritePolicy(Metacard input, Map<String, Serializable> properties, Map<String, Set<String>> policy) {
    Map<String, Set<String>> operationPolicy = new HashMap<>();
    Map<String, Set<String>> securityAttributes = new HashMap<>();
    if (Requests.isLocal(properties) && input != null && (RegistryUtility.isInternalRegistryMetacard(input) || RegistryUtility.isRegistryMetacard(input))) {
        Attribute securityAttribute = input.getAttribute(RegistryObjectMetacardType.SECURITY_LEVEL);
        if (securityAttribute != null) {
            securityAttributes.putAll(Permissions.parsePermissionsFromString(securityAttribute.getValues().stream().map(Object::toString).collect(Collectors.toList())));
        }
        String registryBaseUrl = RegistryUtility.getStringAttribute(input, RegistryObjectMetacardType.REGISTRY_BASE_URL, null);
        if (isRegistryDisabled() || (registryBaseUrl != null && registryBaseUrl.startsWith(SystemBaseUrl.getBaseUrl()))) {
            operationPolicy.putAll(bypassAccessPolicy);
        } else {
            operationPolicy.putAll(policy);
        }
    }
    if (securityAttributes.isEmpty()) {
        return new PolicyResponseImpl(operationPolicy, operationPolicy);
    } else {
        return new PolicyResponseImpl(operationPolicy, securityAttributes);
    }
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) HashMap(java.util.HashMap) Attribute(ddf.catalog.data.Attribute) PolicyResponseImpl(ddf.catalog.plugin.impl.PolicyResponseImpl)

Example 18 with Attribute

use of ddf.catalog.data.Attribute in project ddf by codice.

the class RegistryPublicationServiceImplTest method testPublishAddAnotherSource.

@Test
public void testPublishAddAnotherSource() throws Exception {
    String someAlreadyPublishedRegistryId = "someAlreadyPublishedRegistryId";
    String publishThisRegistryId = "publishThisRegistryId";
    Date now = new Date();
    Date before = new Date(now.getTime() - 100000);
    Attribute publishedLocationsAttribute = new AttributeImpl(RegistryObjectMetacardType.PUBLISHED_LOCATIONS, Collections.singletonList(someAlreadyPublishedRegistryId));
    metacard.setAttribute(publishedLocationsAttribute);
    metacard.setAttribute(new AttributeImpl(RegistryObjectMetacardType.LAST_PUBLISHED, before));
    when(federationAdminService.getRegistryMetacardsByRegistryIds(any(List.class))).thenReturn(Collections.singletonList(metacard));
    registryPublicationService.publish(publishThisRegistryId, REGISTRY_STORE_REGISTRY_ID);
    verify(federationAdminService).addRegistryEntry(metacard, Collections.singleton(REGISTRY_STORE_ID));
    verify(federationAdminService).updateRegistryEntry(metacard);
    Attribute lastPublished = metacard.getAttribute(RegistryObjectMetacardType.LAST_PUBLISHED);
    assertThat(lastPublished, notNullValue());
    Date lastPublishedDate = (Date) lastPublished.getValue();
    assertThat(lastPublishedDate.after(before), is(equalTo(true)));
    Attribute publicationsAfter = metacard.getAttribute(RegistryObjectMetacardType.PUBLISHED_LOCATIONS);
    List<Serializable> publications = publicationsAfter.getValues();
    assertThat(publications, hasItem(REGISTRY_STORE_REGISTRY_ID));
}
Also used : Serializable(java.io.Serializable) Attribute(ddf.catalog.data.Attribute) AttributeImpl(ddf.catalog.data.impl.AttributeImpl) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) List(java.util.List) Date(java.util.Date) Test(org.junit.Test)

Example 19 with Attribute

use of ddf.catalog.data.Attribute in project ddf by codice.

the class RegistryPublicationServiceImplTest method testPublish.

@Test
public void testPublish() throws Exception {
    doReturn(Collections.singletonList(metacard)).when(federationAdminService).getRegistryMetacardsByRegistryIds(any(List.class));
    String publishThisRegistryId = "registryId";
    Date now = new Date();
    Date before = new Date(now.getTime() - 100000);
    metacard.setAttribute(new AttributeImpl(RegistryObjectMetacardType.LAST_PUBLISHED, before));
    registryPublicationService.publish(publishThisRegistryId, REGISTRY_STORE_REGISTRY_ID);
    verify(federationAdminService).addRegistryEntry(metacard, Collections.singleton(REGISTRY_STORE_ID));
    verify(federationAdminService).updateRegistryEntry(metacard);
    Attribute lastPublished = metacard.getAttribute(RegistryObjectMetacardType.LAST_PUBLISHED);
    assertThat(lastPublished, notNullValue());
    Date lastPublishedDate = (Date) lastPublished.getValue();
    assertThat(lastPublishedDate.after(before), is(equalTo(true)));
    Attribute publicationsAfter = metacard.getAttribute(RegistryObjectMetacardType.PUBLISHED_LOCATIONS);
    List<Serializable> publications = publicationsAfter.getValues();
    assertThat(publications, hasItem(REGISTRY_STORE_REGISTRY_ID));
}
Also used : Serializable(java.io.Serializable) Attribute(ddf.catalog.data.Attribute) AttributeImpl(ddf.catalog.data.impl.AttributeImpl) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) List(java.util.List) Date(java.util.Date) Test(org.junit.Test)

Example 20 with Attribute

use of ddf.catalog.data.Attribute in project ddf by codice.

the class Search method getResultItem.

private Map<String, Object> getResultItem(Result result) throws CatalogTransformerException {
    Map<String, Object> transformedResult = new HashMap<>();
    addObject(transformedResult, DISTANCE, result.getDistanceInMeters());
    addObject(transformedResult, RELEVANCE, result.getRelevanceScore());
    @SuppressWarnings("unchecked") Map<String, Object> metacard = (Map<String, Object>) GeoJsonMetacardTransformer.convertToJSON(result.getMetacard());
    metacard.put(ACTIONS, getActions(result.getMetacard()));
    Attribute cachedDate = result.getMetacard().getAttribute(CACHED);
    if (cachedDate != null && cachedDate.getValue() != null) {
        metacard.put(CACHED, ISO_8601_DATE_FORMAT.print(new DateTime(cachedDate.getValue())));
    } else {
        metacard.put(CACHED, ISO_8601_DATE_FORMAT.print(new DateTime()));
    }
    metacard.put(IS_RESOURCE_LOCAL, Optional.ofNullable(result.getMetacard().getAttribute(INTERNAL_LOCAL_RESOURCE)).map(Attribute::getValue).orElse(Boolean.FALSE));
    addObject(transformedResult, METACARD, metacard);
    return transformedResult;
}
Also used : HashMap(java.util.HashMap) Attribute(ddf.catalog.data.Attribute) HashMap(java.util.HashMap) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) DateTime(org.joda.time.DateTime)

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