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;
}
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());
}
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());
}
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);
}
}
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");
}
}
Aggregations