Search in sources :

Example 6 with TranslationService

use of com.qcadoo.localization.api.TranslationService in project qcadoo by qcadoo.

the class FormComponentStateTest method shouldRenderFormEntityId.

@Test
public void shouldRenderFormEntityId() throws Exception {
    // given
    TranslationService translationService = mock(TranslationService.class);
    DataDefinition dataDefinition = mock(DataDefinition.class);
    FormComponentPattern pattern = mock(FormComponentPattern.class);
    given(pattern.getExpressionNew()).willReturn(null);
    given(pattern.getExpressionEdit()).willReturn("2");
    setField(pattern, "applicationContext", applicationContext);
    AbstractComponentState componentState = new FormComponentState(pattern);
    componentState.setTranslationService(translationService);
    componentState.setDataDefinition(dataDefinition);
    componentState.setFieldValue(13L);
    componentState.initialize(new JSONObject(ImmutableMap.of("components", new JSONObject())), Locale.ENGLISH);
    // when
    JSONObject json = componentState.render();
    // then
    assertEquals(13L, json.getJSONObject(AbstractComponentState.JSON_CONTENT).getLong(FormComponentState.JSON_ENTITY_ID));
}
Also used : FormComponentPattern(com.qcadoo.view.internal.components.form.FormComponentPattern) JSONObject(org.json.JSONObject) TranslationService(com.qcadoo.localization.api.TranslationService) AbstractComponentState(com.qcadoo.view.internal.states.AbstractComponentState) DataDefinition(com.qcadoo.model.api.DataDefinition) FormComponentState(com.qcadoo.view.internal.components.form.FormComponentState) AbstractStateTest(com.qcadoo.view.internal.states.AbstractStateTest) Test(org.junit.Test)

Example 7 with TranslationService

use of com.qcadoo.localization.api.TranslationService 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);
}
Also used : SecurityRole(com.qcadoo.security.api.SecurityRole) CustomViewService(com.qcadoo.view.beans.sample.CustomViewService) StringType(com.qcadoo.model.internal.types.StringType) ViewDefinitionServiceImpl(com.qcadoo.view.internal.ViewDefinitionServiceImpl) FieldDefinition(com.qcadoo.model.api.FieldDefinition) DataDefinitionService(com.qcadoo.model.api.DataDefinitionService) DataDefinition(com.qcadoo.model.api.DataDefinition) RibbonParserService(com.qcadoo.view.internal.ribbon.RibbonParserService) ApplicationContext(org.springframework.context.ApplicationContext) HasManyType(com.qcadoo.model.api.types.HasManyType) BelongsToType(com.qcadoo.model.api.types.BelongsToType) TranslationService(com.qcadoo.localization.api.TranslationService) SecurityRolesService(com.qcadoo.security.api.SecurityRolesService) Before(org.junit.Before)

Example 8 with TranslationService

use of com.qcadoo.localization.api.TranslationService in project qcadoo by qcadoo.

the class FieldTypeFactoryTest method shouldReturnEnumType.

@Test
public void shouldReturnEnumType() throws Exception {
    // given
    TranslationService translationService = mock(TranslationService.class);
    given(translationService.translate("path.value.val1", Locale.ENGLISH)).willReturn("i18nVal1");
    given(translationService.translate("path.value.val2", Locale.ENGLISH)).willReturn("i18nVal2");
    given(translationService.translate("path.value.val3", Locale.ENGLISH)).willReturn("i18nVal3");
    // when
    EnumeratedType fieldType = new EnumType(translationService, "path", true, "val1", "val2", "val3");
    // then
    assertEquals(fieldType.activeValues(Locale.ENGLISH).keySet(), Sets.newHashSet("val1", "val2", "val3"));
    assertEquals(Lists.newArrayList(fieldType.activeValues(Locale.ENGLISH).values()), Lists.newArrayList("i18nVal1", "i18nVal2", "i18nVal3"));
    assertEquals(String.class, fieldType.getType());
    ValueAndError valueAndError1 = fieldType.toObject(fieldDefinition, "val1");
    ValueAndError valueAndError2 = fieldType.toObject(fieldDefinition, "val4");
    assertTrue(valueAndError1.isValid());
    assertFalse(valueAndError2.isValid());
    assertNotNull(valueAndError1.getValue());
    assertNull(valueAndError2.getValue());
    assertEquals("qcadooView.validate.field.error.invalidDictionaryItem", valueAndError2.getMessage());
    assertEquals("[val1, val2, val3]", valueAndError2.getArgs()[0]);
}
Also used : ValueAndError(com.qcadoo.model.internal.api.ValueAndError) TranslationService(com.qcadoo.localization.api.TranslationService) EnumeratedType(com.qcadoo.model.api.types.EnumeratedType) EnumType(com.qcadoo.model.internal.types.EnumType) DataAccessTest(com.qcadoo.model.internal.DataAccessTest) Test(org.junit.Test)

