Search in sources :

Example 1 with CreateResponse

use of ddf.catalog.operation.CreateResponse in project ddf by codice.

the class TestRegistryStore method testCreateNoExistingMetacard.

@Test
public void testCreateNoExistingMetacard() throws Exception {
    Metacard mcard = getDefaultMetacard();
    Csw csw = mock(Csw.class);
    TransactionResponseType responseType = mock(TransactionResponseType.class);
    InsertResultType insertResultType = mock(InsertResultType.class);
    BriefRecordType briefRecord = mock(BriefRecordType.class);
    JAXBElement identifier = mock(JAXBElement.class);
    SimpleLiteral literal = mock(SimpleLiteral.class);
    when(literal.getContent()).thenReturn(Collections.singletonList(mcard.getId()));
    when(identifier.getValue()).thenReturn(literal);
    when(briefRecord.getIdentifier()).thenReturn(Collections.singletonList(identifier));
    when(insertResultType.getBriefRecord()).thenReturn(Collections.singletonList(briefRecord));
    when(responseType.getInsertResult()).thenReturn(Collections.singletonList(insertResultType));
    when(factory.getClientForSubject(any())).thenReturn(csw);
    when(csw.transaction(any())).thenReturn(responseType);
    when(transformer.getTransformerIdForSchema(any())).thenReturn("myInsertType");
    queryResults.add(new ResultImpl(mcard));
    CreateRequest request = new CreateRequestImpl(mcard);
    CreateResponse response = registryStore.create(request);
    assertThat(response.getCreatedMetacards().get(0), is(mcard));
}
Also used : Metacard(ddf.catalog.data.Metacard) Csw(org.codice.ddf.spatial.ogc.csw.catalog.common.Csw) CreateRequest(ddf.catalog.operation.CreateRequest) CreateResponse(ddf.catalog.operation.CreateResponse) CreateRequestImpl(ddf.catalog.operation.impl.CreateRequestImpl) SimpleLiteral(net.opengis.cat.csw.v_2_0_2.dc.elements.SimpleLiteral) ResultImpl(ddf.catalog.data.impl.ResultImpl) JAXBElement(javax.xml.bind.JAXBElement) InsertResultType(net.opengis.cat.csw.v_2_0_2.InsertResultType) BriefRecordType(net.opengis.cat.csw.v_2_0_2.BriefRecordType) TransactionResponseType(net.opengis.cat.csw.v_2_0_2.TransactionResponseType) Test(org.junit.Test)

Example 2 with CreateResponse

use of ddf.catalog.operation.CreateResponse in project ddf by codice.

the class FederationAdminServiceImpl method addRegistryEntries.

@Override
public List<String> addRegistryEntries(List<Metacard> metacards, Set<String> destinations) throws FederationAdminException {
    validateRegistryMetacards(metacards);
    List<String> registryIds;
    Map<String, Serializable> properties = new HashMap<>();
    CreateRequest createRequest = new CreateRequestImpl(metacards, properties, destinations);
    try {
        CreateResponse createResponse = security.runWithSubjectOrElevate(() -> catalogFramework.create(createRequest));
        //loop through to get id's
        if (!createResponse.getProcessingErrors().isEmpty()) {
            throw new FederationAdminException("Processing error occurred while creating registry entry. Details:" + System.lineSeparator() + stringifyProcessingErrors(createResponse.getProcessingErrors()));
        }
        registryIds = createResponse.getCreatedMetacards().stream().filter(RegistryUtility::isRegistryMetacard).map(RegistryUtility::getRegistryId).collect(Collectors.toList());
    } catch (SecurityServiceException | InvocationTargetException e) {
        throw new FederationAdminException("Error adding local registry entry.", e);
    }
    return registryIds;
}
Also used : FederationAdminException(org.codice.ddf.registry.federationadmin.service.internal.FederationAdminException) Serializable(java.io.Serializable) SecurityServiceException(ddf.security.service.SecurityServiceException) HashMap(java.util.HashMap) CreateRequest(ddf.catalog.operation.CreateRequest) CreateResponse(ddf.catalog.operation.CreateResponse) RegistryUtility(org.codice.ddf.registry.common.metacard.RegistryUtility) InvocationTargetException(java.lang.reflect.InvocationTargetException) CreateRequestImpl(ddf.catalog.operation.impl.CreateRequestImpl)

