use of org.motechproject.mds.domain.Lookup 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.Lookup 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());
}
use of org.motechproject.mds.domain.Lookup in project motech by motech.
the class AllEntitiesContextIT method shouldUpdateLookup.
@Test
public void shouldUpdateLookup() throws Exception {
Query query = getPersistenceManager().newQuery(Entity.class);
query.setFilter("className == name");
query.declareParameters("java.lang.String name");
query.setUnique(true);
Entity entity = (Entity) query.execute(EXAMPLE_CLASS_WITH_LOOKUPS);
for (Lookup lookup : entity.getLookups()) {
if (EXAMPLE_LOOKUP_1.equals(lookup.getLookupName())) {
lookup.setSingleObjectReturn(false);
} else if (EXAMPLE_LOOKUP_2.equals(lookup.getLookupName())) {
lookup.setExposedViaRest(true);
}
}
for (Lookup lookup : getLookups()) {
if (EXAMPLE_LOOKUP_1.equals(lookup.getLookupName())) {
assertEquals("Lookup was not updated properly", false, lookup.isSingleObjectReturn());
assertEquals("Lookup was not updated properly", false, lookup.isExposedViaRest());
} else if (EXAMPLE_LOOKUP_2.equals(lookup.getLookupName())) {
assertEquals("Lookup was not updated properly", true, lookup.isSingleObjectReturn());
assertEquals("Lookup was not updated properly", true, lookup.isExposedViaRest());
}
}
}
use of org.motechproject.mds.domain.Lookup in project motech by motech.
the class EntityValidator method validateEntityLookupsFieldsReferences.
private void validateEntityLookupsFieldsReferences(EntityDraft draft) {
Map<String, Lookup> draftLookups = new HashMap<>();
List<String> validateLookups = new ArrayList<>();
for (Lookup lookup : draft.getLookups()) {
draftLookups.put(lookup.getLookupName(), lookup);
}
for (Lookup lookup : draft.getParentEntity().getLookups()) {
Lookup draftLookup = draftLookups.get(lookup.getLookupName());
if (draftLookup == null || lookupFieldsChanged(lookup, draftLookup)) {
validateLookups.add(lookup.getLookupName());
}
}
validateLookupsReferences(validateLookups, draft.getClassName());
}
use of org.motechproject.mds.domain.Lookup in project motech by motech.
the class AllEntityDrafts method setProperties.
public void setProperties(EntityDraft draft, Entity entity, String username) {
draft.setParentEntity(entity);
draft.setParentVersion(entity.getEntityVersion());
draft.setDraftOwnerUsername(username);
draft.setLastModificationDate(DateUtil.nowUTC());
draft.setName(entity.getName());
draft.setClassName(entity.getClassName());
draft.setNamespace(entity.getNamespace());
draft.setModule(entity.getModule());
draft.setSecurityMode(entity.getSecurityMode());
draft.setSecurityMembers(new HashSet<>(entity.getSecurityMembers()));
draft.setReadOnlySecurityMode(entity.getReadOnlySecurityMode());
draft.setReadOnlySecurityMembers(new HashSet<>(entity.getReadOnlySecurityMembers()));
draft.getFields().clear();
for (Field field : entity.getFields()) {
draft.addField(field.copy());
}
draft.getLookups().clear();
for (Lookup lookup : entity.getLookups()) {
Lookup newLookup = lookup.copy(draft.getFields());
draft.addLookup(newLookup);
}
if (entity.getRestOptions() != null) {
RestOptions restOptions = entity.getRestOptions().copy();
restOptions.setEntity(draft);
draft.setRestOptions(restOptions);
}
if (entity.getTracking() != null) {
Tracking tracking = entity.getTracking().copy();
tracking.setEntity(draft);
draft.setTracking(tracking);
}
}
Aggregations