Example 9 with TranslationService

use of com.qcadoo.localization.api.TranslationService in project mes by qcadoo.

the class AdvancedGenealogyPdfService method createDocumentPanelTable.

private PdfPTable createDocumentPanelTable(final Entity entity, final Locale locale) {
    final PdfPTable panel = pdfHelper.createPanelTable(2);
    final Entity batch = entity.getBelongsToField(GenealogyReportFields.BATCH);
    final TranslationService translation = translationService;
    String batchNumber = translation.translate(L_ADVANCED_GENEALOGY_BATCH_REPORT_BATCH_NUMBER_MESSAGE, locale) + AdvancedGenealogyConstants.L_SPACER + batch.getField(BatchFields.NUMBER);
    final StringBuilder type = new StringBuilder(translation.translate("advancedGenealogy.batch.report.type", locale)).append(AdvancedGenealogyConstants.L_SPACER);
    if (AdvancedGenealogyConstants.L_USED_TO_PRODUCE.equals(entity.getField(GenealogyReportFields.TYPE))) {
        type.append(translation.translate("advancedGenealogy.genealogyReport.type.value.01usedToProduce", locale));
    } else if (AdvancedGenealogyConstants.L_PRODUCED_FROM.equals(entity.getField(GenealogyReportFields.TYPE))) {
        type.append(translation.translate("advancedGenealogy.genealogyReport.type.value.02producedFrom", locale));
    } else {
        throw new IllegalStateException("Type of genealogy table should be specified");
    }
    final StringBuilder includeDraft = new StringBuilder(translation.translate("advancedGenealogy.batch.report.includeDraft", locale)).append(AdvancedGenealogyConstants.L_SPACER);
    if (entity.getBooleanField(GenealogyReportFields.INCLUDE_DRAFT)) {
        includeDraft.append(translation.translate("qcadooView.true", locale));
    } else {
        includeDraft.append(translation.translate("qcadooView.false", locale));
    }
    final StringBuilder directRelatedOnly = new StringBuilder(translation.translate("advancedGenealogy.batch.report.directRelatedOnly", locale)).append(AdvancedGenealogyConstants.L_SPACER);
    if (entity.getBooleanField(GenealogyReportFields.DIRECT_RELATED_ONLY)) {
        directRelatedOnly.append(translation.translate("qcadooView.true", locale));
    } else {
        directRelatedOnly.append(translation.translate("qcadooView.false", locale));
    }
    panel.addCell(new Phrase(batchNumber, FontUtils.getDejavuBold9Dark()));
    panel.addCell(new Phrase(type.toString(), FontUtils.getDejavuBold9Dark()));
    panel.addCell(new Phrase(includeDraft.toString(), FontUtils.getDejavuBold9Dark()));
    panel.addCell(new Phrase(directRelatedOnly.toString(), FontUtils.getDejavuBold9Dark()));
    return panel;
}
Also used : Entity(com.qcadoo.model.api.Entity) PdfPTable(com.lowagie.text.pdf.PdfPTable) TranslationService(com.qcadoo.localization.api.TranslationService)

