示例#1
0
  @Override
  public long countTrashRecords(Long entityId) {
    EntityDto entity = getEntity(entityId);
    validateCredentialsForReading(entity);

    return trashService.countTrashRecords(entity.getClassName());
  }
示例#2
0
  @Override
  public EntityRecord getSingleTrashRecord(Long entityId, Long instanceId) {
    EntityDto entity = getEntity(entityId);
    validateCredentialsForReading(entity);

    MotechDataService service = getServiceForEntity(entity);
    List<FieldDto> fields = entityService.getEntityFields(entityId);
    Object instance = trashService.findTrashById(instanceId, entityId);

    return instanceToRecord(instance, entity, fields, service);
  }
示例#3
0
  @Override
  public List<EntityRecord> getTrashRecords(Long entityId, QueryParams queryParams) {
    EntityDto entity = getEntity(entityId);
    validateCredentialsForReading(entity);

    MotechDataService service = getServiceForEntity(entity);
    List<FieldDto> fields = entityService.getEntityFields(entityId);
    Collection collection = trashService.getInstancesFromTrash(entity.getClassName(), queryParams);

    return instancesToRecords(collection, entity, fields, service);
  }
示例#4
0
  @Test
  public void shouldReturnInstancesFromTrash() {
    mockDataService();
    mockSampleFields();
    mockEntity();
    QueryParams queryParams = new QueryParams(1, 10);
    when(trashService.getInstancesFromTrash(anyString(), eq(queryParams)))
        .thenReturn(sampleCollection());

    List<BasicEntityRecord> records = instanceService.getTrashRecords(ENTITY_ID, queryParams);
    verify(trashService).getInstancesFromTrash(anyString(), eq(queryParams));
    assertNotNull(records);
    assertEquals(records.size(), 1);

    // Make sure all fields that were in the instance are still available
    assertEquals(records.get(0).getFields().size(), 5);

    // should not perform update when username is null or blank
    verify(userPreferencesService, never()).updateGridSize(anyLong(), anyString(), anyInt());
  }