Search in sources :

Example 6 with CommandException

use of org.activityinfo.shared.exception.CommandException in project activityinfo by bedatadriven.

the class CommandTestCase method execute.

protected <T extends CommandResult> T execute(Command<T> command) throws CommandException {
    User user = em.find(User.class, AuthenticationModuleStub.getCurrentUser().getUserId());
    assert user != null : "cannot find user id " + AuthenticationModuleStub.getCurrentUser().getUserId() + " in the database, have you " + " called execute() without a @OnDataset annotation?";
    Locale.setDefault(Locale.ENGLISH);
    List<CommandResult> results = servlet.handleCommands(Collections.<Command>singletonList(command));
    // normally each request and so each handleCommand() gets its own
    // EntityManager, but here successive requests in the same test
    // will share an EntityManager, which can be bad if there are
    // collections
    // still living in the first-level cache
    // 
    // I think these command tests should ultimately become real end-to-end
    // tests and so would go through the actual servlet process, but for the
    // moment,
    // we'll just add this work aroudn that clears the cache after each
    // command.
    em.clear();
    CommandResult result = results.get(0);
    if (result instanceof CommandException) {
        throw (CommandException) result;
    }
    return (T) result;
}
Also used : User(org.activityinfo.server.database.hibernate.entity.User) CommandException(org.activityinfo.shared.exception.CommandException) CommandResult(org.activityinfo.shared.command.result.CommandResult)

Example 7 with CommandException

use of org.activityinfo.shared.exception.CommandException in project activityinfo by bedatadriven.

the class PivotSitesHandlerTest method execute.

private void execute() {
    setUser(OWNER_USER_ID);
    try {
        PivotSites pivot = new PivotSites(dimensions, filter);
        pivot.setValueType(valueType);
        pivot.setPointRequested(pointsRequested);
        buckets = execute(pivot).getBuckets();
    } catch (CommandException e) {
        throw new RuntimeException(e);
    }
    System.out.println("Buckets = [");
    for (Bucket bucket : buckets) {
        System.out.print("  { Value: " + bucket.doubleValue());
        for (Dimension dim : bucket.dimensions()) {
            DimensionCategory cat = bucket.getCategory(dim);
            System.out.print("\n    " + dim.toString() + ": ");
            System.out.print(cat.toString());
        }
        System.out.println("\n  }");
    }
    System.out.print("]\n");
}
Also used : DimensionCategory(org.activityinfo.shared.report.content.DimensionCategory) Bucket(org.activityinfo.shared.command.result.Bucket) CommandException(org.activityinfo.shared.exception.CommandException) Dimension(org.activityinfo.shared.report.model.Dimension) AttributeGroupDimension(org.activityinfo.shared.report.model.AttributeGroupDimension) AdminDimension(org.activityinfo.shared.report.model.AdminDimension) DateDimension(org.activityinfo.shared.report.model.DateDimension)

Example 8 with CommandException

use of org.activityinfo.shared.exception.CommandException in project activityinfo by bedatadriven.

the class PivotSitesHandlerLocalTest method execute.

private void execute() {
    setUser(OWNER_USER_ID);
    try {
        PivotSites pivot = new PivotSites(dimensions, filter);
        pivot.setValueType(valueType);
        buckets = executeLocally(pivot).getBuckets();
    } catch (CommandException e) {
        throw new RuntimeException(e);
    }
    System.out.println("Buckets = [");
    for (Bucket bucket : buckets) {
        System.out.print(bucket.toString());
    }
    System.out.print("]\n");
}
Also used : Bucket(org.activityinfo.shared.command.result.Bucket) CommandException(org.activityinfo.shared.exception.CommandException)

Example 9 with CommandException

use of org.activityinfo.shared.exception.CommandException in project activityinfo by bedatadriven.

the class GetSyncRegionUpdatesHandler method execute.

@Override
public CommandResult execute(GetSyncRegionUpdates cmd, User user) throws CommandException {
    Log.info("Fetching updates for " + cmd.getRegionId() + ", localVersion = " + cmd.getLocalVersion());
    UpdateBuilder builder;
    if (cmd.getRegionId().equals("schema")) {
        builder = injector.getInstance(SchemaUpdateBuilder.class);
    } else if (cmd.getRegionId().startsWith("admin/")) {
        builder = injector.getInstance(AdminUpdateBuilder.class);
    } else if (cmd.getRegionId().startsWith("location/")) {
        builder = injector.getInstance(LocationUpdateBuilder.class);
    } else if (cmd.getRegionId().startsWith("site/")) {
        builder = injector.getInstance(SiteUpdateBuilder.class);
    } else if (cmd.getRegionId().equals("site-tables")) {
        builder = injector.getInstance(SiteTableUpdateBuilder.class);
    } else {
        throw new CommandException("Unknown sync region: " + cmd.getRegionId());
    }
    try {
        return builder.build(user, cmd);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : SchemaUpdateBuilder(org.activityinfo.server.command.handler.sync.SchemaUpdateBuilder) LocationUpdateBuilder(org.activityinfo.server.command.handler.sync.LocationUpdateBuilder) SiteTableUpdateBuilder(org.activityinfo.server.command.handler.sync.SiteTableUpdateBuilder) UpdateBuilder(org.activityinfo.server.command.handler.sync.UpdateBuilder) AdminUpdateBuilder(org.activityinfo.server.command.handler.sync.AdminUpdateBuilder) LocationUpdateBuilder(org.activityinfo.server.command.handler.sync.LocationUpdateBuilder) SiteTableUpdateBuilder(org.activityinfo.server.command.handler.sync.SiteTableUpdateBuilder) SiteUpdateBuilder(org.activityinfo.server.command.handler.sync.SiteUpdateBuilder) SchemaUpdateBuilder(org.activityinfo.server.command.handler.sync.SchemaUpdateBuilder) CommandException(org.activityinfo.shared.exception.CommandException) CommandException(org.activityinfo.shared.exception.CommandException)

Example 10 with CommandException

use of org.activityinfo.shared.exception.CommandException 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)

Aggregations

CommandException (org.activityinfo.shared.exception.CommandException)15 User (org.activityinfo.server.database.hibernate.entity.User)3 LogException (org.activityinfo.server.util.logging.LogException)3 CommandResult (org.activityinfo.shared.command.result.CommandResult)3 PropertyMap (org.activityinfo.server.command.handler.crud.PropertyMap)2 Filter (org.activityinfo.shared.command.Filter)2 Bucket (org.activityinfo.shared.command.result.Bucket)2 CreateResult (org.activityinfo.shared.command.result.CreateResult)2 VoidResult (org.activityinfo.shared.command.result.VoidResult)2 IllegalAccessCommandException (org.activityinfo.shared.exception.IllegalAccessCommandException)2 DateRange (org.activityinfo.shared.report.model.DateRange)2 AsyncCallback (com.google.gwt.user.client.rpc.AsyncCallback)1 IOException (java.io.IOException)1 StringWriter (java.io.StringWriter)1 ArrayList (java.util.ArrayList)1 Calendar (java.util.Calendar)1 Date (java.util.Date)1 TransformerConfigurationException (javax.xml.transform.TransformerConfigurationException)1 ActivityPolicy (org.activityinfo.server.command.handler.crud.ActivityPolicy)1 UserDatabasePolicy (org.activityinfo.server.command.handler.crud.UserDatabasePolicy)1