use of org.activityinfo.shared.command.result.CreateResult in project activityinfo by bedatadriven.
the class CreateEntityHandler method createAttributeGroup.
private CommandResult createAttributeGroup(CreateEntity cmd, Map<String, Object> properties) {
AttributeGroup group = new AttributeGroup();
updateAttributeGroupProperties(group, properties);
entityManager().persist(group);
Activity activity = entityManager().find(Activity.class, properties.get("activityId"));
activity.getAttributeGroups().add(group);
activity.getDatabase().setLastSchemaUpdate(new Date());
return new CreateResult(group.getId());
}
use of org.activityinfo.shared.command.result.CreateResult in project activityinfo by bedatadriven.
the class CreateEntityHandler method createAttribute.
private CommandResult createAttribute(CreateEntity cmd, Map<String, Object> properties) {
Attribute attribute = new Attribute();
AttributeGroup ag = entityManager().getReference(AttributeGroup.class, properties.get("attributeGroupId"));
attribute.setGroup(ag);
updateAttributeProperties(properties, attribute);
// Assume
Activity activity = ag.getActivities().iterator().next();
// group has
// only one
// activity
entityManager().persist(attribute);
activity.getDatabase().setLastSchemaUpdate(new Date());
return new CreateResult(attribute.getId());
}
use of org.activityinfo.shared.command.result.CreateResult in project activityinfo by bedatadriven.
the class CreateReportHandler method execute.
@Override
public CommandResult execute(CreateReport cmd, User user) throws CommandException {
// verify that the XML is valid
try {
reportDef = new ReportDefinition();
// TODO should allow null to xml field
String xml = ReportParserJaxb.createXML(cmd.getReport());
reportDef.setXml(xml);
if (cmd.getDatabaseId() != null) {
reportDef.setDatabase(em.getReference(UserDatabase.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.shared.command.result.CreateResult in project activityinfo by bedatadriven.
the class CreateLockedPeriodHandler method execute.
@Override
public CommandResult execute(CreateLockedPeriod cmd, User user) throws CommandException {
Activity activity = null;
UserDatabase database = null;
Project project = null;
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.getUserDatabseId() != 0) {
database = em.find(UserDatabase.class, cmd.getUserDatabseId());
lockedPeriod.setUserDatabase(database);
databaseId = database.getId();
} else if (cmd.getProjectId() != 0) {
project = em.find(Project.class, cmd.getProjectId());
lockedPeriod.setProject(project);
databaseId = project.getUserDatabase().getId();
} else if (cmd.getActivityId() != 0) {
activity = em.find(Activity.class, cmd.getActivityId());
lockedPeriod.setActivity(activity);
databaseId = activity.getDatabase().getId();
} else {
throw new CommandException("One of the following must be provdied: userDatabaseId, projectId, activityId");
}
UserDatabase db = em.find(UserDatabase.class, databaseId);
em.persist(lockedPeriod);
db.setLastSchemaUpdate(new Date());
em.persist(db);
if (database != null) {
database.getLockedPeriods().add(lockedPeriod);
}
if (project != null) {
project.getLockedPeriods().add(lockedPeriod);
}
if (activity != null) {
activity.getLockedPeriods().add(lockedPeriod);
}
return new CreateResult(lockedPeriod.getId());
}
use of org.activityinfo.shared.command.result.CreateResult in project activityinfo by bedatadriven.
the class CreateSiteHandler method execute.
@Override
public void execute(final CreateSite cmd, final ExecutionContext context, final AsyncCallback<CreateResult> callback) {
if (cmd.hasNestedCommand()) {
executeNestedCommand(cmd, context);
}
insertSite(context.getTransaction(), cmd);
// we only create a reporting period if this is a one-off activity
Integer reportingPeriodId = cmd.getReportingPeriodId();
if (reportingPeriodId != null) {
insertReportingPeriod(context.getTransaction(), cmd);
}
callback.onSuccess(new CreateResult(cmd.getSiteId()));
}
Aggregations