Search in sources :

Example 6 with Taxonomy

use of org.incode.module.classification.dom.impl.category.taxonomy.Taxonomy in project estatio by estatio.

the class DemoObjectWithAtPath_and_OtherObjectWithAtPath_create3 method execute.

@Override
protected void execute(final ExecutionContext executionContext) {
    // italian taxonomy applicable only to Italian DemoObject and OtherObject
    Taxonomy italianColours = categoryRepository.createTaxonomy("Italian Colours");
    italianColours.setReference("ITACOL");
    Category italianRed = italianColours.addChild("Red", "RED", null);
    Category italianGreen = italianColours.addChild("Green", "GREEN", null);
    Category italianWhite = italianColours.addChild("White", "WHITE", null);
    wrap(italianColours).applicable("/ITA", DemoObjectWithAtPath.class.getName());
    wrap(italianColours).applicable("/ITA", OtherObjectWithAtPath.class.getName());
    // french taxonomy applicable only to French DemoObject (and not to OtherObject even if with FRA app tenancy)
    Taxonomy frenchColours = categoryRepository.createTaxonomy("French Colours");
    frenchColours.setReference("FRCOL");
    Category frenchRed = frenchColours.addChild("Red", "FRRED", null);
    Category frenchWhite = frenchColours.addChild("White", "FRWHITE", null);
    Category frenchBlue = frenchColours.addChild("Blue", "FRBLUE", null);
    wrap(frenchColours).applicable("/FRA", DemoObjectWithAtPath.class.getName());
    // global taxonomy applicable only to DemoObject (any app tenancy)
    Taxonomy globalSizes = categoryRepository.createTaxonomy("Sizes");
    globalSizes.setReference("SIZES");
    Category large = globalSizes.addChild("Large", "LGE", 1);
    Category medium = globalSizes.addChild("Medium", "M", 2);
    Category small = globalSizes.addChild("Small", "SML", 3);
    Category largeLargest = large.addChild("Largest", "XXL", 1);
    Category largeLarger = large.addChild("Larger", "XL", 2);
    Category largeLarge = large.addChild("Large", "L", 3);
    Category smallSmall = small.addChild("Small", "S", 1);
    Category smallSmaller = small.addChild("Smaller", "XS", 2);
    Category smallSmallest = small.addChild("Smallest", "XXS", 3);
    wrap(globalSizes).applicable("/", DemoObjectWithAtPath.class.getName());
    // create a sample set of DemoObject and OtherObject, for various app tenancies
    final DemoObjectWithAtPath demoFooInItaly = createDemo("Demo foo (in Italy)", "/ITA", executionContext);
    final DemoObjectWithAtPath demoBarInFrance = createDemo("Demo bar (in France)", "/FRA", executionContext);
    final DemoObjectWithAtPath demoBaz = createDemo("Demo baz (Global)", "/", executionContext);
    final DemoObjectWithAtPath demoBip = createDemo("Demo bip (in Milan)", "/ITA/I-MIL", executionContext);
    final DemoObjectWithAtPath demoBop = createDemo("Demo bop (in Paris)", "/FRA/F-PAR", executionContext);
    final OtherObjectWithAtPath otherFooInItaly = createOther("Other foo (in Italy)", "/ITA", executionContext);
    final OtherObjectWithAtPath otherBarInFrance = createOther("Other bar (in France)", "/FRA", executionContext);
    final OtherObjectWithAtPath otherBaz = createOther("Other baz (Global)", "/", executionContext);
    final OtherObjectWithAtPath otherBip = createOther("Other bip (in Milan)", "/ITA/I-MIL", executionContext);
    final OtherObjectWithAtPath otherBop = createOther("Other bop (in Paris)", "/FRA/F-PAR", executionContext);
    // classify DemoObject
    wrap(mixin(ClassificationForDemoObjectWithAtPath.classify.class, demoFooInItaly)).classify(italianColours, italianRed);
    wrap(mixin(ClassificationForDemoObjectWithAtPath.classify.class, demoFooInItaly)).classify(globalSizes, medium);
    wrap(mixin(ClassificationForDemoObjectWithAtPath.classify.class, demoBarInFrance)).classify(globalSizes, smallSmaller);
// leave OtherObject unclassified
}
Also used : ClassificationForDemoObjectWithAtPath(org.incode.platform.dom.classification.integtests.dom.classification.dom.classification.demowithatpath.ClassificationForDemoObjectWithAtPath) ClassificationForDemoObjectWithAtPath(org.incode.platform.dom.classification.integtests.dom.classification.dom.classification.demowithatpath.ClassificationForDemoObjectWithAtPath) DemoObjectWithAtPath(org.incode.platform.dom.classification.integtests.demo.dom.demowithatpath.DemoObjectWithAtPath) Category(org.incode.module.classification.dom.impl.category.Category) Taxonomy(org.incode.module.classification.dom.impl.category.taxonomy.Taxonomy) OtherObjectWithAtPath(org.incode.platform.dom.classification.integtests.demo.dom.otherwithatpath.OtherObjectWithAtPath)

Example 7 with Taxonomy

use of org.incode.module.classification.dom.impl.category.taxonomy.Taxonomy in project estatio by estatio.

