use of ddf.catalog.data.Metacard in project ddf by codice.
the class MockMemoryProvider method delete.
@Override
public DeleteResponse delete(DeleteRequest deleteRequest) {
hasReceivedDelete = true;
@SuppressWarnings("unchecked") List<String> ids = (List<String>) deleteRequest.getAttributeValues();
Map<String, Serializable> properties = new HashMap<>();
List<Metacard> returnedMetacards = new ArrayList<>(ids.size());
for (int i = 0; i < ids.size(); i++) {
String id = (String) ids.get(i);
UUID curUUID = UUID.fromString(id);
if (store.containsKey(curUUID.toString())) {
Metacard card = store.remove(curUUID.toString());
if (card != null) {
returnedMetacards.add(card);
}
}
}
DeleteResponse response = new DeleteResponseImpl(deleteRequest, properties, returnedMetacards);
return response;
}
use of ddf.catalog.data.Metacard in project ddf by codice.
the class MockMemoryProvider method create.
@Override
public CreateResponse create(CreateRequest request) {
List<Metacard> oldCards = request.getMetacards();
hasReceivedCreate = true;
List<Metacard> returnedMetacards = new ArrayList<>(oldCards.size());
Map<String, Serializable> properties = new HashMap<>();
for (Metacard curCard : oldCards) {
MetacardImpl card = new MetacardImpl(curCard);
if (card.getId() == null) {
card.setId(UUID.randomUUID().toString());
}
LOGGER.debug("Storing metacard with id: {}", card.getId());
store.put(card.getId(), card);
properties.put(card.getId(), card);
returnedMetacards.add(card);
}
CreateResponse ingestResponseImpl = new CreateResponseImpl(request, properties, returnedMetacards);
return ingestResponseImpl;
}
use of ddf.catalog.data.Metacard in project ddf by codice.
the class CatalogBackupPlugin method process.
/**
* Backs up updated metacards to the file system backup.
*
* @param input the {@link UpdateResponse} to process
* @return {@link UpdateResponse}
*/
@Override
public UpdateResponse process(UpdateResponse input) {
int size = input.getUpdatedMetacards().size();
List<Metacard> toDelete = new ArrayList<>(size);
List<Metacard> toCreate = new ArrayList<>(size);
for (Update update : input.getUpdatedMetacards()) {
toDelete.add(update.getOldMetacard());
toCreate.add(update.getNewMetacard());
}
execute(() -> delete(toDelete));
execute(() -> create(toCreate));
return input;
}
use of ddf.catalog.data.Metacard in project ddf by codice.
the class CatalogBackupPluginTest method getMetacard.
private Metacard getMetacard(String metacardId, String title) {
Metacard metacard = new MetacardImpl();
metacard.setAttribute(new AttributeImpl(Metacard.ID, metacardId));
metacard.setAttribute((new AttributeImpl(Metacard.TITLE, title)));
return metacard;
}
use of ddf.catalog.data.Metacard in project ddf by codice.
the class CatalogBackupPluginTest method getDeleteResponse.
private DeleteResponse getDeleteResponse(List<String> metacardIds) {
MetacardType mockMetacardType = mock(MetacardType.class);
when(mockMetacardType.getName()).thenReturn(MetacardType.DEFAULT_METACARD_TYPE_NAME);
List<Metacard> deletedMetacards = new ArrayList<>(metacardIds.size());
for (String metacardId : metacardIds) {
Metacard mockMetacard = mock(Metacard.class);
when(mockMetacard.getId()).thenReturn(metacardId);
when(mockMetacard.getMetacardType()).thenReturn(mockMetacardType);
deletedMetacards.add(mockMetacard);
}
DeleteRequest request = mock(DeleteRequest.class);
DeleteResponse mockDeleteResponse = mock(DeleteResponse.class);
when(mockDeleteResponse.getDeletedMetacards()).thenReturn(deletedMetacards);
when(mockDeleteResponse.getRequest()).thenReturn(request);
return mockDeleteResponse;
}
Aggregations