Search in sources :

Example 11 with CommandException

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

the class CreateLocationHandler method execute.

@Override
public VoidResult execute(CreateLocation cmd, User user) throws CommandException {
    PropertyMap propertyMap = new PropertyMap(cmd.getProperties());
    List<Location> existingLocation = entityManager.createQuery("SELECT L from Location L LEFT JOIN FETCH L.adminEntities WHERE L.id = :id", Location.class).setParameter("id", cmd.getLocationId()).getResultList();
    if (existingLocation.isEmpty()) {
        /*
             * Create new Location
             */
        LocationType locationType = entityManager.find(LocationType.class, cmd.getLocationTypeId());
        if (locationType == null) {
            throw new CommandException("LocationType " + cmd.getLocationTypeId() + " does not exist");
        }
        Location location = new Location();
        location.setId(cmd.getLocationId());
        location.setLocationType(locationType);
        location.setVersion(locationType.incrementVersion());
        applyProperties(location, propertyMap);
        entityManager.persist(location);
    } else {
        Location location = existingLocation.get(0);
        location.setVersion(location.getLocationType().incrementVersion());
        if (cmd.getProperties().containsKey("locationTypeId") && location.getLocationType().getId() != cmd.getLocationTypeId()) {
            throw new CommandException("LocationType of a location cannot be changed");
        }
        applyProperties(location, propertyMap);
    }
    return VoidResult.EMPTY;
}
Also used : PropertyMap(org.activityinfo.server.command.handler.crud.PropertyMap) CommandException(org.activityinfo.legacy.shared.exception.CommandException) LocationType(org.activityinfo.server.database.hibernate.entity.LocationType) CreateLocation(org.activityinfo.legacy.shared.command.CreateLocation) Location(org.activityinfo.server.database.hibernate.entity.Location)

Example 12 with CommandException

use of org.activityinfo.legacy.shared.exception.CommandException 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());
}
Also used : CreateResult(org.activityinfo.legacy.shared.command.result.CreateResult) CommandException(org.activityinfo.legacy.shared.exception.CommandException) CreateLockedPeriod(org.activityinfo.legacy.shared.command.CreateLockedPeriod) Date(java.util.Date) LockedPeriodDTO(org.activityinfo.legacy.shared.model.LockedPeriodDTO)

Example 13 with CommandException

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

the class UpdateUserPermissionsHandler method doUpdate.

protected void doUpdate(UserPermission perm, UserPermissionDTO dto, boolean isOwner, UserPermission executingUserPermissions) {
    perm.setPartner(partnerDAO.findById(dto.getPartner().getId()));
    if (perm.getPartner() == null) {
        throw new CommandException("Partner with id " + dto.getPartner().getId() + " does not exist");
    }
    perm.setAllowView(dto.getAllowView());
    perm.setAllowEdit(dto.getAllowEdit());
    perm.setAllowManageUsers(dto.getAllowManageUsers());
    if (dto.hasFolderLimitation()) {
        perm.setModel(constructModel(perm, dto).toJson().toJson());
    } else {
        // If there are no folders specified, then revert back to the
        // the simple model
        perm.setModel(null);
    }
    if (isOwner || executingUserPermissions.isAllowManageAllUsers() || !dto.getAllowView()) {
        perm.setAllowViewAll(dto.getAllowViewAll());
    }
    if (isOwner || executingUserPermissions.isAllowManageAllUsers() || !dto.getAllowEdit()) {
        perm.setAllowEditAll(dto.getAllowEditAll());
    }
    if (isOwner || executingUserPermissions.isAllowManageAllUsers()) {
        perm.setAllowManageAllUsers(dto.getAllowManageAllUsers());
    }
    if (isOwner || executingUserPermissions.isAllowDesign()) {
        perm.setAllowDesign(dto.getAllowDesign());
    }
    perm.setLastSchemaUpdate(new Date());
}
Also used : IllegalAccessCommandException(org.activityinfo.legacy.shared.exception.IllegalAccessCommandException) CommandException(org.activityinfo.legacy.shared.exception.CommandException) Date(java.util.Date)

Example 14 with CommandException

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

the class RenderElementHandler method execute.

