use of ddf.catalog.data.impl.AttributeImpl in project ddf by codice.
the class IdentificationPlugin method updateIdentifiers.
private void updateIdentifiers(Metacard metacard, boolean create) throws StopProcessingException {
boolean extOriginFound = false;
boolean extRegIdFound = false;
String metacardID = metacard.getId();
String registryID = RegistryUtility.getRegistryId(metacard);
String systemRegId = System.getProperty(RegistryConstants.REGISTRY_ID_PROPERTY);
try {
RegistryPackageType registryPackage = metacardMarshaller.getRegistryPackageFromMetacard(metacard);
List<ExternalIdentifierType> extIdList = new ArrayList<>();
//check if external ids are already present
if (registryPackage.isSetExternalIdentifier()) {
List<ExternalIdentifierType> currentExtIdList = registryPackage.getExternalIdentifier();
for (ExternalIdentifierType extId : currentExtIdList) {
extId.setRegistryObject(registryID);
if (extId.getId().equals(RegistryConstants.REGISTRY_MCARD_ID_LOCAL)) {
if (isInternal(metacard) && create) {
metacard.setAttribute(new AttributeImpl(RegistryObjectMetacardType.REMOTE_METACARD_ID, extId.getValue()));
}
extId.setValue(metacardID);
} else if (extId.getId().equals(RegistryConstants.REGISTRY_MCARD_ID_ORIGIN)) {
extOriginFound = true;
} else if (extId.getId().equals(RegistryConstants.REGISTRY_ID_ORIGIN)) {
if (!systemRegId.equals(extId.getValue()) && isInternal(metacard)) {
metacard.setAttribute(new AttributeImpl(RegistryObjectMetacardType.REMOTE_REGISTRY_ID, extId.getValue()));
}
extId.setValue(systemRegId);
extRegIdFound = true;
}
extIdList.add(extId);
}
if (!extOriginFound) {
extIdList.add(createExternalIdentifier(RegistryConstants.REGISTRY_MCARD_ID_ORIGIN, registryID, RegistryConstants.REGISTRY_METACARD_ID_CLASS, metacardID));
}
if (!extRegIdFound) {
extIdList.add(createExternalIdentifier(RegistryConstants.REGISTRY_ID_ORIGIN, registryID, RegistryConstants.REGISTRY_ID_CLASS, systemRegId));
}
} else {
extIdList.add(createExternalIdentifier(RegistryConstants.REGISTRY_MCARD_ID_LOCAL, registryID, RegistryConstants.REGISTRY_METACARD_ID_CLASS, metacardID));
extIdList.add(createExternalIdentifier(RegistryConstants.REGISTRY_MCARD_ID_ORIGIN, registryID, RegistryConstants.REGISTRY_METACARD_ID_CLASS, metacardID));
extIdList.add(createExternalIdentifier(RegistryConstants.REGISTRY_ID_ORIGIN, registryID, RegistryConstants.REGISTRY_ID_CLASS, systemRegId));
}
registryPackage.setExternalIdentifier(extIdList);
metacardMarshaller.setMetacardRegistryPackage(metacard, registryPackage);
} catch (ParserException e) {
throw new StopProcessingException("Unable to access Registry Metadata. Parser exception caught");
}
}
use of ddf.catalog.data.impl.AttributeImpl 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.impl.AttributeImpl in project ddf by codice.
the class RefreshRegistryEntriesTest method getPopulatedTestRegistryMetacard.
private MetacardImpl getPopulatedTestRegistryMetacard(String id, String regId, long dateOffset, boolean internal, String remoteMcardId) {
MetacardImpl registryMetacard = new MetacardImpl(new RegistryObjectMetacardType());
registryMetacard.setAttribute(new AttributeImpl(RegistryObjectMetacardType.REGISTRY_ID, regId));
registryMetacard.setAttribute(new AttributeImpl(Metacard.MODIFIED, new Date(new Date().getTime() + dateOffset)));
if (internal) {
registryMetacard.setAttribute(new AttributeImpl(RegistryObjectMetacardType.REMOTE_METACARD_ID, remoteMcardId));
registryMetacard.setAttribute(new AttributeImpl(RegistryObjectMetacardType.REMOTE_REGISTRY_ID, "remoteRegId"));
registryMetacard.setAttribute(new AttributeImpl(Metacard.TAGS, Collections.singletonList(RegistryConstants.REGISTRY_TAG_INTERNAL)));
} else {
registryMetacard.setAttribute(new AttributeImpl(Metacard.TAGS, Collections.singletonList(RegistryConstants.REGISTRY_TAG)));
}
registryMetacard.setAttribute(new AttributeImpl(Metacard.ID, id));
registryMetacard.setAttribute(new AttributeImpl(Metacard.METADATA, TEST_XML_STRING));
return registryMetacard;
}
use of ddf.catalog.data.impl.AttributeImpl 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.impl.AttributeImpl 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));
}
Aggregations