use of ddf.catalog.operation.impl.UpdateRequestImpl in project ddf by codice.
the class CswEndpoint method updateRecords.
private int updateRecords(UpdateAction updateAction) throws CswException, FederationException, IngestException, SourceUnavailableException, UnsupportedQueryException {
if (updateAction.getMetacard() != null) {
Metacard newRecord = updateAction.getMetacard();
if (newRecord.getId() != null) {
UpdateRequest updateRequest = new UpdateRequestImpl(newRecord.getId(), newRecord);
LOGGER.debug("Attempting to update {} ", newRecord.getId());
UpdateResponse updateResponse = framework.update(updateRequest);
return updateResponse.getUpdatedMetacards().size();
} else {
throw new CswException("Unable to update record. No ID was specified in the request.", CswConstants.MISSING_PARAMETER_VALUE, updateAction.getHandle());
}
} else if (updateAction.getConstraint() != null) {
QueryConstraintType constraint = updateAction.getConstraint();
QueryRequest queryRequest = queryFactory.getQuery(constraint);
queryRequest = queryFactory.updateQueryRequestTags(queryRequest, schemaTransformerManager.getTransformerSchemaForId(updateAction.getTypeName()));
QueryResponse response = framework.query(queryRequest);
if (response.getHits() > 0) {
Map<String, Serializable> recordProperties = updateAction.getRecordProperties();
List<String> updatedMetacardIdsList = new ArrayList<>();
List<Metacard> updatedMetacards = new ArrayList<>();
for (Result result : response.getResults()) {
Metacard metacard = result.getMetacard();
if (metacard != null) {
for (Entry<String, Serializable> recordProperty : recordProperties.entrySet()) {
Attribute attribute = new AttributeImpl(recordProperty.getKey(), recordProperty.getValue());
metacard.setAttribute(attribute);
}
updatedMetacardIdsList.add(metacard.getId());
updatedMetacards.add(metacard);
}
}
if (updatedMetacardIdsList.size() > 0) {
String[] updatedMetacardIds = updatedMetacardIdsList.toArray(new String[updatedMetacardIdsList.size()]);
UpdateRequest updateRequest = new UpdateRequestImpl(updatedMetacardIds, updatedMetacards);
LOGGER.debug("Attempting to update {} metacards.", updatedMetacardIdsList.size());
UpdateResponse updateResponse = framework.update(updateRequest);
return updateResponse.getUpdatedMetacards().size();
}
}
}
return 0;
}
use of ddf.catalog.operation.impl.UpdateRequestImpl in project ddf by codice.
the class TestRegistryStore method testUpdateNonRegistryMetacard.
@Test(expected = IngestException.class)
public void testUpdateNonRegistryMetacard() throws Exception {
MetacardImpl updatedMcard = getDefaultMetacard();
updatedMcard.setAttribute(RegistryObjectMetacardType.REGISTRY_ID, null);
UpdateRequestImpl request = new UpdateRequestImpl("testId", updatedMcard);
registryStore.update(request);
}
use of ddf.catalog.operation.impl.UpdateRequestImpl in project ddf by codice.
the class WorkspacePreIngestPluginTest method update.
private static UpdateRequest update(Metacard original, Metacard updated) {
UpdateRequestImpl request = new UpdateRequestImpl(original.getId(), updated);
OperationTransaction transaction = new OperationTransactionImpl(OperationTransaction.OperationType.UPDATE, Arrays.asList(original));
request.setProperties(Collections.singletonMap(Constants.OPERATION_TRANSACTION_KEY, transaction));
return request;
}
use of ddf.catalog.operation.impl.UpdateRequestImpl in project ddf by codice.
the class MetacardEditEndpoint method deleteAttribute.
@DELETE
@Path("/{id}/{attribute}")
public Response deleteAttribute(@Context HttpServletResponse response, @PathParam("id") String id, @PathParam("attribute") String attribute, String value) throws Exception {
Metacard metacard = endpointUtil.getMetacard(id);
Attribute metacardAttribute = metacard.getAttribute(attribute);
if (metacardAttribute == null) {
return Response.ok().build();
}
metacard.setAttribute(new AttributeImpl(attribute, (Serializable) null));
catalogFramework.update(new UpdateRequestImpl(id, metacard));
return Response.ok().build();
}
use of ddf.catalog.operation.impl.UpdateRequestImpl in project ddf by codice.
the class TestMetacardGroomerPlugin method testUpdateByAlternativeIdentifier.
@Test
public void testUpdateByAlternativeIdentifier() throws PluginExecutionException, StopProcessingException, URISyntaxException {
Date snapshotOfNow = new Date();
Metacard inputMetacard = getStandardMetacard(null);
URI[] uris = new URI[1];
uris[0] = new URI(SAMPLE_ID);
UpdateRequestImpl inputRequest = new UpdateRequestImpl(uris, Arrays.asList(copy(inputMetacard)));
UpdateRequest returnedRequest = plugin.process(inputRequest);
assertNotNull(returnedRequest);
assertThat(returnedRequest.getUpdates().size(), is(1));
Metacard outputMetacard = returnedRequest.getUpdates().get(0).getValue();
assertThat(inputMetacard.getId(), is(outputMetacard.getId()));
assertEquals(DEFAULT_TITLE, outputMetacard.getTitle());
assertEquals(DEFAULT_LOCATION, outputMetacard.getLocation());
assertEquals(DEFAULT_TYPE, outputMetacard.getContentTypeName());
assertEquals(DEFAULT_VERSION, outputMetacard.getContentTypeVersion());
assertThat(outputMetacard.getMetadata(), is(DEFAULT_METADATA));
assertThat(outputMetacard.getCreatedDate().getTime(), is(inputMetacard.getCreatedDate().getTime()));
assertThat(((Date) outputMetacard.getAttribute(Core.METACARD_CREATED).getValue()).getTime(), equalTo(((Date) inputMetacard.getAttribute(Core.METACARD_CREATED).getValue()).getTime()));
assertThat(outputMetacard.getModifiedDate().getTime(), is(equalTo(inputMetacard.getModifiedDate().getTime())));
assertThat(((Date) outputMetacard.getAttribute(Core.METACARD_MODIFIED).getValue()).getTime(), is(greaterThanOrEqualTo(snapshotOfNow.getTime())));
assertEquals(inputMetacard.getEffectiveDate(), outputMetacard.getEffectiveDate());
assertEquals(inputMetacard.getExpirationDate(), outputMetacard.getExpirationDate());
assertTrue(Arrays.equals(inputMetacard.getThumbnail(), outputMetacard.getThumbnail()));
assertEquals(inputMetacard.getLocation(), outputMetacard.getLocation());
}
Aggregations