use of com.qcadoo.model.api.types.BelongsToType in project qcadoo by qcadoo.
the class EntityTreeImplTest method shouldFailIfThereIsNoRoot.
@Test(expected = IllegalStateException.class)
public void shouldFailIfThereIsNoRoot() throws Exception {
// given
Entity entity = mock(Entity.class);
given(entity.getBelongsToField("parent")).willReturn(entity);
List<Entity> entities = Collections.singletonList(entity);
BelongsToType fieldType = mock(BelongsToType.class);
InternalDataDefinition dataDefinition = mock(InternalDataDefinition.class, RETURNS_DEEP_STUBS);
given(fieldType.getDataDefinition()).willReturn(dataDefinition);
FieldDefinition fieldDefinition = mock(FieldDefinition.class);
given(fieldDefinition.getType()).willReturn(fieldType);
given(fieldDefinition.getName()).willReturn("field");
given(dataDefinition.getField("tree")).willReturn(fieldDefinition);
given(dataDefinition.find().add(SearchRestrictions.belongsTo("field", dataDefinition, 1L)).addOrder(SearchOrders.asc("priority")).list().getEntities()).willReturn(entities);
EntityTreeImpl tree = new EntityTreeImpl(dataDefinition, "tree", 1L);
// when
tree.size();
}
use of com.qcadoo.model.api.types.BelongsToType in project qcadoo by qcadoo.
the class ViewDefinitionParserImplTest method init.
@Before
public void init() throws Exception {
applicationContext = mock(ApplicationContext.class);
dataDefinitionService = mock(DataDefinitionService.class);
translationService = mock(TranslationService.class);
RibbonParserService ribbonService = new RibbonParserService();
contextualHelpService = mock(ContextualHelpService.class);
securityRolesService = mock(SecurityRolesService.class);
viewDefinitionService = new ViewDefinitionServiceImpl();
hookFactory = new HookFactory();
setField(hookFactory, "applicationContext", applicationContext);
viewDefinitionParser = new ViewDefinitionParserImpl();
setField(viewDefinitionParser, "dataDefinitionService", dataDefinitionService);
setField(viewDefinitionParser, "viewDefinitionService", viewDefinitionService);
setField(viewDefinitionParser, "hookFactory", hookFactory);
setField(viewDefinitionParser, "translationService", translationService);
setField(viewDefinitionParser, "applicationContext", applicationContext);
setField(viewDefinitionParser, "contextualHelpService", contextualHelpService);
setField(viewDefinitionParser, "viewComponentsResolver", viewComponentsResolver);
setField(viewDefinitionParser, "ribbonService", ribbonService);
setField(viewDefinitionParser, "securityRolesService", securityRolesService);
userRoleMock = mock(SecurityRole.class);
given(securityRolesService.getRoleByIdentifier("ROLE_USER")).willReturn(userRoleMock);
adminRoleMock = mock(SecurityRole.class);
given(securityRolesService.getRoleByIdentifier("ROLE_ADMIN")).willReturn(adminRoleMock);
xml1 = "view/test1.xml";
xml2 = "view/test2.xml";
given(applicationContext.getBean(CustomViewService.class)).willReturn(new CustomViewService());
dataDefinitionA = mock(DataDefinition.class);
dataDefinitionB = mock(DataDefinition.class);
FieldDefinition nameA = mock(FieldDefinition.class, "nameA");
FieldDefinition nameB = mock(FieldDefinition.class, "nameB");
FieldDefinition hasManyB = mock(FieldDefinition.class, "hasManyB");
FieldDefinition belongToA = mock(FieldDefinition.class, "belongsToA");
HasManyType hasManyBType = mock(HasManyType.class);
BelongsToType belongToAType = mock(BelongsToType.class);
given(nameA.getDataDefinition()).willReturn(dataDefinitionA);
given(nameA.getType()).willReturn(new StringType());
given(nameB.getType()).willReturn(new StringType());
given(nameB.getDataDefinition()).willReturn(dataDefinitionA);
given(hasManyB.getType()).willReturn(hasManyBType);
given(hasManyB.getDataDefinition()).willReturn(dataDefinitionB);
given(belongToA.getType()).willReturn(belongToAType);
given(belongToA.getDataDefinition()).willReturn(dataDefinitionB);
given(hasManyBType.getDataDefinition()).willReturn(dataDefinitionB);
given(belongToAType.getDataDefinition()).willReturn(dataDefinitionA);
given(dataDefinitionA.getField("beansB")).willReturn(hasManyB);
given(dataDefinitionA.getField("name")).willReturn(nameA);
given(dataDefinitionB.getField("activeA")).willReturn(nameA);
given(dataDefinitionB.getField("activeB")).willReturn(nameA);
given(dataDefinitionB.getField("activeC")).willReturn(nameA);
given(dataDefinitionB.getField("beanA")).willReturn(belongToA);
given(dataDefinitionB.getField("beanM")).willReturn(belongToA);
given(dataDefinitionB.getField("beanB")).willReturn(belongToA);
given(dataDefinitionB.getField("name")).willReturn(nameB);
given(dataDefinitionA.getName()).willReturn("beanA");
given(dataDefinitionB.getName()).willReturn("beanB");
given(dataDefinitionA.getFields()).willReturn(ImmutableMap.of("name", nameA, "beansB", hasManyB));
given(dataDefinitionB.getFields()).willReturn(ImmutableMap.of("name", nameB, "beanA", belongToA));
given(dataDefinitionService.get("sample", "beanA")).willReturn(dataDefinitionA);
given(dataDefinitionService.get("sample", "beanB")).willReturn(dataDefinitionB);
}
use of com.qcadoo.model.api.types.BelongsToType in project mes by qcadoo.
the class BatchUtil method checkField.
private static void checkField(final DataDefinition dataDef, final String fieldName) {
FieldDefinition fd = dataDef.getField(fieldName);
if (fd.getType() instanceof BelongsToType) {
BelongsToType btType = (BelongsToType) fd.getType();
DataDefinition dd = btType.getDataDefinition();
if (AdvancedGenealogyConstants.PLUGIN_IDENTIFIER.equals(dd.getPluginIdentifier()) && AdvancedGenealogyConstants.MODEL_BATCH.equals(dd.getName())) {
return;
}
}
throw new IllegalArgumentException(String.format("Field '%s' should be of type belongsTo, pointing to the advanced genealogy's batch entity!", fieldName));
}
use of com.qcadoo.model.api.types.BelongsToType in project qcadoo by qcadoo.
the class DefaultEntityTest method init.
@Before
public final void init() {
belongsToFieldDefinition = mock(FieldDefinition.class);
final BelongsToType belongsToType = mock(BelongsToType.class);
when(belongsToFieldDefinition.getType()).thenReturn(belongsToType);
belongsToFieldDataDefinition = mock(DataDefinition.class);
when(belongsToFieldDefinition.getDataDefinition()).thenReturn(belongsToFieldDataDefinition);
decimalFieldDefinition = mock(FieldDefinition.class);
final DecimalType decimalType = new DecimalType();
when(decimalFieldDefinition.getType()).thenReturn(decimalType);
integerFieldDefinition = mock(FieldDefinition.class);
final IntegerType integerType = new IntegerType();
when(integerFieldDefinition.getType()).thenReturn(integerType);
manyToManyFieldDefinition = mock(FieldDefinition.class);
final ManyToManyType manyToManyType = mock(ManyToManyType.class);
when(manyToManyFieldDefinition.getType()).thenReturn(manyToManyType);
manyToManyDataDefinition = mock(DataDefinition.class);
when(manyToManyFieldDefinition.getDataDefinition()).thenReturn(manyToManyDataDefinition);
secondManyToManyFieldDefinition = mock(FieldDefinition.class);
when(secondManyToManyFieldDefinition.getType()).thenReturn(manyToManyType);
secondManyToManyDataDefinition = mock(DataDefinition.class);
when(secondManyToManyFieldDefinition.getDataDefinition()).thenReturn(secondManyToManyDataDefinition);
hasManyFieldDefinition = mock(FieldDefinition.class);
final HasManyType hasManyType = mock(HasManyType.class);
when(hasManyType.getJoinFieldName()).thenReturn(BELONGS_TO_FIELD_NAME);
when(hasManyFieldDefinition.getType()).thenReturn(hasManyType);
hasManyDataDefinition = mock(DataDefinition.class);
when(hasManyFieldDefinition.getDataDefinition()).thenReturn(hasManyDataDefinition);
stringFieldDefinition = mock(FieldDefinition.class);
when(stringFieldDefinition.isPersistent()).thenReturn(false);
dataDefinition = mock(DataDefinition.class);
booleanFieldDefinition = mock(FieldDefinition.class);
defaultEntity = new DefaultEntity(dataDefinition);
final Map<String, FieldDefinition> fieldsMap = Maps.newHashMap();
fieldsMap.put(BELONGS_TO_FIELD_NAME, belongsToFieldDefinition);
fieldsMap.put(STRING_FIELD_NAME, stringFieldDefinition);
fieldsMap.put(BOOLEAN_FIELD_NAME, booleanFieldDefinition);
fieldsMap.put(DECIMAL_FIELD_NAME, decimalFieldDefinition);
fieldsMap.put(INTEGER_FIELD_NAME, integerFieldDefinition);
fieldsMap.put(MANY_TO_MANY_FIELD_NAME, manyToManyFieldDefinition);
fieldsMap.put(SECOND_MANY_TO_MANY_FIELD_NAME, secondManyToManyFieldDefinition);
fieldsMap.put(HAS_MANY_FIELD_NAME, hasManyFieldDefinition);
for (Map.Entry<String, FieldDefinition> fieldEntry : fieldsMap.entrySet()) {
when(dataDefinition.getField(fieldEntry.getKey())).thenReturn(fieldEntry.getValue());
}
when(dataDefinition.getFields()).thenReturn(fieldsMap);
}
use of com.qcadoo.model.api.types.BelongsToType in project qcadoo by qcadoo.
the class DefaultEntity method getProxyForBelongsToField.
private Entity getProxyForBelongsToField(final String fieldName) {
BelongsToType belongsToType = (BelongsToType) dataDefinition.getField(fieldName).getType();
Long belongsToEntityId = ((Number) getField(fieldName)).longValue();
return new ProxyEntity(belongsToType.getDataDefinition(), belongsToEntityId);
}
Aggregations