use of org.isisaddons.module.security.dom.tenancy.ApplicationTenancy in project estatio by estatio.
the class TaxImport method importData.
@Programmatic
@Override
public List<Object> importData(final Object previousRow) {
final ApplicationTenancy applicationTenancy = securityApplicationTenancyRepository.findByPath(atPath);
final Tax tax = taxRepository.findOrCreate(reference, name, applicationTenancy);
tax.setExternalReference(externalReference);
tax.setDescription(description);
final TaxRate rate = tax.newRate(rateStartDate, ratePercentage);
rate.setExternalReference(rateExternalReference);
return Lists.newArrayList(tax);
}
use of org.isisaddons.module.security.dom.tenancy.ApplicationTenancy in project estatio by estatio.
the class PersonImport method importData.
@Override
public List<Object> importData(Object previousRow) {
final ApplicationTenancy applicationTenancy = securityApplicationTenancyRepository.findByPath(atPath);
Person person = (Person) partyRepository.findPartyByReference(reference);
if (person == null) {
person = personRepository.newPerson(reference, initials, firstName, lastName, gender == null ? PersonGenderType.UNKNOWN : PersonGenderType.valueOf(gender), applicationTenancy);
}
person.setApplicationTenancyPath(applicationTenancy.getPath());
person.setFirstName(firstName);
person.setLastName(lastName);
return Lists.newArrayList();
}
use of org.isisaddons.module.security.dom.tenancy.ApplicationTenancy in project estatio by estatio.
the class OrganisationBuilder method execute.
@Override
protected void execute(ExecutionContext executionContext) {
checkParam("atPath", executionContext, String.class);
checkParam("reference", executionContext, String.class);
checkParam("name", executionContext, String.class);
defaultParam("useNumeratorForReference", executionContext, false);
ApplicationTenancy applicationTenancy = applicationTenancies.findTenancyByPath(atPath);
this.object = organisationRepository.newOrganisation(reference, useNumeratorForReference, name, applicationTenancy);
executionContext.addResult(this, object.getReference(), object);
}
use of org.isisaddons.module.security.dom.tenancy.ApplicationTenancy in project estatio by estatio.
the class ApplicationTenancyBuilder method execute.
@Override
protected void execute(final ExecutionContext executionContext) {
checkParam("path", executionContext, String.class);
checkParam("name", executionContext, String.class);
ApplicationTenancy applicationTenancy = repository.findByPath(path);
if (applicationTenancy == null) {
final ApplicationTenancy parent = path.length() > 1 ? repository.findByPath(pathOfParent) : null;
applicationTenancy = repository.newTenancy(name, path, parent);
}
executionContext.addResult(this, path, applicationTenancy);
object = applicationTenancy;
}
use of org.isisaddons.module.security.dom.tenancy.ApplicationTenancy 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;
}
Aggregations