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