use of com.qcadoo.model.api.types.HasManyType in project qcadoo by qcadoo.
the class EntityServiceImpl method getHasManyField.
private Object getHasManyField(final Object databaseEntity, final FieldDefinition fieldDefinition) {
Long parentId = getId(databaseEntity);
HasManyType hasManyFieldType = (HasManyType) fieldDefinition.getType();
InternalDataDefinition referencedDataDefinition = (InternalDataDefinition) hasManyFieldType.getDataDefinition();
return new EntityListImpl(referencedDataDefinition, hasManyFieldType.getJoinFieldName(), parentId);
}
use of com.qcadoo.model.api.types.HasManyType in project qcadoo by qcadoo.
the class GridComponentStateTest method init.
@Before
public void init() throws Exception {
JSONObject jsonContent = new JSONObject();
jsonContent.put(GridComponentState.JSON_SELECTED_ENTITY_ID, 13L);
jsonContent.put(GridComponentState.JSON_MULTISELECT_MODE, false);
JSONObject jsonSelected = new JSONObject();
jsonSelected.put("13", true);
jsonContent.put(GridComponentState.JSON_SELECTED_ENTITIES, jsonSelected);
jsonContent.put(GridComponentState.JSON_BELONGS_TO_ENTITY_ID, 1L);
jsonContent.put(GridComponentState.JSON_FIRST_ENTITY, 60);
jsonContent.put(GridComponentState.JSON_MAX_ENTITIES, 30);
jsonContent.put(GridComponentState.JSON_FILTERS_ENABLED, true);
JSONArray jsonOrder = new JSONArray();
jsonOrder.put(ImmutableMap.of("column", "asd", "direction", "asc"));
jsonContent.put(GridComponentState.JSON_ORDER, jsonOrder);
JSONObject jsonFilters = new JSONObject();
jsonFilters.put("asd", "test");
jsonFilters.put("qwe", "test2");
jsonContent.put(GridComponentState.JSON_FILTERS, jsonFilters);
json = new JSONObject(Collections.singletonMap(AbstractComponentState.JSON_CONTENT, jsonContent));
Entity entity = mock(Entity.class);
given(entity.getField("name")).willReturn("text");
viewDefinitionState = mock(ViewDefinitionState.class);
productDataDefinition = mock(DataDefinition.class, RETURNS_DEEP_STUBS);
substituteDataDefinition = mock(DataDefinition.class, "substituteDataDefinition");
HasManyType substitutesFieldType = mock(HasManyType.class);
given(substitutesFieldType.getDataDefinition()).willReturn(substituteDataDefinition);
given(substitutesFieldType.getJoinFieldName()).willReturn("product");
substitutesFieldDefinition = mock(FieldDefinition.class);
given(substitutesFieldDefinition.getType()).willReturn(substitutesFieldType);
given(substitutesFieldDefinition.getName()).willReturn("substitutes");
given(substitutesFieldDefinition.getDataDefinition()).willReturn(substituteDataDefinition);
substituteCriteria = mock(SearchCriteriaBuilder.class);
given(substituteDataDefinition.getPluginIdentifier()).willReturn("plugin");
given(substituteDataDefinition.getName()).willReturn("substitute");
given(substituteDataDefinition.find()).willReturn(substituteCriteria);
given(productDataDefinition.getPluginIdentifier()).willReturn("plugin");
given(productDataDefinition.getName()).willReturn("product");
given(productDataDefinition.getField("substitutes")).willReturn(substitutesFieldDefinition);
columns = new LinkedHashMap<String, GridComponentColumn>();
TranslationService translationService = mock(TranslationService.class);
given(translationService.translate(Mockito.anyString(), Mockito.any(Locale.class))).willReturn("i18n");
given(translationService.translate(Mockito.anyString(), Mockito.anyString(), Mockito.any(Locale.class))).willReturn("i18n");
given(translationService.translate(Mockito.anyString(), Mockito.any(Locale.class))).willReturn("i18n");
GridComponentPattern pattern = mock(GridComponentPattern.class);
given(pattern.getColumns()).willReturn(columns);
given(pattern.getBelongsToFieldDefinition()).willReturn(substitutesFieldDefinition);
given(pattern.isActivable()).willReturn(false);
given(pattern.isWeakRelation()).willReturn(false);
ApplicationContext applicationContext = mock(ApplicationContext.class);
setField(pattern, "applicationContext", applicationContext);
SecurityRolesService securityRolesService = mock(SecurityRolesService.class);
given(applicationContext.getBean(SecurityRolesService.class)).willReturn(securityRolesService);
grid = new GridComponentState(productDataDefinition, pattern);
grid.setDataDefinition(substituteDataDefinition);
grid.setTranslationService(translationService);
new ExpressionServiceImpl().init();
}
use of com.qcadoo.model.api.types.HasManyType in project qcadoo by qcadoo.
the class GridComponentPatternTest method shouldHaveScopeFieldName.
@Test
public void shouldHaveScopeFieldName() throws Exception {
// given
DataDefinition dataDefinition = mock(DataDefinition.class);
BelongsToType belongsToFieldType = mock(BelongsToType.class);
FieldDefinition belongsToFieldDefinition = mock(FieldDefinition.class);
given(belongsToFieldDefinition.getName()).willReturn("joinName");
given(belongsToFieldDefinition.getType()).willReturn(belongsToFieldType);
given(belongsToFieldDefinition.getDataDefinition()).willReturn(dataDefinition);
HasManyType hasManyFieldType = mock(HasManyType.class);
given(hasManyFieldType.getJoinFieldName()).willReturn("joinName");
given(hasManyFieldType.getDataDefinition()).willReturn(dataDefinition);
FieldDefinition hasManyFieldDefinition = mock(FieldDefinition.class);
given(hasManyFieldDefinition.getName()).willReturn("fieldName");
given(hasManyFieldDefinition.getType()).willReturn(hasManyFieldType);
given(hasManyFieldDefinition.getDataDefinition()).willReturn(dataDefinition);
given(dataDefinition.getField("field")).willReturn(hasManyFieldDefinition);
given(dataDefinition.getField("joinName")).willReturn(belongsToFieldDefinition);
InternalViewDefinition viewDefinition = mock(InternalViewDefinition.class);
AbstractComponentPattern sourceComponent = new TextInputComponentPattern(getComponentDefinition("component", viewDefinition));
setField(sourceComponent, "dataDefinition", dataDefinition);
setField(sourceComponent, "initialized", true);
given(viewDefinition.getComponentByReference("component")).willReturn(sourceComponent);
ComponentDefinition componentDefinition = getComponentDefinition(QcadooViewConstants.L_GRID, null, "#{component}.field", null, viewDefinition);
componentDefinition.setTranslationService(translationService);
componentDefinition.setApplicationContext(applicationContext);
GridComponentPattern pattern = new GridComponentPattern(componentDefinition);
pattern.addOption(new ComponentOption("order", ImmutableMap.of("column", "name", "direction", "asc")));
// when
pattern.initialize();
// then
JSONObject options = getJsOptions(pattern);
assertEquals("joinName", options.getString("belongsToFieldName"));
}
use of com.qcadoo.model.api.types.HasManyType in project qcadoo by qcadoo.
the class GridComponentPatternTest method shouldReturnState.
@Test
public void shouldReturnState() throws Exception {
// given
InternalViewDefinitionState viewDefinitionState = mock(InternalViewDefinitionState.class);
DataDefinition dataDefinition = mock(DataDefinition.class);
BelongsToType belongsToFieldType = mock(BelongsToType.class);
FieldDefinition belongsToFieldDefinition = mock(FieldDefinition.class);
given(belongsToFieldDefinition.getName()).willReturn("joinName");
given(belongsToFieldDefinition.getType()).willReturn(belongsToFieldType);
HasManyType hasManyFieldType = mock(HasManyType.class);
given(hasManyFieldType.getJoinFieldName()).willReturn("joinName");
given(hasManyFieldType.getDataDefinition()).willReturn(dataDefinition);
FieldDefinition hasManyFieldDefinition = mock(FieldDefinition.class);
given(hasManyFieldDefinition.getName()).willReturn("fieldName");
given(hasManyFieldDefinition.getType()).willReturn(hasManyFieldType);
given(dataDefinition.getField("field")).willReturn(hasManyFieldDefinition);
given(dataDefinition.getField("joinName")).willReturn(belongsToFieldDefinition);
InternalViewDefinition viewDefinition = mock(InternalViewDefinition.class);
AbstractComponentPattern sourceComponent = new TextInputComponentPattern(getComponentDefinition("component", viewDefinition));
setField(sourceComponent, "dataDefinition", dataDefinition);
setField(sourceComponent, "initialized", true);
given(viewDefinition.getComponentByReference("component")).willReturn(sourceComponent);
ComponentDefinition componentDefinition = getComponentDefinition(QcadooViewConstants.L_GRID, null, "#{component}.field", null, viewDefinition);
componentDefinition.setTranslationService(translationService);
componentDefinition.setApplicationContext(applicationContext);
GridComponentPattern pattern = new GridComponentPattern(componentDefinition);
pattern.addOption(new ComponentOption("order", ImmutableMap.of("column", "name", "direction", "asc")));
pattern.initialize();
// when
ComponentState state = pattern.createComponentState(viewDefinitionState);
// then
assertTrue(state instanceof GridComponent);
assertEquals(belongsToFieldDefinition, getField(state, "belongsToFieldDefinition"));
assertEquals(getField(pattern, "columns"), getField(state, "columns"));
}
use of com.qcadoo.model.api.types.HasManyType in project qcadoo by qcadoo.
the class InitializationTest method shouldGetDataDefinitionFromHasManyTypeFieldDefinition.
@Test
public void shouldGetDataDefinitionFromHasManyTypeFieldDefinition() throws Exception {
// given
HasManyType fieldType = mock(HasManyType.class);
FieldDefinition fieldDefinition = mock(FieldDefinition.class);
given(fieldDefinition.getType()).willReturn(fieldType);
DataDefinition dataDefinition = mock(DataDefinition.class);
given(dataDefinition.getField("field")).willReturn(fieldDefinition);
DataDefinition belongsToDefinition = mock(DataDefinition.class);
given(fieldType.getDataDefinition()).willReturn(belongsToDefinition);
InternalViewDefinition viewDefinition = mock(InternalViewDefinition.class);
AbstractContainerPattern parent = new WindowComponentPattern(getComponentDefinition("parent", viewDefinition));
setField(parent, "dataDefinition", dataDefinition);
setField(parent, "initialized", true);
AbstractComponentPattern pattern = new TextInputComponentPattern(getComponentDefinition("test", "field", null, parent, viewDefinition));
// when
pattern.initialize();
// then
Assert.assertEquals(belongsToDefinition, getField(pattern, "dataDefinition"));
Assert.assertEquals(fieldDefinition, getField(pattern, "fieldDefinition"));
}
Aggregations