Example 3 with CreateResponse

use of ddf.catalog.operation.CreateResponse in project ddf by codice.

the class SolrProviderTest method testDeleteAlternativeAttribute.

/**
     * Testing if another attribute can be used to delete records other than {@link Metacard#ID}
     *
     * @throws IngestException
     * @throws UnsupportedQueryException
     */
@Test
public void testDeleteAlternativeAttribute() throws IngestException, UnsupportedQueryException {
    deleteAllIn(provider);
    MockMetacard metacard = new MockMetacard(Library.getFlagstaffRecord());
    CreateResponse createResponse = create(metacard);
    DeleteResponse deleteResponse = provider.delete(new DeleteRequest() {

        @Override
        public boolean hasProperties() {
            return false;
        }

        @Override
        public Serializable getPropertyValue(String name) {
            return null;
        }

        @Override
        public Set<String> getPropertyNames() {
            return null;
        }

        @Override
        public Map<String, Serializable> getProperties() {
            return null;
        }

        @Override
        public boolean containsPropertyName(String name) {
            return false;
        }

        @Override
        public List<? extends Serializable> getAttributeValues() {
            return Arrays.asList(MockMetacard.DEFAULT_TITLE);
        }

        @Override
        public String getAttributeName() {
            return Metacard.TITLE;
        }
    });
    Metacard deletedMetacard = deleteResponse.getDeletedMetacards().get(0);
    verifyDeletedRecord(metacard, createResponse, deleteResponse, deletedMetacard);
    // verify it is really not in SOLR
    Filter filter = filterBuilder.attribute(Metacard.TITLE).like().text(MockMetacard.DEFAULT_TITLE);
    QueryImpl query = new QueryImpl(filter);
    SourceResponse sourceResponse = provider.query(new QueryRequestImpl(query));
    List<Result> results = sourceResponse.getResults();
    assertEquals(0, results.size());
}
Also used : Serializable(java.io.Serializable) Set(java.util.Set) TreeSet(java.util.TreeSet) HashSet(java.util.HashSet) SourceResponse(ddf.catalog.operation.SourceResponse) CreateResponse(ddf.catalog.operation.CreateResponse) Matchers.containsString(org.hamcrest.Matchers.containsString) Result(ddf.catalog.data.Result) Metacard(ddf.catalog.data.Metacard) QueryImpl(ddf.catalog.operation.impl.QueryImpl) DeleteResponse(ddf.catalog.operation.DeleteResponse) Filter(org.opengis.filter.Filter) QueryRequestImpl(ddf.catalog.operation.impl.QueryRequestImpl) List(java.util.List) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) DeleteRequest(ddf.catalog.operation.DeleteRequest) Map(java.util.Map) Test(org.junit.Test)

Example 4 with CreateResponse

use of ddf.catalog.operation.CreateResponse in project ddf by codice.

the class SolrProviderTest method testStartIndexWithSorting.

