Search in sources :

Example 1 with Applicability

use of org.incode.module.classification.dom.impl.applicability.Applicability in project estatio by estatio.

the class T_classify method choices0Classify.

public Collection<Taxonomy> choices0Classify() {
    SortedSet<Applicability> applicableToClassHierarchy = Sets.newTreeSet();
    // pull together all the 'Applicability's for this domain type and all its supertypes.
    String atPath = getAtPath();
    if (atPath == null) {
        return Collections.emptyList();
    }
    appendDirectApplicabilities(atPath, classified.getClass(), applicableToClassHierarchy);
    // the obtain the corresponding 'Taxonomy's of each of these
    Set<Taxonomy> taxonomies = Sets.newTreeSet();
    taxonomies.addAll(applicableToClassHierarchy.stream().map(Applicability::getTaxonomy).distinct().collect(Collectors.toSet()));
    // remove any taxonomies already selected
    T_classifications t_classifications = new T_classifications(classified) {
    };
    serviceRegistry.injectServicesInto(t_classifications);
    final List<Classification> classifications = t_classifications.$$();
    final Set<Taxonomy> existing = classifications.stream().map(Classification::getTaxonomy).collect(Collectors.toSet());
    taxonomies.removeAll(existing);
    return taxonomies;
}
Also used : Taxonomy(org.incode.module.classification.dom.impl.category.taxonomy.Taxonomy) Applicability(org.incode.module.classification.dom.impl.applicability.Applicability) TranslatableString(org.apache.isis.applib.services.i18n.TranslatableString)

Example 2 with Applicability

use of org.incode.module.classification.dom.impl.applicability.Applicability in project estatio by estatio.

the class Taxonomy method applicable.

@Action(domainEvent = ApplicableToDomainEvent.class)
@ActionLayout(cssClassFa = "fa-plus")
@MemberOrder(name = "appliesTo", sequence = "1")
public Category applicable(@ParameterLayout(named = "Application tenancy") final String atPath, @ParameterLayout(named = "Domain type") final String domainTypeName) {
    Applicability applicability = new Applicability(this, atPath, domainTypeName);
    repositoryService.persistAndFlush(applicability);
    return this;
}
Also used : Applicability(org.incode.module.classification.dom.impl.applicability.Applicability) Action(org.apache.isis.applib.annotation.Action) MemberOrder(org.apache.isis.applib.annotation.MemberOrder) ActionLayout(org.apache.isis.applib.annotation.ActionLayout)

Example 3 with Applicability

use of org.incode.module.classification.dom.impl.applicability.Applicability in project estatio by estatio.

the class Taxonomy_applicable_IntegTest method can_add_applicability_for_same_domain_types_with_different_atPath.

@Test
public void can_add_applicability_for_same_domain_types_with_different_atPath() {
    // eg given an applicability for "/ITA" and 'DemoObject', can also add an applicability for "/ITA/MIL" and 'DemoObject'
    Taxonomy italianColours = (Taxonomy) categoryRepository.findByParentAndName(null, "Italian Colours");
    final List<Applicability> byDomainTypeAndUnderAtPath = applicabilityRepository.findByDomainTypeAndUnderAtPath(DemoObjectWithAtPath.class, "/ITA");
    assertThat(byDomainTypeAndUnderAtPath).hasSize(2);
    assertThat(byDomainTypeAndUnderAtPath).extracting(Applicability::getTaxonomy).extracting(Taxonomy::getFullyQualifiedName).containsOnly("Italian Colours", "Sizes");
    // when
    wrap(italianColours).applicable("/ITA/MIL", DemoObjectWithAtPath.class.getName());
    // then
    final List<Applicability> byDomainTypeAndUnderAtPathNew = applicabilityRepository.findByDomainTypeAndUnderAtPath(DemoObjectWithAtPath.class, "/ITA/MIL");
    assertThat(byDomainTypeAndUnderAtPathNew).hasSize(3);
    assertThat(byDomainTypeAndUnderAtPathNew).extracting(Applicability::getTaxonomy).extracting(Taxonomy::getFullyQualifiedName).containsOnly("Italian Colours", "Sizes");
}
Also used : DemoObjectWithAtPath(org.incode.platform.dom.classification.integtests.demo.dom.demowithatpath.DemoObjectWithAtPath) Taxonomy(org.incode.module.classification.dom.impl.category.taxonomy.Taxonomy) Applicability(org.incode.module.classification.dom.impl.applicability.Applicability) Test(org.junit.Test)

