use of java.util.Collection in project head by mifos.
the class BranchReportLoanArrearsAgingHelperIntegrationTest method assertLoanArrearsAgingPopulated.
private void assertLoanArrearsAgingPopulated(Set<BranchReportLoanArrearsAgingBO> loanArrearsAgingSummaries) {
Assert.assertNotNull(loanArrearsAgingSummaries);
Collection foundPeriods = CollectionUtils.collect(loanArrearsAgingSummaries, new Transformer() {
@Override
public Object transform(Object input) {
return ((BranchReportLoanArrearsAgingBO) input).getAgingPeriod();
}
});
assertSameCollections(expectedPeriods, foundPeriods);
}
use of java.util.Collection in project morphia by mongodb.
the class Mapper method fromDb.
/**
* Converts a DBObject back to a type-safe java object (POJO)
*
* @param <T> the type of the entity
* @param datastore the Datastore to use when fetching this reference
* @param dbObject the DBObject containing the document from mongodb
* @param entity the instance to populate
* @param cache the EntityCache to use
* @return the entity
*/
public <T> T fromDb(final Datastore datastore, final DBObject dbObject, final T entity, final EntityCache cache) {
//hack to bypass things and just read the value.
if (entity instanceof MappedField) {
readMappedField(datastore, (MappedField) entity, entity, cache, dbObject);
return entity;
}
if (dbObject.containsField(ID_KEY) && getMappedClass(entity).getIdField() != null && getMappedClass(entity).getEntityAnnotation() != null) {
final Key<T> key = new Key(entity.getClass(), getCollectionName(entity.getClass()), dbObject.get(ID_KEY));
final T cachedInstance = cache.getEntity(key);
if (cachedInstance != null) {
return cachedInstance;
} else {
// to avoid stackOverflow in recursive refs
cache.putEntity(key, entity);
}
}
if (entity instanceof Map) {
Map<String, Object> map = (Map<String, Object>) entity;
for (String key : dbObject.keySet()) {
Object o = dbObject.get(key);
map.put(key, (o instanceof DBObject) ? fromDBObject(datastore, (DBObject) o) : o);
}
} else if (entity instanceof Collection) {
Collection<Object> collection = (Collection<Object>) entity;
for (Object o : ((List) dbObject)) {
collection.add((o instanceof DBObject) ? fromDBObject(datastore, (DBObject) o) : o);
}
} else {
final MappedClass mc = getMappedClass(entity);
final DBObject updated = mc.callLifecycleMethods(PreLoad.class, entity, dbObject, this);
try {
for (final MappedField mf : mc.getPersistenceFields()) {
readMappedField(datastore, mf, entity, cache, updated);
}
} catch (final MappingException e) {
Object id = dbObject.get(ID_KEY);
String entityName = entity.getClass().getName();
throw new MappingException(format("Could not map %s with ID: %s in database '%s'", entityName, id, datastore.getDB().getName()), e);
}
if (updated.containsField(ID_KEY) && getMappedClass(entity).getIdField() != null) {
final Key key = new Key(entity.getClass(), getCollectionName(entity.getClass()), updated.get(ID_KEY));
cache.putEntity(key, entity);
}
mc.callLifecycleMethods(PostLoad.class, entity, updated, this);
}
return entity;
}
use of java.util.Collection in project morphia by mongodb.
the class ReferenceMapper method readCollection.
private void readCollection(final Datastore datastore, final Mapper mapper, final DBObject dbObject, final MappedField mf, final Object entity, final Reference refAnn, final EntityCache cache) {
// multiple references in a List
final Class referenceObjClass = mf.getSubClass();
// load reference class. this "fixes" #816
mapper.getMappedClass(referenceObjClass);
Collection references = mf.isSet() ? mapper.getOptions().getObjectFactory().createSet(mf) : mapper.getOptions().getObjectFactory().createList(mf);
if (refAnn.lazy() && LazyFeatureDependencies.assertDependencyFullFilled()) {
final Object dbVal = mf.getDbObjectValue(dbObject);
if (dbVal != null) {
references = mapper.getProxyFactory().createListProxy(datastore, references, referenceObjClass, refAnn.ignoreMissing());
final ProxiedEntityReferenceList referencesAsProxy = (ProxiedEntityReferenceList) references;
if (dbVal instanceof List) {
referencesAsProxy.__addAll(refAnn.idOnly() ? mapper.getKeysByManualRefs(referenceObjClass, (List) dbVal) : mapper.getKeysByRefs((List) dbVal));
} else {
referencesAsProxy.__add(refAnn.idOnly() ? mapper.manualRefToKey(referenceObjClass, dbVal) : mapper.refToKey((DBRef) dbVal));
}
}
} else {
final Object dbVal = mf.getDbObjectValue(dbObject);
final Collection refs = references;
new IterHelper<String, Object>().loopOrSingle(dbVal, new IterCallback<Object>() {
@Override
public void eval(final Object val) {
final Object ent = resolveObject(datastore, mapper, cache, mf, refAnn.idOnly(), val);
if (ent == null) {
LOG.warning("Null reference found when retrieving value for " + mf.getFullName());
} else {
refs.add(ent);
}
}
});
}
if (mf.getType().isArray()) {
mf.setFieldValue(entity, ReflectionUtils.convertToArray(mf.getSubClass(), ReflectionUtils.iterToList(references)));
} else {
mf.setFieldValue(entity, references);
}
}
use of java.util.Collection in project feign by OpenFeign.
the class JacksonJaxbCodecTest method notFoundDecodesToEmpty.
/** Enabled via {@link feign.Feign.Builder#decode404()} */
@Test
public void notFoundDecodesToEmpty() throws Exception {
Response response = Response.builder().status(404).reason("NOT FOUND").headers(Collections.<String, Collection<String>>emptyMap()).build();
assertThat((byte[]) new JacksonJaxbJsonDecoder().decode(response, byte[].class)).isEmpty();
}
use of java.util.Collection in project feign by OpenFeign.
the class JacksonCodecTest method notFoundDecodesToEmpty.
/** Enabled via {@link feign.Feign.Builder#decode404()} */
@Test
public void notFoundDecodesToEmpty() throws Exception {
Response response = Response.builder().status(404).reason("NOT FOUND").headers(Collections.<String, Collection<String>>emptyMap()).build();
assertThat((byte[]) new JacksonDecoder().decode(response, byte[].class)).isEmpty();
}
Aggregations