Search in sources :

Example 6 with MotechDataService

use of org.motechproject.mds.service.MotechDataService in project motech by motech.

the class InstanceServiceImpl method countRecordsWithFilters.

@Override
public long countRecordsWithFilters(Long entityId, Filters filters) {
    EntityDto entity = getEntity(entityId);
    validateCredentialsForReading(entity);
    MotechDataService service = getServiceForEntity(entity);
    return service.countForFilters(filters);
}
Also used : EntityDto(org.motechproject.mds.dto.EntityDto) MotechDataService(org.motechproject.mds.service.MotechDataService)

Example 7 with MotechDataService

use of org.motechproject.mds.service.MotechDataService in project motech by motech.

the class InstanceServiceImpl method deleteAllInstances.

@Override
public void deleteAllInstances(Long entityId) {
    EntityDto entity = getEntity(entityId);
    validateCredentials(entity);
    validateNonEditableProperty(entity);
    MotechDataService service = getServiceForEntity(entity);
    service.deleteAll();
}
Also used : EntityDto(org.motechproject.mds.dto.EntityDto) MotechDataService(org.motechproject.mds.service.MotechDataService)

Example 8 with MotechDataService

use of org.motechproject.mds.service.MotechDataService in project motech by motech.

the class InstanceServiceImpl method revertInstanceFromTrash.

@Override
public void revertInstanceFromTrash(Long entityId, Long instanceId) {
    EntityDto entity = getEntity(entityId);
    validateCredentials(entity);
    validateNonEditableProperty(entity);
    MotechDataService service = getServiceForEntity(entity);
    service.revertFromTrash(instanceId);
}
Also used : EntityDto(org.motechproject.mds.dto.EntityDto) MotechDataService(org.motechproject.mds.service.MotechDataService)

Example 9 with MotechDataService

use of org.motechproject.mds.service.MotechDataService in project motech by motech.

the class InstanceServiceImpl method getSingleTrashRecord.

@Override
public EntityRecord getSingleTrashRecord(Long entityId, Long instanceId) {
    EntityDto entity = getEntity(entityId);
    validateCredentialsForReading(entity);
    MotechDataService service = getServiceForEntity(entity);
    List<FieldDto> fields = entityService.getEntityFieldsForUI(entityId);
    Object instance = trashService.findTrashById(instanceId, entity.getClassName());
    Map<String, List<FieldDto>> relatedEntitiesFields = getRelatedEntitiesFields(fields);
    return instanceToRecord(instance, entity, fields, service, EntityType.TRASH, relatedEntitiesFields);
}
Also used : EntityDto(org.motechproject.mds.dto.EntityDto) ArrayList(java.util.ArrayList) List(java.util.List) MotechDataService(org.motechproject.mds.service.MotechDataService) FieldDto(org.motechproject.mds.dto.FieldDto)

Example 10 with MotechDataService

use of org.motechproject.mds.service.MotechDataService in project motech by motech.

the class DataServiceHelper method getDataService.

/**
 * Retrieves {@link org.motechproject.mds.service.MotechDataService} implementation for the
 * given entity class. It will throw {@link org.motechproject.mds.exception.entity.ServiceNotFoundException}, in
 * case a service for the given entity class cannot be found.
 *
 * @param bundleContext context of a bundle
 * @param entityClass fully qualified class name of an entity
 * @return generated {@link org.motechproject.mds.service.MotechDataService} implementation
 */
public static MotechDataService getDataService(BundleContext bundleContext, String entityClass) {
    String interfaceName = MotechClassPool.getInterfaceName(entityClass);
    MotechDataService dataService = OSGiServiceUtils.findService(bundleContext, interfaceName);
    if (dataService == null) {
        throw new ServiceNotFoundException(interfaceName);
    }
    return dataService;
}
Also used : ServiceNotFoundException(org.motechproject.mds.exception.entity.ServiceNotFoundException) MotechDataService(org.motechproject.mds.service.MotechDataService)

Aggregations

MotechDataService (org.motechproject.mds.service.MotechDataService)52 EntityDto (org.motechproject.mds.dto.EntityDto)26 FieldDto (org.motechproject.mds.dto.FieldDto)14 ArrayList (java.util.ArrayList)13 List (java.util.List)9 Test (org.junit.Test)8 Entity (org.motechproject.mds.domain.Entity)4 LookupDto (org.motechproject.mds.dto.LookupDto)4 ObjectNotFoundException (org.motechproject.mds.exception.object.ObjectNotFoundException)4 LookupExecutor (org.motechproject.mds.lookup.LookupExecutor)4 BasicEntityRecord (org.motechproject.mds.web.domain.BasicEntityRecord)4 Bundle (org.osgi.framework.Bundle)4 InvocationTargetException (java.lang.reflect.InvocationTargetException)3 Collection (java.util.Collection)3 LookupExecutionException (org.motechproject.mds.exception.lookup.LookupExecutionException)3 ObjectReadException (org.motechproject.mds.exception.object.ObjectReadException)3 DefaultMotechDataService (org.motechproject.mds.service.DefaultMotechDataService)3 EntityRecord (org.motechproject.mds.web.domain.EntityRecord)3 IOException (java.io.IOException)2 HashMap (java.util.HashMap)2