Search in sources :

Example 96 with AttributeImpl

use of ddf.catalog.data.impl.AttributeImpl in project ddf by codice.

the class ExpirationDatePlugin method updateExpirationDate.

/**
     * Updates a metacard's expiration date.
     *
     * @param metacard
     *            the metacard to update.
     */
private void updateExpirationDate(Metacard metacard) {
    Date currentExpirationDate = metacard.getExpirationDate();
    if (currentExpirationDate == null && !overwriteIfBlank) {
        // Don't overwrite empty expiration date if configuration disallows
        LOGGER.debug("The Expiration Date Pre-Ingest Plugin is not configured to overwrite 'empty' expiration dates. Not overwriting null expiration date for metacard ID [{}]. ", metacard.getId());
        return;
    } else if (currentExpirationDate != null && !overwriteIfExists) {
        // Don't overwrite existing expiration date if configuration disallows
        LOGGER.debug("The Expiration Date Pre-Ingest Plugin is not configured to overwrite 'existing' expiration dates. Not overwriting the existing expiration date of {} for metacard ID [{}]. ", currentExpirationDate, metacard.getId());
        return;
    }
    Date metacardCreatedDate = getMetacardCreatedDate(metacard);
    Date newExpirationDate = calculateNewExpirationDate(metacardCreatedDate);
    LOGGER.debug("Metacard ID [{}] has an expiration date of {}. Calculating new expiration date by adding {} day(s) to the created date of {}. The new expiration date is {}.", metacard.getId(), currentExpirationDate, this.offsetFromCreatedDate, metacardCreatedDate, newExpirationDate);
    Attribute expirationDate = new AttributeImpl(Metacard.EXPIRATION, newExpirationDate);
    metacard.setAttribute(expirationDate);
}
Also used : Attribute(ddf.catalog.data.Attribute) AttributeImpl(ddf.catalog.data.impl.AttributeImpl) Date(java.util.Date)

Example 97 with AttributeImpl

use of ddf.catalog.data.impl.AttributeImpl in project ddf by codice.

the class RegistryTransformerTest method testMetacardToXmlBadTag.

@Test(expected = CatalogTransformerException.class)
public void testMetacardToXmlBadTag() throws Exception {
    String in = IOUtils.toString(getClass().getResourceAsStream("/csw-rim-node.xml"));
    Metacard metacard = registryTransformer.transform(IOUtils.toInputStream(in));
    metacard.setAttribute(new AttributeImpl(Metacard.TAGS, "JustSomeMadeUpStuff"));
    String out = IOUtils.toString(registryTransformer.transform(metacard, null).getInputStream());
    assertThat(in, is(out));
}
Also used : Metacard(ddf.catalog.data.Metacard) AttributeImpl(ddf.catalog.data.impl.AttributeImpl) Test(org.junit.Test)

Example 98 with AttributeImpl

use of ddf.catalog.data.impl.AttributeImpl in project ddf by codice.

the class FederationAdmin method createLocalEntry.

@Override
public String createLocalEntry(String base64EncodedXmlData) throws FederationAdminException {
    if (StringUtils.isBlank(base64EncodedXmlData)) {
        throw new FederationAdminException("Error creating local entry. String provided was blank.");
    }
    String metacardId;
    try (InputStream xmlStream = new ByteArrayInputStream(Base64.getDecoder().decode(base64EncodedXmlData))) {
        Metacard metacard = getRegistryMetacardFromInputStream(xmlStream);
        metacard.setAttribute(new AttributeImpl(RegistryObjectMetacardType.REGISTRY_LOCAL_NODE, true));
        metacardId = federationAdminService.addRegistryEntry(metacard);
    } catch (IOException | IllegalArgumentException e) {
        throw new FederationAdminException("Error creating local entry. Couldn't decode string.", e);
    }
    return metacardId;
}
Also used : FederationAdminException(org.codice.ddf.registry.federationadmin.service.internal.FederationAdminException) Metacard(ddf.catalog.data.Metacard) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) AttributeImpl(ddf.catalog.data.impl.AttributeImpl) IOException(java.io.IOException)

Example 99 with AttributeImpl

use of ddf.catalog.data.impl.AttributeImpl in project ddf by codice.

the class FederationAdmin method updateLocalEntry.

@Override
public void updateLocalEntry(Map<String, Object> registryObjectMap) throws FederationAdminException {
    Optional<RegistryPackageType> registryPackageOptional = registryTypeConverter.convert(registryObjectMap);
    RegistryPackageType registryPackage = registryPackageOptional.orElseThrow(() -> new FederationAdminException("Error updating local registry entry. Couldn't convert registry map to a registry package."));
    updateDateFields(registryPackage);
    List<Metacard> existingMetacards = federationAdminService.getLocalRegistryMetacardsByRegistryIds(Collections.singletonList(registryPackage.getId()));
    if (CollectionUtils.isEmpty(existingMetacards)) {
        String message = "Error updating local registry entry. Registry metacard not found.";
        LOGGER.debug("{} Registry ID: {}", message, registryPackage.getId());
        throw new FederationAdminException(message);
    }
    if (existingMetacards.size() > 1) {
        throw new FederationAdminException("Error updating local registry entry. Multiple registry metacards found.");
    }
    Metacard existingMetacard = existingMetacards.get(0);
    Metacard updateMetacard = getRegistryMetacardFromRegistryPackage(registryPackage);
    updateMetacard.setAttribute(new AttributeImpl(Metacard.ID, existingMetacard.getId()));
    federationAdminService.updateRegistryEntry(updateMetacard);
}
Also used : FederationAdminException(org.codice.ddf.registry.federationadmin.service.internal.FederationAdminException) Metacard(ddf.catalog.data.Metacard) RegistryPackageType(oasis.names.tc.ebxml_regrep.xsd.rim._3.RegistryPackageType) AttributeImpl(ddf.catalog.data.impl.AttributeImpl)

Example 100 with AttributeImpl

use of ddf.catalog.data.impl.AttributeImpl in project ddf by codice.

the class FederationAdminTest method testUpdateLocalEntry.

@Test
public void testUpdateLocalEntry() throws Exception {
    RegistryPackageType registryObject = getRegistryObjectFromResource("/csw-registry-package-smaller.xml");
    Map<String, Object> registryMap = getMapFromRegistryObject(registryObject);
    String existingMetacardId = "someUpdateMetacardId";
    Metacard existingMetacard = getTestMetacard();
    existingMetacard.setAttribute(new AttributeImpl(Metacard.ID, existingMetacardId));
    List<Metacard> existingMetacards = new ArrayList<>();
    existingMetacards.add(existingMetacard);
    Metacard updateMetacard = getTestMetacard();
    when(federationAdminService.getLocalRegistryMetacardsByRegistryIds(Collections.singletonList(registryObject.getId()))).thenReturn(existingMetacards);
    when(registryTransformer.transform(any(InputStream.class))).thenReturn(updateMetacard);
    federationAdmin.updateLocalEntry(registryMap);
    verify(federationAdminService).getLocalRegistryMetacardsByRegistryIds(Collections.singletonList(registryObject.getId()));
    verify(registryTransformer).transform(any(InputStream.class));
    verify(federationAdminService).updateRegistryEntry(updateMetacard);
}
Also used : Metacard(ddf.catalog.data.Metacard) RegistryPackageType(oasis.names.tc.ebxml_regrep.xsd.rim._3.RegistryPackageType) InputStream(java.io.InputStream) AttributeImpl(ddf.catalog.data.impl.AttributeImpl) ArrayList(java.util.ArrayList) 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