Example 4 with Applicability

use of org.incode.module.classification.dom.impl.applicability.Applicability in project estatio by estatio.

the class Taxonomy_notApplicable_IntegTest method happy_case.

@Test
public void happy_case() {
    // given
    Taxonomy italianColours = (Taxonomy) categoryRepository.findByParentAndName(null, "Italian Colours");
    List<Applicability> applicabilities = applicabilityRepository.findByDomainTypeAndUnderAtPath(DemoObjectWithAtPath.class, "/ITA");
    assertThat(applicabilities).extracting(Applicability::getTaxonomy).extracting(Taxonomy::getName).containsOnly("Italian Colours", "Sizes");
    Applicability italianColoursApplicability = applicabilities.stream().filter(applicability -> applicability.getTaxonomy().getName().equals("Italian Colours")).findFirst().get();
    // when
    wrap(italianColours).notApplicable(italianColoursApplicability);
    // then
    List<Applicability> newApplicabilities = applicabilityRepository.findByDomainTypeAndUnderAtPath(DemoObjectWithAtPath.class, "/ITA");
    assertThat(newApplicabilities).extracting(Applicability::getTaxonomy).extracting(Taxonomy::getName).containsOnly("Sizes");
}
Also used : Taxonomy(org.incode.module.classification.dom.impl.category.taxonomy.Taxonomy) Applicability(org.incode.module.classification.dom.impl.applicability.Applicability) Test(org.junit.Test)

Example 5 with Applicability

use of org.incode.module.classification.dom.impl.applicability.Applicability in project estatio by estatio.

the class Taxonomy_notApplicable_IntegTest method existing_classifications_are_ignored.

@Test
public void existing_classifications_are_ignored() {
    // given
    Taxonomy italianColours = (Taxonomy) categoryRepository.findByParentAndName(null, "Italian Colours");
    List<Applicability> applicabilities = applicabilityRepository.findByDomainTypeAndUnderAtPath(DemoObjectWithAtPath.class, "/ITA");
    assertThat(applicabilities).extracting(Applicability::getTaxonomy).extracting(Taxonomy::getName).contains("Italian Colours");
    Applicability italianColoursApplicability = applicabilities.stream().filter(applicability -> applicability.getTaxonomy().getName().equals("Italian Colours")).findFirst().get();
    DemoObjectWithAtPath demoFooInItaly = demoObjectMenu.listAllDemoObjectsWithAtPath().stream().filter(d -> d.getName().equals("Demo foo (in Italy)")).findFirst().get();
    List<Classification> classifications = classificationRepository.findByClassified(demoFooInItaly);
    assertThat(classifications).extracting(Classification::getTaxonomy).contains(italianColours);
    // when
    wrap(italianColours).notApplicable(italianColoursApplicability);
    // then
    assertThat(classificationRepository.findByClassified(demoFooInItaly)).extracting(Classification::getTaxonomy).contains(italianColours);
}
Also used : DemoObjectWithAtPath(org.incode.platform.dom.classification.integtests.demo.dom.demowithatpath.DemoObjectWithAtPath) Taxonomy(org.incode.module.classification.dom.impl.category.taxonomy.Taxonomy) Classification(org.incode.module.classification.dom.impl.classification.Classification) Applicability(org.incode.module.classification.dom.impl.applicability.Applicability) Test(org.junit.Test)

Aggregations

Applicability (org.incode.module.classification.dom.impl.applicability.Applicability)5 Taxonomy (org.incode.module.classification.dom.impl.category.taxonomy.Taxonomy)4 Test (org.junit.Test)3 DemoObjectWithAtPath (org.incode.platform.dom.classification.integtests.demo.dom.demowithatpath.DemoObjectWithAtPath)2 Action (org.apache.isis.applib.annotation.Action)1 ActionLayout (org.apache.isis.applib.annotation.ActionLayout)1 MemberOrder (org.apache.isis.applib.annotation.MemberOrder)1 TranslatableString (org.apache.isis.applib.services.i18n.TranslatableString)1 Classification (org.incode.module.classification.dom.impl.classification.Classification)1