Search in sources :

Example 31 with Entity

use of org.motechproject.mds.domain.Entity in project motech by motech.

the class AllEntityDraftsContextIT method shouldNotAllowTwoDraftsOfTheSameEntityForOneUser.

@Test(expected = JDOException.class)
public void shouldNotAllowTwoDraftsOfTheSameEntityForOneUser() {
    EntityDto dto = new EntityDto();
    dto.setClassName("DraftCls2");
    Entity entity = allEntities.create(dto);
    allEntityDrafts.create(entity, USERNAME);
    allEntityDrafts.create(entity, USERNAME);
}
Also used : EntityDto(org.motechproject.mds.dto.EntityDto) Entity(org.motechproject.mds.domain.Entity) Test(org.junit.Test)

Example 32 with Entity

use of org.motechproject.mds.domain.Entity in project motech by motech.

the class EntityServiceContextIT method testDraftWorkflow.

@Test
public void testDraftWorkflow() throws IOException {
    EntityDto entityDto = new EntityDto();
    entityDto.setName("DraftTest");
    entityDto = entityService.createEntity(entityDto);
    final Long entityId = entityDto.getId();
    entityService.saveDraftEntityChanges(entityId, DraftBuilder.forNewField("disp", "f1name", Long.class.getName()));
    List<FieldDto> fields = entityService.getFields(entityId);
    assertNotNull(fields);
    assertEquals(asList("id", "creator", "owner", "modifiedBy", "creationDate", "modificationDate", "f1name"), extract(fields, on(FieldDto.class).getBasic().getName()));
    // check if abandoning works
    entityService.abandonChanges(entityId);
    fields = entityService.getFields(entityId);
    assertNotNull(fields);
    assertEquals(asList("id", "creator", "owner", "modifiedBy", "creationDate", "modificationDate"), extract(fields, on(FieldDto.class).getBasic().getName()));
    // check add-edit-commit
    entityService.saveDraftEntityChanges(entityId, DraftBuilder.forNewField("disp", "f1name", Long.class.getName()));
    fields = entityService.getFields(entityId);
    assertNotNull(fields);
    assertEquals(7, fields.size());
    FieldDto field = selectFirst(fields, having(on(FieldDto.class).getBasic().getName(), equalTo("f1name")));
    entityService.saveDraftEntityChanges(entityDto.getId(), DraftBuilder.forFieldEdit(field.getId(), "basic.displayName", "newDisp"));
    fields = entityService.getFields(entityId);
    assertNotNull(fields);
    assertEquals(asList("Id", "Created By", "Owner", "Modified By", "Creation Date", "Modification Date", "newDisp"), extract(fields, on(FieldDto.class).getBasic().getDisplayName()));
    entityService.commitChanges(entityId);
    // check if changes were persisted in db
    Entity entityFromDb = getEntities().get(0);
    assertEquals(7, entityFromDb.getFields().size());
    Field fieldFromDb = entityFromDb.getField("f1name");
    assertNotNull(fieldFromDb);
    assertEquals("newDisp", fieldFromDb.getDisplayName());
    // no drafts in db
    assertTrue(entityService.listWorkInProgress().isEmpty());
}
Also used : EntityDto(org.motechproject.mds.dto.EntityDto) Entity(org.motechproject.mds.domain.Entity) Field(org.motechproject.mds.domain.Field) LookupFieldDto(org.motechproject.mds.dto.LookupFieldDto) FieldDto(org.motechproject.mds.dto.FieldDto) Test(org.junit.Test)

Example 33 with Entity

use of org.motechproject.mds.domain.Entity in project motech by motech.

the class UserPreferencesServiceImpl method unselectField.

