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