the class ClassificationForPropertyImport method importData.

@Override
public List<Object> importData(final Object previousRow) {
    final Property property = propertyRepository.findPropertyByReference(getPropertyReference());
    if (property == null) {
        throw new IllegalArgumentException(String.format("No property found for '%s'", getPropertyReference()));
    }
    final Taxonomy taxonomy = (Taxonomy) categoryRepository.findByReference(getTaxonomyReference());
    if (taxonomy == null) {
        throw new IllegalArgumentException(String.format("No taxonomy found for '%s'", getTaxonomyReference()));
    }
    final Category category = categoryRepository.findByTaxonomyAndReference(taxonomy, getCategoryReference());
    if (category == null) {
        throw new IllegalArgumentException(String.format("No category found for '%s'", getCategoryReference()));
    }
    final Classification classification = classificationRepository.create(category, property);
    return Lists.newArrayList(classification);
}
Also used : Category(org.incode.module.classification.dom.impl.category.Category) Taxonomy(org.incode.module.classification.dom.impl.category.taxonomy.Taxonomy) Classification(org.incode.module.classification.dom.impl.classification.Classification) Property(org.estatio.module.asset.dom.Property)

Example 8 with Taxonomy

use of org.incode.module.classification.dom.impl.category.taxonomy.Taxonomy 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)

Example 9 with Taxonomy

use of org.incode.module.classification.dom.impl.category.taxonomy.Taxonomy in project estatio by estatio.

the class Taxonomy_applicable_IntegTest method cannot_add_applicability_if_already_has_applicability_for_given_domainType_and_atPath.

@Test
public void cannot_add_applicability_if_already_has_applicability_for_given_domainType_and_atPath() {
    // eg set up for "/ITA" and 'DemoObject', cannot add again
    // given
    Taxonomy italianColours = (Taxonomy) categoryRepository.findByParentAndName(null, "Italian Colours");
    // then
    expectedException.expect(InvalidException.class);
    expectedException.expectMessage("Already applicable for '/ITA' and '" + DemoObjectWithAtPath.class.getName() + "'");
    // when
    wrap(italianColours).applicable("/ITA", DemoObjectWithAtPath.class.getName());
}
Also used : DemoObjectWithAtPath(org.incode.platform.dom.classification.integtests.demo.dom.demowithatpath.DemoObjectWithAtPath) Taxonomy(org.incode.module.classification.dom.impl.category.taxonomy.Taxonomy) Test(org.junit.Test)

Example 10 with Taxonomy

use of org.incode.module.classification.dom.impl.category.taxonomy.Taxonomy in project estatio by estatio.

the class Taxonomy_applicable_IntegTest method can_add_applicability_for_different_domain_types_with_same_atPath.

@Test
public void can_add_applicability_for_different_domain_types_with_same_atPath() {
    // given
    Taxonomy frenchColours = (Taxonomy) categoryRepository.findByParentAndName(null, "French Colours");
    assertThat(applicabilityRepository.findByDomainTypeAndUnderAtPath(OtherObjectWithAtPath.class, "/FRA")).isEmpty();
    // when
    wrap(frenchColours).applicable("/FRA", OtherObjectWithAtPath.class.getName());
    // then
    assertThat(applicabilityRepository.findByDomainTypeAndUnderAtPath(OtherObjectWithAtPath.class, "/FRA")).hasSize(1);
}
Also used : Taxonomy(org.incode.module.classification.dom.impl.category.taxonomy.Taxonomy) OtherObjectWithAtPath(org.incode.platform.dom.classification.integtests.demo.dom.otherwithatpath.OtherObjectWithAtPath) Test(org.junit.Test)

Aggregations

Taxonomy (org.incode.module.classification.dom.impl.category.taxonomy.Taxonomy)18 Test (org.junit.Test)11 Category (org.incode.module.classification.dom.impl.category.Category)7 DemoObjectWithAtPath (org.incode.platform.dom.classification.integtests.demo.dom.demowithatpath.DemoObjectWithAtPath)5 Applicability (org.incode.module.classification.dom.impl.applicability.Applicability)4 Classification (org.incode.module.classification.dom.impl.classification.Classification)4 Programmatic (org.apache.isis.applib.annotation.Programmatic)2 TranslatableString (org.apache.isis.applib.services.i18n.TranslatableString)2 OtherObjectWithAtPath (org.incode.platform.dom.classification.integtests.demo.dom.otherwithatpath.OtherObjectWithAtPath)2 ClassificationForDemoObjectWithAtPath (org.incode.platform.dom.classification.integtests.dom.classification.dom.classification.demowithatpath.ClassificationForDemoObjectWithAtPath)2 ArrayList (java.util.ArrayList)1 DomainObject (org.apache.isis.applib.annotation.DomainObject)1 Bookmark (org.apache.isis.applib.services.bookmark.Bookmark)1 Property (org.estatio.module.asset.dom.Property)1 Unit (org.estatio.module.asset.dom.Unit)1 Lease (org.estatio.module.lease.dom.Lease)1 Occupancy (org.estatio.module.lease.dom.occupancy.Occupancy)1 ApplicationTenancy (org.isisaddons.module.security.dom.tenancy.ApplicationTenancy)1