@Override
@Transactional
public void unselectField(Long id, String username, String fieldName) {
    Entity entity = getEntity(id);
    UserPreferences userPreferences = allUserPreferences.retrieveByClassNameAndUsername(entity.getClassName(), username);
    userPreferences = checkPreferences(userPreferences, entity, username);
    Field field = entity.getField(fieldName);
    assertField(field, entity.getClassName(), fieldName);
    userPreferences.unselectField(field);
    allUserPreferences.update(userPreferences);
}
Also used : UserPreferences(org.motechproject.mds.domain.UserPreferences) AllUserPreferences(org.motechproject.mds.repository.internal.AllUserPreferences) Entity(org.motechproject.mds.domain.Entity) Field(org.motechproject.mds.domain.Field) Transactional(org.springframework.transaction.annotation.Transactional)

Example 34 with Entity

use of org.motechproject.mds.domain.Entity in project motech by motech.

the class AllEntitiesContextIT method shouldCascadeDeleteLookups.

@Test
public void shouldCascadeDeleteLookups() {
    Query query = getPersistenceManager().newQuery(Entity.class);
    query.setFilter("className == name");
    query.declareParameters("java.lang.String name");
    query.setUnique(true);
    Entity found = (Entity) query.execute(EXAMPLE_CLASS_WITH_LOOKUPS);
    List<Lookup> lookups = new ArrayList<>(found.getLookups());
    allEntities.delete(found.getId());
    assertFalse("Lookup was not deleted", getLookups().contains(lookups.get(0)));
    assertFalse("Lookup was not deleted", getLookups().contains(lookups.get(1)));
}
Also used : Entity(org.motechproject.mds.domain.Entity) Query(javax.jdo.Query) ArrayList(java.util.ArrayList) Lookup(org.motechproject.mds.domain.Lookup) Test(org.junit.Test)

Example 35 with Entity

use of org.motechproject.mds.domain.Entity in project motech by motech.

the class AllEntitiesContextIT method shouldCascadeSaveLookup.

@Test
public void shouldCascadeSaveLookup() throws Exception {
    Lookup lookup = new Lookup(SAMPLE_LOOKUP, true, false, null);
    Entity entity = getEntities().get(0);
    List<Lookup> lookupSet = new LinkedList<>();
    lookupSet.add(lookup);
    entity.setLookups(lookupSet);
    int indexOfLookup = getLookups().indexOf(lookup);
    assertTrue(String.format("'%s' not found in database", SAMPLE_LOOKUP), indexOfLookup >= 0);
    assertEquals("Lookup was not associated with an entity", entity, getLookups().get(indexOfLookup).getEntity());
}
Also used : Entity(org.motechproject.mds.domain.Entity) Lookup(org.motechproject.mds.domain.Lookup) LinkedList(java.util.LinkedList) Test(org.junit.Test)

Aggregations

Entity (org.motechproject.mds.domain.Entity)97 Test (org.junit.Test)35 Field (org.motechproject.mds.domain.Field)33 MdsEntity (org.motechproject.mds.domain.MdsEntity)32 MdsVersionedEntity (org.motechproject.mds.domain.MdsVersionedEntity)32 Transactional (org.springframework.transaction.annotation.Transactional)32 ArrayList (java.util.ArrayList)14 Lookup (org.motechproject.mds.domain.Lookup)12 UserPreferences (org.motechproject.mds.domain.UserPreferences)8 Type (org.motechproject.mds.domain.Type)7 AllUserPreferences (org.motechproject.mds.repository.internal.AllUserPreferences)7 EntityDto (org.motechproject.mds.dto.EntityDto)6 LookupFieldDto (org.motechproject.mds.dto.LookupFieldDto)6 HashMap (java.util.HashMap)5 FieldDto (org.motechproject.mds.dto.FieldDto)5 HashSet (java.util.HashSet)4 EntityDraft (org.motechproject.mds.domain.EntityDraft)4 MotechDataService (org.motechproject.mds.service.MotechDataService)4 Query (javax.jdo.Query)3 FieldSetting (org.motechproject.mds.domain.FieldSetting)3