Search in sources :

Example 1 with TranslatableString

use of org.apache.isis.applib.services.i18n.TranslatableString in project estatio by estatio.

the class DocumentTemplate_changeDate method validate0$$.

public TranslatableString validate0$$(LocalDate proposedDate) {
    final DocumentTemplate original = documentTemplate;
    final String proposedAtPath = documentTemplate.getAtPath();
    return documentTemplateRepository.validateApplicationTenancyAndDate(original.getType(), proposedAtPath, proposedDate, original);
}
Also used : TranslatableString(org.apache.isis.applib.services.i18n.TranslatableString)

Example 2 with TranslatableString

use of org.apache.isis.applib.services.i18n.TranslatableString in project estatio by estatio.

the class Applicability_TitleSubscriber_Test method happy_case.

@Ignore
@Test
public void happy_case() throws Exception {
    // given
    final Applicability.TitleUiEvent ev = new Applicability.TitleUiEvent();
    ev.setSource(mockApplicability);
    // expect
    context.checking(new Expectations() {

        {
            allowing(mockApplicability).getDomainClassName();
            will(returnValue("com.mycompany.SomeDomainObject"));
            allowing(mockApplicability).getDocumentTemplate();
            will(returnValue(mockDocumentTemplate));
            allowing(mockDocumentTemplate).getType();
            will(returnValue(mockDocumentType));
            allowing(mockDocumentType).getReference();
            will(returnValue("XYZ123"));
        }
    });
    // when
    titleSubscriber.on(ev);
    // then
    final TranslatableString translatableTitle = ev.getTranslatableTitle();
    Assertions.assertThat(translatableTitle.translate(mockTranslationService, "")).isEqualTo("SomeDomainObject XYZ123");
}
Also used : Expectations(org.jmock.Expectations) TranslatableString(org.apache.isis.applib.services.i18n.TranslatableString) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 3 with TranslatableString

use of org.apache.isis.applib.services.i18n.TranslatableString in project estatio by estatio.

the class DocumentTemplateMenu method validateNewTemplate.

private TranslatableString validateNewTemplate(final DocumentType proposedType, final LocalDate proposedDate, final ApplicationTenancy proposedApplicationTenancy, final RenderingStrategy proposedRenderingStrategy, final DocumentSort documentSort) {
    TranslatableString translatableString = documentTemplateRepository.validateApplicationTenancyAndDate(proposedType, proposedApplicationTenancy.getPath(), proposedDate, null);
    if (translatableString != null) {
        return translatableString;
    }
    translatableString = documentTemplateRepository.validateSortAndRenderingStrategyInputNature(documentSort, proposedRenderingStrategy);
    if (translatableString != null) {
        return translatableString;
    }
    return null;
}
Also used : TranslatableString(org.apache.isis.applib.services.i18n.TranslatableString)

Example 4 with TranslatableString

use of org.apache.isis.applib.services.i18n.TranslatableString in project estatio by estatio.

the class TaxonomyImport method importData.

@Override
public List<Object> importData(final Object previousRow) {
    final TaxonomyImport previousTaxonomyImport = (TaxonomyImport) previousRow;
    final List<Object> createdTaxonomiesAndCategories = Lists.newArrayList();
    if (getTaxonomyReference() == null) {
        final String previousReference = previousTaxonomyImport.getTaxonomyReference();
        if (previousReference == null) {
            throw new IllegalArgumentException("Taxonomy reference is null and previous row's taxonomy reference also null");
        }
        setTaxonomyReference(previousReference);
    }
    final Taxonomy taxonomy;
    Category taxonomyAsCategory = categoryRepository.findByReference(getTaxonomyReference());
    if (taxonomyAsCategory != null) {
        if (!(taxonomyAsCategory instanceof Taxonomy)) {
            throw new IllegalArgumentException(String.format("Ref: '%s' is a reference to a Category, not a Taxonomy", getTaxonomyReference()));
        } else {
            taxonomy = (Taxonomy) taxonomyAsCategory;
        }
    } else {
        taxonomy = categoryRepository.createTaxonomy(getTaxonomyName());
        taxonomy.setReference(getTaxonomyReference());
        taxonomy.setOrdinal(getTaxonomyOrdinal());
        createdTaxonomiesAndCategories.add(taxonomy);
    }
    if (getApplicabilityAtPath() != null) {
        final ApplicationTenancy applicationTenancy = applicationTenancyRepository.findByPath(getApplicabilityAtPath());
        if (applicationTenancy == null) {
            throw new IllegalArgumentException(String.format("No such application tenancy with atPath '%s'", getApplicabilityAtPath()));
        }
        if (getApplicabilityDomainType() != null) {
            final TranslatableString whetherApplicable = taxonomy.validateApplicable(getApplicabilityAtPath(), getApplicabilityDomainType());
            if (whetherApplicable == null) {
                taxonomy.applicable(getApplicabilityAtPath(), getApplicabilityDomainType());
                taxonomy.getAppliesTo();
            }
        }
    }
    // Get Parent category
    Optional<Category> parentCategory = Optional.empty();
    if (getParentCategoryReference() != null && getParentCategoryReference().length() > 0) {
        parentCategory = Optional.ofNullable(categoryRepository.findByTaxonomyAndReference(taxonomy, getParentCategoryReference()));
        if (!parentCategory.isPresent()) {
            throw new IllegalArgumentException(String.format("No category with reference '%s' found", getParentCategoryReference()));
        }
    }
    // 
    if (getCategoryReference() != null) {
        final Category parent = parentCategory.isPresent() ? parentCategory.get() : taxonomy;
        final Optional<Category> categoryIfAny = Optional.ofNullable(categoryRepository.findByTaxonomyAndReference(taxonomy, getCategoryReference()));
        if (!categoryIfAny.isPresent()) {
            createdTaxonomiesAndCategories.add(parent.addChild(getCategoryName(), getCategoryReference(), getCategoryOrdinal()));
        } else {
            // update existing
            final Category category = categoryIfAny.get();
            category.setName(getCategoryName());
            category.setParent(parent);
        }
    }
    return createdTaxonomiesAndCategories;
}
Also used : Category(org.incode.module.classification.dom.impl.category.Category) Taxonomy(org.incode.module.classification.dom.impl.category.taxonomy.Taxonomy) DomainObject(org.apache.isis.applib.annotation.DomainObject) TranslatableString(org.apache.isis.applib.services.i18n.TranslatableString) ApplicationTenancy(org.isisaddons.module.security.dom.tenancy.ApplicationTenancy) TranslatableString(org.apache.isis.applib.services.i18n.TranslatableString)

Aggregations

TranslatableString (org.apache.isis.applib.services.i18n.TranslatableString)4 DomainObject (org.apache.isis.applib.annotation.DomainObject)1 Category (org.incode.module.classification.dom.impl.category.Category)1 Taxonomy (org.incode.module.classification.dom.impl.category.taxonomy.Taxonomy)1 ApplicationTenancy (org.isisaddons.module.security.dom.tenancy.ApplicationTenancy)1 Expectations (org.jmock.Expectations)1 Ignore (org.junit.Ignore)1 Test (org.junit.Test)1