use of org.codice.ddf.persistence.PersistentStore in project ddf by codice.
the class TestDataUsage method setUp.
@Before
public void setUp() throws PersistenceException {
attributesStore = mock(AttributesStore.class);
persistentStore = mock(PersistentStore.class);
userList = generateUserList();
when(attributesStore.getAllUsers()).thenReturn(userList);
doAnswer((InvocationOnMock invocationOnMock) -> {
Object[] args = invocationOnMock.getArguments();
String user = (String) args[0];
long dataUsage = (long) args[1];
for (Map<String, Object> map : userList) {
if (map.get(USER_TXT).equals(user)) {
map.put(DATA_LIMIT, dataUsage);
}
}
return null;
}).when(attributesStore).setDataLimit(anyString(), anyLong());
dataUsage = new DataUsage(attributesStore, persistentStore);
}
use of org.codice.ddf.persistence.PersistentStore in project ddf by codice.
the class TestCatalog method persistToWorkspace.
private void persistToWorkspace(int size) throws Exception {
// Generate very large data block
Map<String, String> map = Maps.newHashMap();
for (int i = 0; i < size; i++) {
map.put("Key-" + i, "Val-" + i);
}
JSONObject jsonObject = new JSONObject();
jsonObject.putAll(map);
String jsonString = jsonObject.toJSONString();
final PersistentStore pstore = getServiceManager().getService(PersistentStore.class);
PersistentItem item = new PersistentItem();
item.addIdProperty("itest");
item.addProperty("user", "itest");
item.addProperty("workspaces_json", jsonString);
final String WORKSPACE_TYPE = PersistenceType.WORKSPACE_TYPE.toString();
await("").atMost(1, TimeUnit.MINUTES).pollDelay(1, TimeUnit.SECONDS).ignoreExceptions().until(() -> pstore.get(WORKSPACE_TYPE).isEmpty());
pstore.add(WORKSPACE_TYPE, item);
await("Solr core to be spun up and item to be persisted").atMost(5, TimeUnit.MINUTES).until(() -> pstore.get(WORKSPACE_TYPE).size(), equalTo(1));
List<Map<String, Object>> storedWs = pstore.get(WORKSPACE_TYPE, "\"id\" = 'itest'");
assertThat(storedWs, hasSize(1));
assertThat(storedWs.get(0).get("user_txt"), is("itest"));
pstore.delete(WORKSPACE_TYPE, "\"id\" = 'itest'");
await("Workspace to be empty").atMost(5, TimeUnit.MINUTES).until(() -> pstore.get(WORKSPACE_TYPE).size(), equalTo(0));
}
use of org.codice.ddf.persistence.PersistentStore in project ddf by codice.
the class DeleteCommand method execute.
@Override
public Object execute() throws Exception {
PrintStream console = System.out;
// Get Notification service
@SuppressWarnings("rawtypes") ServiceReference[] serviceReferences = bundleContext.getServiceReferences(SERVICE_PID, null);
int numDeleted = 0;
if (serviceReferences == null || serviceReferences.length != 1) {
LOGGER.debug("Found no service references for {}", SERVICE_PID);
} else {
LOGGER.debug("Found " + serviceReferences.length + " service references for " + SERVICE_PID);
PersistentStore persistentStore = (PersistentStore) bundleContext.getService(serviceReferences[0]);
if (persistentStore != null) {
if (StringUtils.isNotBlank(id)) {
try {
numDeleted = persistentStore.delete(PersistentStore.NOTIFICATION_TYPE, Notification.NOTIFICATION_KEY_ID + " = '" + id + "'");
} catch (PersistenceException e) {
LOGGER.info("PersistenceException during deletion of notifications for ID {}", id, e);
}
} else if (StringUtils.isNotBlank(userId)) {
try {
numDeleted = persistentStore.delete(PersistentStore.NOTIFICATION_TYPE, Notification.NOTIFICATION_KEY_USER_ID + " = '" + userId + "'");
} catch (PersistenceException e) {
LOGGER.info("PersistenceException during deletion of notifications for user {}", userId, e);
}
}
} else {
LOGGER.debug("Unable to lookup PersistentStore service");
}
}
console.println(CYAN_CONSOLE_COLOR + "Deleted " + numDeleted + " notifications" + DEFAULT_CONSOLE_COLOR);
return null;
}
use of org.codice.ddf.persistence.PersistentStore in project ddf by codice.
the class ListCommand method getNotifications.
@SuppressWarnings("unchecked")
private List<Map<String, Object>> getNotifications(String userId) throws InvalidSyntaxException {
List<Map<String, Object>> notifications = new ArrayList<>();
// Get Notification service
@SuppressWarnings("rawtypes") ServiceReference[] serviceReferences = bundleContext.getServiceReferences(SERVICE_PID, null);
if (serviceReferences == null || serviceReferences.length != 1) {
LOGGER.debug("Found no service references for {}", SERVICE_PID);
} else {
LOGGER.debug("Found " + serviceReferences.length + " service references for " + SERVICE_PID);
PersistentStore persistentStore = (PersistentStore) bundleContext.getService(serviceReferences[0]);
if (persistentStore != null) {
try {
List<Map<String, Object>> results;
if (StringUtils.isNotBlank(cql)) {
results = persistentStore.get(PersistentStore.NOTIFICATION_TYPE, cql);
} else if (StringUtils.isNotBlank(userId)) {
results = persistentStore.get(PersistentStore.NOTIFICATION_TYPE, Notification.NOTIFICATION_KEY_USER_ID + " = '" + userId + "'");
} else {
results = persistentStore.get(PersistentStore.NOTIFICATION_TYPE);
}
for (Map<String, Object> result : results) {
notifications.add(PersistentItem.stripSuffixes(result));
}
} catch (PersistenceException e) {
LOGGER.info("PersistenceException during retrieval of notifications", e);
}
} else {
LOGGER.debug("Unable to lookup PersistentStore service");
}
}
return notifications;
}
use of org.codice.ddf.persistence.PersistentStore in project ddf by codice.
the class TestSubscriptionsPersistentStoreImpl method setup.
@Before
public void setup() {
PersistentStore persistentStore = new MemoryPersistentStore();
store = new SubscriptionsPersistentStoreImpl(persistentStore);
}
Aggregations