Search in sources :

Example 6 with Classification

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

the class Classification_remove_IntegTest method happy_case.

@Test
public void happy_case() {
    // given
    DemoObjectWithAtPath demoFooInItaly = demoObjectMenu.listAllDemoObjectsWithAtPath().stream().filter(demoObject -> demoObject.getName().equals("Demo foo (in Italy)")).findFirst().get();
    Classification italianClassificationRed = classificationRepository.findByClassified(demoFooInItaly).stream().filter(classification -> classification.getCategory().getName().equals("Red")).findFirst().get();
    // when
    wrap(italianClassificationRed).remove();
    // then
    assertThat(classificationRepository.findByClassified(demoFooInItaly)).extracting(Classification::getCategory).extracting(Category::getName).doesNotContain("Red");
}
Also used : DemoObjectWithAtPath(org.incode.platform.dom.classification.integtests.demo.dom.demowithatpath.DemoObjectWithAtPath) Classification(org.incode.module.classification.dom.impl.classification.Classification) Test(org.junit.Test)

Example 7 with Classification

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

the class T_classify_IntegTest method when_applicability_and_no_classification.

@Test
public void when_applicability_and_no_classification() {
    // given
    DemoObjectWithAtPath demoBip = demoObjectMenu.listAllDemoObjectsWithAtPath().stream().filter(demoObject -> demoObject.getName().equals("Demo bip (in Milan)")).findFirst().get();
    assertThat(classificationRepository.findByClassified(demoBip)).isEmpty();
    // when
    final ClassificationForDemoObjectWithAtPath.classify classification = factoryService.mixin(ClassificationForDemoObjectWithAtPath.classify.class, demoBip);
    Collection<Taxonomy> choices0Classify = classification.choices0Classify();
    assertThat(choices0Classify).extracting(Taxonomy::getName).containsOnly("Italian Colours", "Sizes");
    List<String> categoryNames = new ArrayList<>();
    for (Taxonomy taxonomy : choices0Classify) {
        Category category = classification.default1Classify(taxonomy);
        categoryNames.add(category.getName());
        wrap(classification).classify(taxonomy, category);
    }
    // then
    assertThat(classificationRepository.findByClassified(demoBip)).extracting(Classification::getCategory).extracting(Category::getName).containsOnlyElementsOf(categoryNames);
}
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) Classification(org.incode.module.classification.dom.impl.classification.Classification) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 8 with Classification

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

the class CategoryRepository_findByClassified_IntegTest method happy_case.

@Test
public void happy_case() {
    // given
    DemoObjectWithAtPath demoFooInItaly = demoObjectMenu.listAllDemoObjectsWithAtPath().stream().filter(d -> d.getName().equals("Demo foo (in Italy)")).findFirst().get();
    assertThat(demoFooInItaly).isNotNull();
    // when
    List<Classification> classifications = classificationRepository.findByClassified(demoFooInItaly);
    // then
    assertThat(classifications.size()).isEqualTo(2);
    assertThat(classifications).extracting(Classification::getCategory).extracting(Category::getName).containsOnly("Red", "Medium");
}
Also used : DemoObjectWithAtPath(org.incode.platform.dom.classification.integtests.demo.dom.demowithatpath.DemoObjectWithAtPath) Classification(org.incode.module.classification.dom.impl.classification.Classification) Test(org.junit.Test)

Example 9 with Classification

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

the class ClassificationForOccImport method importData.

@Override
public List<Object> importData(final Object previousRow) {
    final Lease lease = leaseRepository.findLeaseByReference(getLeaseReference());
    if (lease == null) {
        throw new IllegalArgumentException(String.format("No lease found for '%s'", getLeaseReference()));
    }
    final Unit unit = unitRepository.findUnitByReference(getUnitReference());
    if (unit == null) {
        throw new IllegalArgumentException(String.format("No unit found for '%s'", getUnitReference()));
    }
    final Occupancy occupancy = occupancyRepository.findByLease(lease).stream().filter(x -> x.getUnit().equals(unit)).findFirst().get();
    if (occupancy == null) {
        throw new IllegalArgumentException(String.format("No occupancy found for lease '%s' and unit '%s'", getLeaseReference(), getUnitReference()));
    }
    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, occupancy);
    return Lists.newArrayList(classification);
}
Also used : Category(org.incode.module.classification.dom.impl.category.Category) Lease(org.estatio.module.lease.dom.Lease) Taxonomy(org.incode.module.classification.dom.impl.category.taxonomy.Taxonomy) Occupancy(org.estatio.module.lease.dom.occupancy.Occupancy) Classification(org.incode.module.classification.dom.impl.classification.Classification) Unit(org.estatio.module.asset.dom.Unit)

Aggregations

Classification (org.incode.module.classification.dom.impl.classification.Classification)9 DemoObjectWithAtPath (org.incode.platform.dom.classification.integtests.demo.dom.demowithatpath.DemoObjectWithAtPath)7 Test (org.junit.Test)6 Category (org.incode.module.classification.dom.impl.category.Category)4 Taxonomy (org.incode.module.classification.dom.impl.category.taxonomy.Taxonomy)4 ClassificationForDemoObjectWithAtPath (org.incode.platform.dom.classification.integtests.dom.classification.dom.classification.demowithatpath.ClassificationForDemoObjectWithAtPath)3 ArrayList (java.util.ArrayList)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 Applicability (org.incode.module.classification.dom.impl.applicability.Applicability)1 Ignore (org.junit.Ignore)1