Search in sources :

Example 46 with AttributeImpl

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");
    }
}
Also used : ParserException(org.codice.ddf.parser.ParserException) RegistryPackageType(oasis.names.tc.ebxml_regrep.xsd.rim._3.RegistryPackageType) AttributeImpl(ddf.catalog.data.impl.AttributeImpl) ArrayList(java.util.ArrayList) ExternalIdentifierType(oasis.names.tc.ebxml_regrep.xsd.rim._3.ExternalIdentifierType) StopProcessingException(ddf.catalog.plugin.StopProcessingException)

Example 47 with AttributeImpl

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"));
}
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 48 with AttributeImpl

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;
}
Also used : AttributeImpl(ddf.catalog.data.impl.AttributeImpl) RegistryObjectMetacardType(org.codice.ddf.registry.common.metacard.RegistryObjectMetacardType) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) Date(java.util.Date)

Example 49 with AttributeImpl

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));
}
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 50 with AttributeImpl

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

Aggregations

AttributeImpl (ddf.catalog.data.impl.AttributeImpl)181 Metacard (ddf.catalog.data.Metacard)109 Test (org.junit.Test)75 ArrayList (java.util.ArrayList)56 MetacardImpl (ddf.catalog.data.impl.MetacardImpl)49 Serializable (java.io.Serializable)30 Date (java.util.Date)30 Attribute (ddf.catalog.data.Attribute)29 List (java.util.List)23 HashMap (java.util.HashMap)20 IOException (java.io.IOException)18 InputStream (java.io.InputStream)17 Result (ddf.catalog.data.Result)15 HashSet (java.util.HashSet)15 PolicyResponse (ddf.catalog.plugin.PolicyResponse)14 ResultImpl (ddf.catalog.data.impl.ResultImpl)11 UpdateRequestImpl (ddf.catalog.operation.impl.UpdateRequestImpl)11 Set (java.util.Set)11 ContentItem (ddf.catalog.content.data.ContentItem)10 QueryResponse (ddf.catalog.operation.QueryResponse)10