@Test
public void testStartIndexWithSorting() throws Exception {
    deleteAllIn(provider);
    List<Metacard> metacards = new ArrayList<Metacard>();
    DateTime dt = new DateTime(1985, 1, 1, 1, 1, 1, 1, DateTimeZone.UTC);
    TreeSet<Date> calculatedDates = new TreeSet<Date>();
    for (int j = 0; j < 10; j++) {
        for (int i = 0; i < 100; i = i + 10) {
            MetacardImpl metacard = new MockMetacard(Library.getFlagstaffRecord());
            // ingest sporadically the effective dates so the default return
            // order won't be ordered
            Date calculatedDate = dt.plusDays(100 - i + 10 - j).toDate();
            calculatedDates.add(calculatedDate);
            metacard.setEffectiveDate(calculatedDate);
            metacards.add(metacard);
        }
    }
    // The TreeSet will sort them, the array will give me access to everyone
    // without an iterator
    Date[] dates = new Date[calculatedDates.size()];
    calculatedDates.toArray(dates);
    /** CREATE **/
    CreateResponse response = create(metacards);
    LOGGER.info("CREATED {} records.", response.getCreatedMetacards().size());
    CommonQueryBuilder queryBuilder = new CommonQueryBuilder();
    QueryImpl query = queryBuilder.queryByProperty(Metacard.CONTENT_TYPE, MockMetacard.DEFAULT_TYPE);
    int maxSize = 20;
    int startIndex = 2;
    // STARTINDEX=2, MAXSIZE=20
    query.setPageSize(maxSize);
    query.setStartIndex(startIndex);
    SortByImpl sortBy = new SortByImpl(queryBuilder.filterFactory.property(Metacard.EFFECTIVE), org.opengis.filter.sort.SortOrder.ASCENDING);
    query.setSortBy(sortBy);
    SourceResponse sourceResponse = provider.query(new QueryRequestImpl(query));
    assertEquals(maxSize, sourceResponse.getResults().size());
    for (int i = 0; i < sourceResponse.getResults().size(); i++) {
        Result r = sourceResponse.getResults().get(i);
        Date effectiveDate = r.getMetacard().getEffectiveDate();
        DateTime currentDate = new DateTime(effectiveDate.getTime());
        LOGGER.debug("Testing current index: {}", startIndex + i);
        assertEquals(new DateTime(dates[startIndex - 1 + i].getTime()).getDayOfYear(), currentDate.getDayOfYear());
    }
    // STARTINDEX=20, MAXSIZE=5
    // a match-all queryByProperty
    query = queryBuilder.queryByProperty(Metacard.CONTENT_TYPE, MockMetacard.DEFAULT_TYPE);
    maxSize = 5;
    startIndex = 20;
    query.setPageSize(maxSize);
    query.setStartIndex(startIndex);
    sortBy = new SortByImpl(queryBuilder.filterFactory.property(Metacard.EFFECTIVE), org.opengis.filter.sort.SortOrder.ASCENDING);
    query.setSortBy(sortBy);
    sourceResponse = provider.query(new QueryRequestImpl(query));
    assertEquals(maxSize, sourceResponse.getResults().size());
    for (int i = 0; i < sourceResponse.getResults().size(); i++) {
        Result r = sourceResponse.getResults().get(i);
        Date effectiveDate = r.getMetacard().getEffectiveDate();
        DateTime currentDate = new DateTime(effectiveDate.getTime());
        LOGGER.debug("Testing current index: {}", startIndex + i);
        assertEquals(new DateTime(dates[startIndex - 1 + i].getTime()).getDayOfYear(), currentDate.getDayOfYear());
    }
    // STARTINDEX=80, MAXSIZE=20
    // a match-all queryByProperty
    query = queryBuilder.queryByProperty(Metacard.CONTENT_TYPE, MockMetacard.DEFAULT_TYPE);
    maxSize = 20;
    startIndex = 80;
    query.setPageSize(maxSize);
    query.setStartIndex(startIndex);
    sortBy = new SortByImpl(queryBuilder.filterFactory.property(Metacard.EFFECTIVE), org.opengis.filter.sort.SortOrder.ASCENDING);
    query.setSortBy(sortBy);
    sourceResponse = provider.query(new QueryRequestImpl(query));
    assertEquals(maxSize, sourceResponse.getResults().size());
    for (int i = 0; i < sourceResponse.getResults().size(); i++) {
        Result r = sourceResponse.getResults().get(i);
        Date effectiveDate = r.getMetacard().getEffectiveDate();
        DateTime currentDate = new DateTime(effectiveDate.getTime());
        LOGGER.debug("Testing current index: {}", startIndex + i);
        assertEquals(new DateTime(dates[startIndex - 1 + i].getTime()).getDayOfYear(), currentDate.getDayOfYear());
    }
    // STARTINDEX=1, MAXSIZE=100
    // a match-all queryByProperty
    query = queryBuilder.queryByProperty(Metacard.CONTENT_TYPE, MockMetacard.DEFAULT_TYPE);
    maxSize = 100;
    startIndex = 1;
    query.setPageSize(maxSize);
    query.setStartIndex(startIndex);
    sortBy = new SortByImpl(queryBuilder.filterFactory.property(Metacard.EFFECTIVE), org.opengis.filter.sort.SortOrder.ASCENDING);
    query.setSortBy(sortBy);
    sourceResponse = provider.query(new QueryRequestImpl(query));
    assertEquals(maxSize, sourceResponse.getResults().size());
    for (int i = 0; i < sourceResponse.getResults().size(); i++) {
        Result r = sourceResponse.getResults().get(i);
        Date effectiveDate = r.getMetacard().getEffectiveDate();
        DateTime currentDate = new DateTime(effectiveDate.getTime());
        LOGGER.debug("Testing current index: {}", startIndex + i);
        assertEquals(new DateTime(dates[startIndex - 1 + i].getTime()).getDayOfYear(), currentDate.getDayOfYear());
    }
}
Also used : SourceResponse(ddf.catalog.operation.SourceResponse) CreateResponse(ddf.catalog.operation.CreateResponse) ArrayList(java.util.ArrayList) DateTime(org.joda.time.DateTime) Date(java.util.Date) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) Result(ddf.catalog.data.Result) Metacard(ddf.catalog.data.Metacard) QueryImpl(ddf.catalog.operation.impl.QueryImpl) SortByImpl(org.geotools.filter.SortByImpl) TreeSet(java.util.TreeSet) QueryRequestImpl(ddf.catalog.operation.impl.QueryRequestImpl) Test(org.junit.Test)

