use of org.activityinfo.server.database.hibernate.entity.Activity 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.server.database.hibernate.entity.Activity in project activityinfo by bedatadriven.
the class UpdateEntityHandler method updateAttribute.
private void updateAttribute(User user, UpdateEntity cmd, Map<String, Object> changes) {
Attribute attribute = entityManager().find(Attribute.class, cmd.getId());
// TODO: decide where attributes belong and how to manage them
// assertDesignPriviledges(user, attribute.get);
updateAttributeProperties(changes, attribute);
AttributeGroup ag = entityManager().find(AttributeGroup.class, attribute.getGroup().getId());
// Assume only
Activity activity = ag.getActivities().iterator().next();
// one
// activity
// for the
// attr group
activity.getDatabase().setLastSchemaUpdate(new Date());
}
use of org.activityinfo.server.database.hibernate.entity.Activity in project activityinfo by bedatadriven.
the class ActivityPolicy method update.
@Override
public void update(User user, Object entityId, PropertyMap changes) {
Activity activity = em.find(Activity.class, entityId);
assertDesignPrivileges(user, activity.getDatabase());
applyProperties(activity, changes);
}
use of org.activityinfo.server.database.hibernate.entity.Activity in project activityinfo by bedatadriven.
the class ActivityPolicy method create.
@Override
public Object create(User user, PropertyMap properties) {
UserDatabase database = getDatabase(properties);
assertDesignPrivileges(user, database);
// create the entity
Activity activity = new Activity();
activity.setDatabase(database);
activity.setSortOrder(calculateNextSortOrderIndex(database.getId()));
activity.setLocationType(getLocationType(properties));
applyProperties(activity, properties);
activityDAO.persist(activity);
return activity.getId();
}
use of org.activityinfo.server.database.hibernate.entity.Activity in project activityinfo by bedatadriven.
the class SchemaUpdateBuilder method makeEntityLists.
private void makeEntityLists() {
for (UserDatabase database : databases) {
if (!userIds.contains(database.getOwner().getId())) {
User u = database.getOwner();
// don't send hashed password to client
// EEK i think hibernate will persist this to the database
// automatically if we change it here!!
// u.setHashedPassword("");
users.add(u);
userIds.add(u.getId());
}
if (!countryIds.contains(database.getCountry().getId())) {
countries.add(database.getCountry());
adminLevels.addAll(database.getCountry().getAdminLevels());
countryIds.add(database.getCountry().getId());
for (org.activityinfo.server.database.hibernate.entity.LocationType l : database.getCountry().getLocationTypes()) {
locationTypes.add(l);
}
}
for (Partner partner : database.getPartners()) {
if (!partnerIds.contains(partner.getId())) {
partners.add(partner);
partnerIds.add(partner.getId());
}
}
projects.addAll(new ArrayList<Project>(database.getProjects()));
allLockedPeriods.addAll(database.getLockedPeriods());
for (Project project : database.getProjects()) {
allLockedPeriods.addAll(project.getLockedPeriods());
}
for (Activity activity : database.getActivities()) {
allLockedPeriods.addAll(activity.getLockedPeriods());
activities.add(activity);
for (Indicator indicator : activity.getIndicators()) {
indicators.add(indicator);
List<IndicatorLinkEntity> links = findIndicatorLinks(indicator);
if (links != null && !links.isEmpty()) {
indicatorLinks.addAll(links);
}
}
for (AttributeGroup g : activity.getAttributeGroups()) {
if (!attributeGroupIds.contains(g.getId())) {
attributeGroups.add(g);
attributeGroupIds.add(g.getId());
for (Attribute a : g.getAttributes()) {
attributes.add(a);
}
}
}
}
}
}
Aggregations