本文整理汇总了Java中org.motechproject.mds.service.MotechDataService类的典型用法代码示例。如果您正苦于以下问题:Java MotechDataService类的具体用法?Java MotechDataService怎么用?Java MotechDataService使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
MotechDataService类属于org.motechproject.mds.service包,在下文中一共展示了MotechDataService类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: verifyEUDEInstancesAreCreated
import org.motechproject.mds.service.MotechDataService; //导入依赖的package包/类
private void verifyEUDEInstancesAreCreated()
throws IllegalAccessException, ClassNotFoundException, InstantiationException {
EntityDto entityDto = entityService.getEntityByClassName
(Constants.Packages.ENTITY.concat(".").concat(generator.getEntityPrefix()).concat("0"));
Assert.assertNotNull(entityDto);
generator.generateDummyInstances(entityDto.getId(), INSTANCES);
Bundle entitiesBundle = OsgiBundleUtils.findBundleBySymbolicName(bundleContext, MDS_ENTITIES_SYMBOLIC_NAME);
assertNotNull(entitiesBundle);
final String serviceName = ClassName.getInterfaceName(entityDto.getName());
MotechDataService service = (MotechDataService) ServiceRetriever.getService(entitiesBundle.getBundleContext(), serviceName);
Assert.assertEquals(service.retrieveAll().size(), INSTANCES);
}
示例2: testPerformance
import org.motechproject.mds.service.MotechDataService; //导入依赖的package包/类
@Test
public void testPerformance() throws NotFoundException, CannotCompileException, IOException, InvalidSyntaxException, InterruptedException, ClassNotFoundException, IllegalAccessException, InstantiationException, NoSuchMethodException, InvocationTargetException {
final String serviceName = ClassName.getInterfaceName(FOO_CLASS);
generator.generateDummyEntities(1, 2, 0, true);
Bundle entitiesBundle = OsgiBundleUtils.findBundleBySymbolicName(bundleContext, MDS_ENTITIES_SYMBOLIC_NAME);
assertNotNull(entitiesBundle);
MotechDataService service = (MotechDataService) ServiceRetriever.getService(entitiesBundle.getBundleContext(), serviceName, true);
Class<?> objectClass = entitiesBundle.loadClass(FOO_CLASS);
LOGGER.info("Loaded class: " + objectClass.getName());
stressTestCreating(service, objectClass);
stressTestRetrieval(service);
stressTestUpdating(service);
stressTestDeleting(service);
}
示例3: stressTestCreating
import org.motechproject.mds.service.MotechDataService; //导入依赖的package包/类
private void stressTestCreating(MotechDataService service, Class clazz)
throws InvocationTargetException, NoSuchMethodException, InstantiationException, IllegalAccessException, ClassNotFoundException {
EntityDto entityDto = entityService.getEntityByClassName(FOO_CLASS);
for (int i = 0 ; i < TEST_INSTANCES; i++) {
testInstances.add(generator.makeDummyInstance(entityDto.getId()));
}
Long startTime = System.nanoTime();
for (Object instance : testInstances) {
service.create(instance);
}
Long endTime = (System.nanoTime() - startTime) / 1000000;
LOGGER.info("MDS Service: Creating " + TEST_INSTANCES + " instances took " + endTime + "ms.");
logToFile((double) endTime);
}
示例4: validateLookupsReferences
import org.motechproject.mds.service.MotechDataService; //导入依赖的package包/类
private void validateLookupsReferences(Collection<String> lookupsNames, String entityClassName) {
MotechDataService dataSourceDataService = OSGiServiceUtils.findService(bundleContext,
MotechClassPool.getInterfaceName(DATA_SOURCE_CLASS_NAME));
if (dataSourceDataService != null) {
StringBuilder lookups = new StringBuilder();
for (String lookupName : lookupsNames) {
long count = (long) dataSourceDataService.executeQuery(createLookupReferenceQuery(lookupName, entityClassName));
if (count > 0) {
if (lookups.length() != 0) {
lookups.append(' ');
}
lookups.append(lookupName);
}
}
if (lookups.length() > 0) {
throw new LookupReferencedException(entityClassName, lookups.toString());
}
}
}
示例5: preDelete
import org.motechproject.mds.service.MotechDataService; //导入依赖的package包/类
@Override
public void preDelete(InstanceLifecycleEvent event) {
Object instance = event.getSource();
String className = instance.getClass().getName();
getLogger().trace("Received pre-delete for: {}", instance);
// omit events for trash and history instances
// get the schema version from the data service
MotechDataService dataService = ServiceUtil.getServiceFromAppContext(getApplicationContext(), className);
Long schemaVersion = dataService.getSchemaVersion();
if (getService().isTrashMode()) {
getLogger().debug("Moving to trash {}, schema version {}", new Object[]{instance, schemaVersion});
getService().moveToTrash(instance, schemaVersion);
}
}
示例6: setRelationshipInstanceProperty
import org.motechproject.mds.service.MotechDataService; //导入依赖的package包/类
private void setRelationshipInstanceProperty(Object instance, Field field, Object value)
throws ActionHandlerException {
RelationshipHolder relationshipHolder = new RelationshipHolder(field);
try {
if (null != value) {
String relatedClassName = relationshipHolder.getRelatedClass();
MotechDataService relatedClassDataService = getEntityDataService(relatedClassName);
if (relationshipHolder.isManyToOne() || relationshipHolder.isOneToOne()) {
Object relatedInstance = getRelatedInstance(relatedClassDataService, value);
PropertyUtil.safeSetProperty(instance, field.getName(), relatedInstance);
} else if (relationshipHolder.isManyToMany() || relationshipHolder.isOneToMany()) {
List<Object> relatedInstances = getRelatedInstances(relatedClassDataService, value);
PropertyUtil.safeSetCollectionProperty(instance, field.getName(), relatedInstances);
}
} else {
PropertyUtil.safeSetProperty(instance, field.getName(), null);
}
} catch (RuntimeException e) {
throw new ActionHandlerException("Cannot set instance property " + field.getName() + " with value " + value, e);
}
}
示例7: shouldDoFilters
import org.motechproject.mds.service.MotechDataService; //导入依赖的package包/类
@Test
public void shouldDoFilters() {
MotechDataService service = getService();
Filter yearFilter = new Filter(DATE_FIELD, FilterValue.THIS_YEAR);
Filter falseFilter = new Filter(BOOL_FIELD, FilterValue.NO);
Filters filters = new Filters(new Filter[]{yearFilter, falseFilter});
try {
TimeFaker.fakeNow(NOW);
List<Object> list = service.filter(filters, null);
assertPresentByStrField(list, "eightDaysAgo", "notThisMonth");
assertEquals(2, service.countForFilters(filters));
} finally {
TimeFaker.stopFakingTime();
}
}
示例8: countRecordsByLookup
import org.motechproject.mds.service.MotechDataService; //导入依赖的package包/类
@Override
public long countRecordsByLookup(Long entityId, String lookupName, Map<String, Object> lookupMap) {
EntityDto entity = getEntity(entityId);
validateCredentialsForReading(entity);
LookupDto lookup = getLookupByName(entityId, lookupName);
Map<String, FieldDto> fieldMap = entityService.getLookupFieldsMapping(entityId, lookupName);
MotechDataService service = getServiceForEntity(entity);
try {
LookupExecutor lookupExecutor = new LookupExecutor(service, lookup, fieldMap);
return lookupExecutor.executeCount(lookupMap);
} catch (RuntimeException e) {
throw new LookupExecutionException(e, LOOKUP_EXCEPTION_MESSAGE_KEY);
}
}
示例9: getInstanceHistory
import org.motechproject.mds.service.MotechDataService; //导入依赖的package包/类
@Override
public List<BasicHistoryRecord> getInstanceHistory(Long entityId, Long instanceId, QueryParams queryParams) {
EntityDto entity = getEntity(entityId);
validateCredentialsForReading(entity);
MotechDataService service = getServiceForEntity(entity);
Object instance = service.retrieve(ID_FIELD_NAME, instanceId);
List history = historyService.getHistoryForInstance(instance, queryParams);
updateGridSize(entityId, queryParams);
List<BasicHistoryRecord> result = new ArrayList<>();
for (Object o : history) {
result.add(convertToBasicHistoryRecord(o, entity, instanceId, service));
}
return result;
}
示例10: getEntityInstance
import org.motechproject.mds.service.MotechDataService; //导入依赖的package包/类
@Override
public EntityRecord getEntityInstance(Long entityId, Long instanceId) {
EntityDto entity = getEntity(entityId);
validateCredentialsForReading(entity);
MotechDataService service = getServiceForEntity(entity);
Object instance = service.retrieve(ID_FIELD_NAME, instanceId);
if (instance == null) {
throw new ObjectNotFoundException(entity.getName(), instanceId);
}
List<FieldDto> fields = entityService.getEntityFieldsForUI(entityId);
Map<String, List<FieldDto>> relatedEntitiesFields = getRelatedEntitiesFields(fields);
return instanceToRecord(instance, entity, fields, service, EntityType.STANDARD, relatedEntitiesFields);
}
示例11: getInstanceValueAsRelatedField
import org.motechproject.mds.service.MotechDataService; //导入依赖的package包/类
@Override
public FieldRecord getInstanceValueAsRelatedField(Long entityId, Long fieldId, Long instanceId) {
validateCredentialsForReading(getEntity(entityId));
try {
FieldRecord fieldRecord;
FieldDto field = entityService.getEntityFieldById(entityId, fieldId);
MotechDataService service = DataServiceHelper.getDataService(bundleContext, field.getMetadata(RELATED_CLASS).getValue());
Object instance = service.findById(instanceId);
if (instance == null) {
throw new ObjectNotFoundException(service.getClassType().getName(), instanceId);
}
List<FieldDto> relatedEntityFields = getEntityFieldsByClassName(field.getMetadata(RELATED_CLASS).getValue());
fieldRecord = new FieldRecord(field);
fieldRecord.setValue(parseValueForDisplay(instance, relatedEntityFields));
fieldRecord.setDisplayValue(instance.toString());
return fieldRecord;
} catch (IllegalAccessException | NoSuchMethodException | InvocationTargetException e) {
throw new ObjectReadException(entityId, e);
}
}
示例12: buildRelatedInstances
import org.motechproject.mds.service.MotechDataService; //导入依赖的package包/类
private Object buildRelatedInstances(MotechDataService service, Class<?> parameterType, Class<?> argumentType, Object fieldValue, Object relatedObject)
throws IllegalAccessException, InstantiationException, ClassNotFoundException, NoSuchMethodException, CannotCompileException, NoSuchFieldException {
Object parsedValue;
RelationshipsUpdate relationshipsUpdate = mapper.convertValue(fieldValue, RelationshipsUpdate.class);
EntityDto relatedEntity = getEntity(argumentType.getName());
List<FieldDto> entityFields = getEntityFields(relatedEntity.getId());
if (Collection.class.isAssignableFrom(parameterType)) {
parsedValue = parseRelationshipCollection(service, (Class<? extends Collection>) parameterType, argumentType, (Collection) relatedObject, relationshipsUpdate, entityFields);
} else {
parsedValue = parseRelationshipValue(service, argumentType, relationshipsUpdate, entityFields);
}
return parsedValue;
}
示例13: findReferences
import org.motechproject.mds.service.MotechDataService; //导入依赖的package包/类
public List<Object> findReferences(AbstractID o, Class c, final Field f) throws ReflectiveOperationException {
final Object id = o.getId();
FilterValue filterValue = new FilterValue() {
@Override
public Object valueForQuery() {
return id;
}
@Override
public String paramTypeForQuery() {
return Long.class.getName();
}
@Override
public List<String> operatorForQueryFilter() {
return f.getGenericType() instanceof ParameterizedType
? Arrays.asList(".contains(", ")") : Arrays.asList("==");
}
};
Filter filter = new Filter(f.getName(), new FilterValue[]{filterValue});
MotechDataService dataService = DataServiceHelper.getDataService(bundleContext, c.getName());
return dataService.filter(new Filters(filter), null);
}
示例14: generateDummyInstances
import org.motechproject.mds.service.MotechDataService; //导入依赖的package包/类
@Override
public void generateDummyInstances(Long entityId, int numberOfInstances,
int numberOfHistoricalRevisions, int numberOfTrashInstances)
throws ClassNotFoundException, IllegalAccessException, InstantiationException {
Bundle entitiesBundle = OsgiBundleUtils.findBundleBySymbolicName(bundleContext, MDS_ENTITIES_SYMBOLIC_NAME);
MotechDataService service = getService(entitiesBundle.getBundleContext(), getEntityClassName(entityId));
makeInstances(service, entityId, numberOfInstances, numberOfHistoricalRevisions, numberOfTrashInstances);
}
示例15: getService
import org.motechproject.mds.service.MotechDataService; //导入依赖的package包/类
@Override
public MotechDataService getService(BundleContext bundleContext, String className) {
String interfaceName = MotechClassPool.getInterfaceName(className);
ServiceReference ref = bundleContext.getServiceReference(interfaceName);
if (ref == null) {
throw new ServiceNotFoundException(interfaceName);
}
return (MotechDataService) bundleContext.getService(ref);
}