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
}
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);
}
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;
}
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());
}
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);
}
Aggregations