@Override
public CommandResult execute(RenderElement cmd, User user) throws CommandException {
    try {
        Renderer renderer = rendererFactory.get(cmd.getFormat());
        GeneratedResource storage = storageProvider.create(renderer.getMimeType(), cmd.getFilename() + renderer.getFileSuffix());
        LOGGER.fine("Rendering element: " + cmd + "\nURL: " + storage.getDownloadUri());
        try (OutputStream out = storage.openOutputStream()) {
            generator.generateElement(user, cmd.getElement(), new Filter(), new DateRange());
            renderer.render(cmd.getElement(), out);
        }
        return new UrlResult(storage.getDownloadUri());
    } catch (Exception e) {
        throw new RuntimeException("Exception generating export", e);
    }
}
Also used : DateRange(org.activityinfo.legacy.shared.reports.model.DateRange) Filter(org.activityinfo.legacy.shared.command.Filter) OutputStream(java.io.OutputStream) Renderer(org.activityinfo.server.report.renderer.Renderer) GeneratedResource(org.activityinfo.server.generated.GeneratedResource) UrlResult(org.activityinfo.legacy.shared.command.result.UrlResult) CommandException(org.activityinfo.legacy.shared.exception.CommandException)

Example 15 with CommandException

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

the class GetSitesHandler method initialiseHandler.

private void initialiseHandler(GetSites command, User user) {
    catalog = catalogProvider.get();
    if (catalog != null) {
        this.command = command;
        builder = new ColumnSetBuilder(catalog, new AppEngineFormScanCache(), new FormSupervisorAdapter(catalog, user.getId()));
        linkedBuilder = new ColumnSetBuilder(catalog, new AppEngineFormScanCache(), new NullFormSupervisor());
        batchFormTreeBuilder = new BatchingFormTreeBuilder(catalog);
        batch = builder.createNewBatch();
        linkedBatch = linkedBuilder.createNewBatch();
        selfLinkedActivities = Maps.newHashMap();
        sortInfo = command.getSortInfo();
        offset = command.getOffset();
        limit = command.getLimit();
        totalResultLength = 0;
    } else {
        throw new CommandException("Could not retrieve form catalog");
    }
}
Also used : ColumnSetBuilder(org.activityinfo.store.query.server.ColumnSetBuilder) AppEngineFormScanCache(org.activityinfo.store.hrd.AppEngineFormScanCache) FormSupervisorAdapter(org.activityinfo.store.query.server.FormSupervisorAdapter) NullFormSupervisor(org.activityinfo.store.query.shared.NullFormSupervisor) CommandException(org.activityinfo.legacy.shared.exception.CommandException) BatchingFormTreeBuilder(org.activityinfo.store.spi.BatchingFormTreeBuilder)

Aggregations

CommandException (org.activityinfo.legacy.shared.exception.CommandException)18 TraceContext (com.google.cloud.trace.core.TraceContext)3 Filter (org.activityinfo.legacy.shared.command.Filter)3 IllegalAccessCommandException (org.activityinfo.legacy.shared.exception.IllegalAccessCommandException)3 SQLException (java.sql.SQLException)2 Date (java.util.Date)2 CommandResult (org.activityinfo.legacy.shared.command.result.CommandResult)2 DateRange (org.activityinfo.legacy.shared.reports.model.DateRange)2 PropertyMap (org.activityinfo.server.command.handler.crud.PropertyMap)2 User (org.activityinfo.server.database.hibernate.entity.User)2 AsyncCallback (com.google.gwt.user.client.rpc.AsyncCallback)1 IOException (java.io.IOException)1 OutputStream (java.io.OutputStream)1 StringWriter (java.io.StringWriter)1 Calendar (java.util.Calendar)1 CreateLocation (org.activityinfo.legacy.shared.command.CreateLocation)1 CreateLockedPeriod (org.activityinfo.legacy.shared.command.CreateLockedPeriod)1 GetSchema (org.activityinfo.legacy.shared.command.GetSchema)1 OldGetSites (org.activityinfo.legacy.shared.command.OldGetSites)1 UpdateMonthlyReports (org.activityinfo.legacy.shared.command.UpdateMonthlyReports)1