Search in sources :

Example 11 with Metacard

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;
}
Also used : Serializable(java.io.Serializable) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Metacard(ddf.catalog.data.Metacard) DeleteResponse(ddf.catalog.operation.DeleteResponse) DeleteResponseImpl(ddf.catalog.operation.impl.DeleteResponseImpl) List(java.util.List) ArrayList(java.util.ArrayList) UUID(java.util.UUID)

Example 12 with Metacard

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;
}
Also used : Metacard(ddf.catalog.data.Metacard) Serializable(java.io.Serializable) HashMap(java.util.HashMap) CreateResponse(ddf.catalog.operation.CreateResponse) ArrayList(java.util.ArrayList) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) CreateResponseImpl(ddf.catalog.operation.impl.CreateResponseImpl)

Example 13 with Metacard

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;
}
Also used : Metacard(ddf.catalog.data.Metacard) ArrayList(java.util.ArrayList) Update(ddf.catalog.operation.Update)

Example 14 with Metacard

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;
}
Also used : Metacard(ddf.catalog.data.Metacard) AttributeImpl(ddf.catalog.data.impl.AttributeImpl) MetacardImpl(ddf.catalog.data.impl.MetacardImpl)

Example 15 with 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;
}
Also used : Metacard(ddf.catalog.data.Metacard) DeleteResponse(ddf.catalog.operation.DeleteResponse) ArrayList(java.util.ArrayList) DeleteRequest(ddf.catalog.operation.DeleteRequest) MetacardType(ddf.catalog.data.MetacardType)

Aggregations

Metacard (ddf.catalog.data.Metacard)746 Test (org.junit.Test)470 ArrayList (java.util.ArrayList)206 MetacardImpl (ddf.catalog.data.impl.MetacardImpl)149 InputStream (java.io.InputStream)136 HashMap (java.util.HashMap)129 AttributeImpl (ddf.catalog.data.impl.AttributeImpl)115 Result (ddf.catalog.data.Result)109 Serializable (java.io.Serializable)100 QueryRequestImpl (ddf.catalog.operation.impl.QueryRequestImpl)90 QueryRequest (ddf.catalog.operation.QueryRequest)84 QueryImpl (ddf.catalog.operation.impl.QueryImpl)80 QueryResponse (ddf.catalog.operation.QueryResponse)78 SourceResponse (ddf.catalog.operation.SourceResponse)76 IOException (java.io.IOException)75 List (java.util.List)74 Map (java.util.Map)67 Filter (org.opengis.filter.Filter)67 CreateResponse (ddf.catalog.operation.CreateResponse)66 HashSet (java.util.HashSet)65