Search in sources :

Example 26 with CreateResult

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());
}
Also used : CreateResult(org.activityinfo.shared.command.result.CreateResult) AttributeGroup(org.activityinfo.server.database.hibernate.entity.AttributeGroup) Activity(org.activityinfo.server.database.hibernate.entity.Activity) Date(java.util.Date)

Example 27 with CreateResult

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());
}
Also used : CreateResult(org.activityinfo.shared.command.result.CreateResult) Attribute(org.activityinfo.server.database.hibernate.entity.Attribute) AttributeGroup(org.activityinfo.server.database.hibernate.entity.AttributeGroup) Activity(org.activityinfo.server.database.hibernate.entity.Activity) Date(java.util.Date)

Example 28 with CreateResult

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());
    }
}
Also used : CreateResult(org.activityinfo.shared.command.result.CreateResult) JAXBException(javax.xml.bind.JAXBException) UserDatabase(org.activityinfo.server.database.hibernate.entity.UserDatabase) ParseException(org.activityinfo.shared.exception.ParseException) ReportDefinition(org.activityinfo.server.database.hibernate.entity.ReportDefinition)

Example 29 with CreateResult

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());
}
Also used : Project(org.activityinfo.server.database.hibernate.entity.Project) CreateResult(org.activityinfo.shared.command.result.CreateResult) UserDatabase(org.activityinfo.server.database.hibernate.entity.UserDatabase) Activity(org.activityinfo.server.database.hibernate.entity.Activity) CommandException(org.activityinfo.shared.exception.CommandException) CreateLockedPeriod(org.activityinfo.shared.command.CreateLockedPeriod) LockedPeriod(org.activityinfo.server.database.hibernate.entity.LockedPeriod) Date(java.util.Date) LockedPeriodDTO(org.activityinfo.shared.dto.LockedPeriodDTO)

Example 30 with CreateResult

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()));
}
Also used : CreateResult(org.activityinfo.shared.command.result.CreateResult)

Aggregations

CreateResult (org.activityinfo.shared.command.result.CreateResult)36 Test (org.junit.Test)17 SchemaDTO (org.activityinfo.shared.dto.SchemaDTO)9 Date (java.util.Date)8 GetSchema (org.activityinfo.shared.command.GetSchema)8 PartnerDTO (org.activityinfo.shared.dto.PartnerDTO)8 CreateSite (org.activityinfo.shared.command.CreateSite)7 SiteDTO (org.activityinfo.shared.dto.SiteDTO)7 AddPartner (org.activityinfo.shared.command.AddPartner)6 ActivityDTO (org.activityinfo.shared.dto.ActivityDTO)6 ProjectDTO (org.activityinfo.shared.dto.ProjectDTO)6 OnDataSet (org.activityinfo.server.database.OnDataSet)5 UserDatabase (org.activityinfo.server.database.hibernate.entity.UserDatabase)5 CreateEntity (org.activityinfo.shared.command.CreateEntity)5 DuplicateCreateResult (org.activityinfo.shared.command.result.DuplicateCreateResult)5 AsyncCallback (com.google.gwt.user.client.rpc.AsyncCallback)4 FormDialogCallback (org.activityinfo.client.page.common.dialog.FormDialogCallback)4 FormDialogTether (org.activityinfo.client.page.common.dialog.FormDialogTether)4 Activity (org.activityinfo.server.database.hibernate.entity.Activity)4 AddTarget (org.activityinfo.shared.command.AddTarget)4