Example 10 with TranslationService

use of com.qcadoo.localization.api.TranslationService in project qcadoo by qcadoo.

the class ModelXmlToDefinitionConverterTest method init.

@BeforeClass
public static void init() throws Exception {
    applicationContext = mock(ApplicationContext.class);
    dataAccessService = mock(DataAccessService.class);
    translationService = mock(TranslationService.class);
    dataDefinitionService = new DataDefinitionServiceImpl();
    modelXmlToDefinitionConverter = new ModelXmlToDefinitionConverterImpl();
    setField(modelXmlToDefinitionConverter, "dataDefinitionService", dataDefinitionService);
    setField(modelXmlToDefinitionConverter, "dataAccessService", dataAccessService);
    setField(modelXmlToDefinitionConverter, "applicationContext", applicationContext);
    setField(modelXmlToDefinitionConverter, "translationService", translationService);
    given(applicationContext.getBean(CustomHook.class)).willReturn(new CustomHook());
    modelXmlToClassConverter = new ModelXmlToClassConverterImpl();
    ((ModelXmlToClassConverterImpl) modelXmlToClassConverter).setBeanClassLoader(ClassLoader.getSystemClassLoader());
    dataDefinitions = performConvert(Utils.FULL_FIRST_ENTITY_XML_RESOURCE, Utils.FULL_SECOND_ENTITY_XML_RESOURCE, Utils.FULL_THIRD_ENTITY_XML_RESOURCE, Utils.OTHER_FIRST_ENTITY_XML_RESOURCE, Utils.OTHER_SECOND_ENTITY_XML_RESOURCE);
    for (DataDefinition dd : dataDefinitions.toArray(new DataDefinition[dataDefinitions.size()])) {
        if (dd.getName().equals("firstEntity") && dd.getPluginIdentifier().equals("full")) {
            dataDefinition = (InternalDataDefinition) dd;
        }
    }
}
Also used : CustomHook(com.qcadoo.model.CustomHook) ApplicationContext(org.springframework.context.ApplicationContext) TranslationService(com.qcadoo.localization.api.TranslationService) DataAccessService(com.qcadoo.model.internal.api.DataAccessService) DataDefinitionServiceImpl(com.qcadoo.model.internal.DataDefinitionServiceImpl) ModelXmlToClassConverterImpl(com.qcadoo.model.internal.classconverter.ModelXmlToClassConverterImpl) InternalDataDefinition(com.qcadoo.model.internal.api.InternalDataDefinition) DataDefinition(com.qcadoo.model.api.DataDefinition) BeforeClass(org.junit.BeforeClass)

Aggregations

TranslationService (com.qcadoo.localization.api.TranslationService)16 JSONObject (org.json.JSONObject)7 Test (org.junit.Test)7 ApplicationContext (org.springframework.context.ApplicationContext)7 DataDefinition (com.qcadoo.model.api.DataDefinition)6 Before (org.junit.Before)6 FormComponentPattern (com.qcadoo.view.internal.components.form.FormComponentPattern)5 Entity (com.qcadoo.model.api.Entity)4 FieldDefinition (com.qcadoo.model.api.FieldDefinition)4 ExpressionServiceImpl (com.qcadoo.model.internal.ExpressionServiceImpl)4 ComponentDefinition (com.qcadoo.view.internal.ComponentDefinition)4 InternalViewDefinition (com.qcadoo.view.internal.api.InternalViewDefinition)4 FormComponentState (com.qcadoo.view.internal.components.form.FormComponentState)4 SecurityRolesService (com.qcadoo.security.api.SecurityRolesService)3 HasManyType (com.qcadoo.model.api.types.HasManyType)2 DefaultEntity (com.qcadoo.model.internal.DefaultEntity)2 StringType (com.qcadoo.model.internal.types.StringType)2 SecurityRole (com.qcadoo.security.api.SecurityRole)2 ViewDefinitionState (com.qcadoo.view.api.ViewDefinitionState)2 Map (java.util.Map)2