Example 5 with CreateResponse

use of ddf.catalog.operation.CreateResponse in project ddf by codice.

the class SolrProviderTest method testUpdatePendingNrtIndex.

@Test
public void testUpdatePendingNrtIndex() throws Exception {
    deleteAllIn(provider);
    ConfigurationStore.getInstance().setForceAutoCommit(false);
    try {
        MockMetacard metacard = new MockMetacard(Library.getFlagstaffRecord());
        CreateResponse createResponse = create(metacard);
        String id = createResponse.getCreatedMetacards().get(0).getId();
        MockMetacard updatedMetacard = new MockMetacard(Library.getFlagstaffRecord());
        updatedMetacard.setContentTypeName("first");
        UpdateResponse firstUpdateResponse = update(id, updatedMetacard);
        updatedMetacard = new MockMetacard(Library.getFlagstaffRecord());
        updatedMetacard.setContentTypeName("second");
        UpdateResponse secondUpdateResponse = update(id, updatedMetacard);
        verifyContentTypeUpdate(firstUpdateResponse, MockMetacard.DEFAULT_TYPE, "first");
        verifyContentTypeUpdate(secondUpdateResponse, "first", "second");
    } finally {
        ConfigurationStore.getInstance().setForceAutoCommit(true);
    }
}
Also used : UpdateResponse(ddf.catalog.operation.UpdateResponse) CreateResponse(ddf.catalog.operation.CreateResponse) Matchers.containsString(org.hamcrest.Matchers.containsString) Test(org.junit.Test)

Aggregations

CreateResponse (ddf.catalog.operation.CreateResponse)111 Test (org.junit.Test)82 Metacard (ddf.catalog.data.Metacard)76 CreateRequestImpl (ddf.catalog.operation.impl.CreateRequestImpl)44 ArrayList (java.util.ArrayList)42 CreateRequest (ddf.catalog.operation.CreateRequest)36 QueryImpl (ddf.catalog.operation.impl.QueryImpl)29 QueryRequestImpl (ddf.catalog.operation.impl.QueryRequestImpl)29 CreateResponseImpl (ddf.catalog.operation.impl.CreateResponseImpl)27 HashMap (java.util.HashMap)25 Serializable (java.io.Serializable)23 List (java.util.List)23 MetacardImpl (ddf.catalog.data.impl.MetacardImpl)22 DeleteResponse (ddf.catalog.operation.DeleteResponse)22 UpdateResponse (ddf.catalog.operation.UpdateResponse)21 Filter (org.opengis.filter.Filter)21 IngestException (ddf.catalog.source.IngestException)20 SourceResponse (ddf.catalog.operation.SourceResponse)18 QueryRequest (ddf.catalog.operation.QueryRequest)17 MetacardType (ddf.catalog.data.MetacardType)16