use of org.activityinfo.legacy.shared.command.result.CreateResult in project activityinfo by bedatadriven.
the class CreateEntityHandler method createIndicator.
private CommandResult createIndicator(User user, Map<String, Object> properties) {
// query the next indicator sort order index
Indicator indicator = new Indicator();
indicator.setId(generator.generateInt());
Activity activity = entityManager().getReference(Activity.class, properties.get("activityId"));
indicator.setActivity(activity);
assertDesignPrivileges(user, activity.getDatabase());
updateIndicatorProperties(indicator, properties);
if (indicator.getSortOrder() == 0) {
indicator.setSortOrder(queryNextIndicatorSortOrdinal(activity));
}
entityManager().persist(indicator);
activity.incrementSchemaVersion();
activity.getDatabase().setLastSchemaUpdate(new Date());
return new CreateResult(indicator.getId());
}
use of org.activityinfo.legacy.shared.command.result.CreateResult in project activityinfo by bedatadriven.
the class CreateEntityHandler method createAttributeGroup.
private CommandResult createAttributeGroup(Map<String, Object> properties) {
Activity activity = entityManager().find(Activity.class, properties.get("activityId"));
AttributeGroup group = new AttributeGroup();
group.setId(generator.generateInt());
group.setSortOrder(activity.getAttributeGroups().size() + 1);
updateAttributeGroupProperties(group, properties);
entityManager().persist(group);
activity.getAttributeGroups().add(group);
activity.incrementSchemaVersion();
activity.getDatabase().setLastSchemaUpdate(new Date());
return new CreateResult(group.getId());
}
use of org.activityinfo.legacy.shared.command.result.CreateResult in project activityinfo by bedatadriven.
the class CreateLockedPeriodHandler method execute.
@Override
public CommandResult execute(CreateLockedPeriod cmd, User user) {
Activity activity;
Database database;
Project project;
Folder folder;
LockedPeriod lockedPeriod = new LockedPeriod();
LockedPeriodDTO lockedPeriodDTO = cmd.getLockedPeriod();
lockedPeriod.setFromDate(lockedPeriodDTO.getFromDate().atMidnightInMyTimezone());
lockedPeriod.setToDate(lockedPeriodDTO.getToDate().atMidnightInMyTimezone());
lockedPeriod.setName(lockedPeriodDTO.getName());
lockedPeriod.setEnabled(lockedPeriodDTO.isEnabled());
int databaseId;
if (cmd.getDatabaseId() != 0) {
database = em.find(Database.class, cmd.getDatabaseId());
lockedPeriod.setDatabase(database);
databaseId = database.getId();
permissionOracle.assertDesignPrivileges(database, user);
} else if (cmd.getProjectId() != 0) {
project = em.find(Project.class, cmd.getProjectId());
lockedPeriod.setProject(project);
lockedPeriod.setDatabase(project.getDatabase());
databaseId = project.getDatabase().getId();
permissionOracle.assertDesignPrivileges(project.getDatabase(), user);
} else if (cmd.getActivityId() != 0) {
activity = em.find(Activity.class, cmd.getActivityId());
lockedPeriod.setActivity(activity);
lockedPeriod.setDatabase(activity.getDatabase());
databaseId = activity.getDatabase().getId();
permissionOracle.assertDesignPrivileges(activity, user);
} else if (cmd.getFolderId() != 0) {
folder = em.find(Folder.class, cmd.getFolderId());
lockedPeriod.setFolder(folder);
lockedPeriod.setDatabase(folder.getDatabase());
databaseId = folder.getDatabase().getId();
permissionOracle.assertDesignPrivileges(folder, user);
} else {
throw new CommandException("One of the following must be provided: userDatabaseId, projectId, activityId, folderId");
}
Database db = em.find(Database.class, databaseId);
em.persist(lockedPeriod);
db.setLastSchemaUpdate(new Date());
em.persist(db);
return new CreateResult(lockedPeriod.getId());
}
use of org.activityinfo.legacy.shared.command.result.CreateResult in project activityinfo by bedatadriven.
the class CreateReportHandler method execute.
@Override
public CommandResult execute(CreateReport cmd, User user) {
// verify that the XML is valid
try {
ReportDefinition reportDef = new ReportDefinition();
String xml = ReportParserJaxb.createXML(cmd.getReport());
reportDef.setXml(xml);
if (cmd.getDatabaseId() != null) {
reportDef.setDatabase(em.getReference(Database.class, cmd.getDatabaseId()));
}
reportDef.setTitle(cmd.getReport().getTitle());
reportDef.setDescription(cmd.getReport().getDescription());
reportDef.setOwner(user);
reportDef.setVisibility(1);
em.persist(reportDef);
return new CreateResult(reportDef.getId());
} catch (JAXBException e) {
throw new ParseException(e.getMessage());
}
}
use of org.activityinfo.legacy.shared.command.result.CreateResult in project activityinfo by bedatadriven.
the class CustomerCalcIndicatorTest method createFormClass.
private FormClass createFormClass() {
SchemaDTO schema = execute(new GetSchema());
UserDatabaseDTO db = schema.getDatabaseById(1);
LocationTypeDTO locType = schema.getCountryById(1).getLocationTypes().get(0);
ActivityFormDTO act = new ActivityFormDTO();
act.setName("Calculated indicators");
act.setLocationType(locType);
act.setReportingFrequency(ActivityFormDTO.REPORT_ONCE);
CreateResult createResult = execute(CreateEntity.Activity(db, act));
ResourceId classId = activityFormClass(createResult.getNewId());
FormClass formClass = assertResolves(locator.getFormClass(classId));
FormField typeField = new FormField(ResourceId.generateFieldId(EnumType.TYPE_CLASS));
typeField.setType(new EnumType(Cardinality.SINGLE, Arrays.asList(new EnumItem(EnumItem.generateId(), "Budgeted"), new EnumItem(EnumItem.generateId(), "Spent"))));
typeField.setLabel("Typology");
formClass.addElement(typeField);
FormField expField = new FormField(quantityId());
expField.setType(new QuantityType().setUnits("currency"));
expField.setLabel("Expenditure");
expField.setCode("EXP");
FormField waterAllocField = new FormField(quantityId());
waterAllocField.setType(new QuantityType().setUnits("%"));
waterAllocField.setLabel("Allocation watter programme");
waterAllocField.setCode("WATER_ALLOC");
FormField pctInitialField = new FormField(quantityId());
pctInitialField.setType(new QuantityType().setUnits("%"));
pctInitialField.setLabel("Initial Cost - Not specified");
pctInitialField.setCode("PCT_INITIAL");
FormField pctInitialHardField = new FormField(quantityId());
pctInitialHardField.setType(new QuantityType().setUnits("%"));
pctInitialHardField.setLabel("Initial Cost - Cap Hard");
pctInitialHardField.setCode("PCT_INITIAL_HARD");
FormField pctInitialSoftField = new FormField(quantityId());
pctInitialSoftField.setType(new QuantityType().setUnits("%"));
pctInitialSoftField.setLabel("Initial Cost - Cap Soft");
pctInitialSoftField.setCode("PCT_INITIAL_SOFT");
FormField pctExtensionField = new FormField(quantityId());
pctExtensionField.setType(new QuantityType().setUnits("%"));
pctExtensionField.setLabel("Extension Cost - Not specified");
pctExtensionField.setCode("PCT_EXTENSION");
FormField pctExtensionHardField = new FormField(quantityId());
pctExtensionHardField.setType(new QuantityType().setUnits("%"));
pctExtensionHardField.setLabel("Extension Cost - Hard");
pctExtensionHardField.setCode("PCT_EXTENSION_HARD");
FormField pctExtensionSoftField = new FormField(quantityId());
pctExtensionSoftField.setType(new QuantityType().setUnits("%"));
pctExtensionSoftField.setLabel("Extension Cost - Soft");
pctExtensionSoftField.setCode("PCT_EXTENSION_SOFT");
FormField pctOpField = new FormField(quantityId());
pctOpField.setType(new QuantityType().setUnits("%"));
pctOpField.setLabel("Operational Cost");
pctOpField.setCode("PCT_OP");
FormField pctMaintenanceField = new FormField(quantityId());
pctMaintenanceField.setType(new QuantityType().setUnits("%"));
pctMaintenanceField.setLabel("Maintenance Cost");
pctMaintenanceField.setCode("PCT_MAINTENANCE");
FormField pctOpMaintField = new FormField(quantityId());
pctOpMaintField.setType(new QuantityType().setUnits("%"));
pctOpMaintField.setLabel("Operational & Maintenance Cost");
pctOpMaintField.setCode("PCT_OP_MAINT");
FormField waterExpField = new FormField(quantityId());
waterExpField.setType(new QuantityType().setUnits("%"));
waterExpField.setLabel("Expenditure on water programme");
waterExpField.setCode("WATER_EXP");
waterExpField.setType(new CalculatedFieldType("{EXP}*({WATER_ALLOC}/100)"));
FormField initialField = new FormField(quantityId());
initialField.setType(new QuantityType().setUnits("%"));
initialField.setLabel("Value of Initial Cost - Not specified");
initialField.setCode("INITIAL");
initialField.setType(new CalculatedFieldType("{WATER_EXP}*({PCT_INITIAL}/100)"));
FormField initialHardField = new FormField(quantityId());
initialHardField.setType(new QuantityType().setUnits("%"));
initialHardField.setLabel("Value of Initial Cost - Cap Hard");
initialHardField.setCode("INITIAL_HARD");
initialHardField.setType(new CalculatedFieldType("{WATER_EXP}*({PCT_INITIAL_HARD}/100)"));
FormField initialSoftField = new FormField(quantityId());
initialSoftField.setType(new QuantityType().setUnits("%"));
initialSoftField.setLabel("Value of Initial Cost – Cap Soft");
initialSoftField.setCode("INITIAL_SOFT");
initialSoftField.setType(new CalculatedFieldType("{WATER_EXP}*({PCT_INITIAL_SOFT}/100)"));
FormField initialTotalField = new FormField(quantityId());
initialTotalField.setType(new QuantityType().setUnits("%"));
initialTotalField.setLabel("Total Value of Initial Cost");
initialTotalField.setCode("INITIAL_TOTAL");
initialTotalField.setType(new CalculatedFieldType("{INITIAL}+{INITIAL_HARD}+{INITIAL_SOFT}"));
formClass.addElement(expField);
formClass.addElement(waterAllocField);
formClass.addElement(pctInitialField);
formClass.addElement(pctInitialHardField);
formClass.addElement(pctInitialSoftField);
formClass.addElement(pctExtensionField);
formClass.addElement(pctExtensionHardField);
formClass.addElement(pctExtensionSoftField);
formClass.addElement(pctOpField);
formClass.addElement(pctMaintenanceField);
formClass.addElement(pctOpMaintField);
formClass.addElement(waterExpField);
formClass.addElement(initialField);
formClass.addElement(initialHardField);
formClass.addElement(initialSoftField);
formClass.addElement(initialTotalField);
assertResolves(locator.persist(formClass));
FormClass reform = assertResolves(locator.getFormClass(formClass.getId()));
assertHasFieldWithLabel(reform, "Expenditure");
assertHasFieldWithLabel(reform, "Allocation watter programme");
assertHasFieldWithLabel(reform, "Initial Cost - Not specified");
assertHasFieldWithLabel(reform, "Initial Cost - Cap Hard");
assertHasFieldWithLabel(reform, "Initial Cost - Cap Soft");
assertHasFieldWithLabel(reform, "Extension Cost - Not specified");
assertHasFieldWithLabel(reform, "Extension Cost - Hard");
assertHasFieldWithLabel(reform, "Extension Cost - Soft");
assertHasFieldWithLabel(reform, "Operational Cost");
assertHasFieldWithLabel(reform, "Maintenance Cost");
assertHasFieldWithLabel(reform, "Operational & Maintenance Cost");
assertHasFieldWithLabel(reform, "Expenditure on water programme");
assertHasFieldWithLabel(reform, "Value of Initial Cost - Not specified");
assertHasFieldWithLabel(reform, "Value of Initial Cost - Cap Hard");
assertHasFieldWithLabel(reform, "Value of Initial Cost – Cap Soft");
assertHasFieldWithLabel(reform, "Total Value of Initial Cost");
return reform;
}
Aggregations