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);
}
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());
}
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);
}
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)));
}
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());
}
Aggregations