use of org.activityinfo.server.database.hibernate.entity.Database in project activityinfo by bedatadriven.
the class GeoDigestModelBuilderTest method testFindDatabasesOwnerAndNoNotification.
@Test
public void testFindDatabasesOwnerAndNoNotification() throws Exception {
// owner & no notification
User user = em.find(User.class, 2);
List<Database> dbs = geoDigestModelBuilder.findDatabases(user);
dbs = geoDigestModelBuilder.findDatabases(user);
assertThat(dbs.size(), is(equalTo(0)));
}
use of org.activityinfo.server.database.hibernate.entity.Database in project activityinfo by bedatadriven.
the class UpdateUserPermissionsHandler method execute.
@Override
public CommandResult execute(UpdateUserPermissions cmd, User executingUser) {
LOGGER.info("UpdateUserPermissions: " + cmd);
Database database = databaseDAO.findById(cmd.getDatabaseId());
UserPermissionDTO dto = cmd.getModel();
/*
* First check that the current user has permission to add users to to
* the queries
*/
boolean isOwner = executingUser.getId() == database.getOwner().getId();
UserPermission executingUserPermission = queryUserPermission(executingUser, database);
LOGGER.info("executingUserPermission: isOwner: " + isOwner + ", executingUserPermissions: " + cmd);
if (!isOwner) {
verifyAuthority(cmd, executingUserPermission);
}
/* Database owner cannot be added */
if (database.getOwner().getEmail().equalsIgnoreCase(cmd.getModel().getEmail())) {
throw new UserExistsException();
}
User user = null;
if (userDAO.doesUserExist(dto.getEmail())) {
user = userDAO.findUserByEmail(dto.getEmail());
}
if (user == null) {
user = createNewUser(executingUser, dto);
}
/*
* Does the permission record exist ?
*/
UserPermission perm = queryUserPermission(user, database);
if (perm == null) {
perm = new UserPermission(database, user);
doUpdate(perm, dto, isOwner, executingUserPermission);
permDAO.persist(perm);
} else {
// If the user is intending to add a new user, verify that this user doesn't already exist
if (cmd.isNewUser() && perm.isAllowView()) {
throw new UserExistsException();
}
doUpdate(perm, dto, isOwner, executingUserPermission);
}
return null;
}
use of org.activityinfo.server.database.hibernate.entity.Database in project activityinfo by bedatadriven.
the class LocationTypePolicy method create.
@Override
public Integer create(User user, PropertyMap properties) {
int databaseId = properties.get(DATABASE_ID_PROPERTY);
Database database = em.find(Database.class, databaseId);
PermissionOracle.using(em).assertDesignPrivileges(database, user);
// create the entity
LocationType locationType = new LocationType();
locationType.setVersion(1L);
locationType.setName(properties.get(NAME_PROPERTY));
locationType.setCountry(database.getCountry());
locationType.setWorkflowId(properties.getOptionalString(WORKFLOW_ID_PROPERTY, LocationTypeDTO.CLOSED_WORKFLOW_ID));
locationType.setDatabase(database);
em.persist(locationType);
return locationType.getId();
}
use of org.activityinfo.server.database.hibernate.entity.Database in project activityinfo by bedatadriven.
the class UserDatabasePolicy method create.
@Override
public Object create(User user, PropertyMap properties) {
Database database = new Database();
database.setCountry(findCountry(properties));
database.setOwner(user);
applyProperties(database, properties);
databaseDAO.persist(database);
addDefaultPartner(database.getId(), user);
return database.getId();
}
use of org.activityinfo.server.database.hibernate.entity.Database in project activityinfo by bedatadriven.
the class RemovePartnerHandler method execute.
@Override
public CommandResult execute(RemovePartner cmd, User user) {
// verify the current user has access to this site
Database db = em.getReference(Database.class, cmd.getDatabaseId());
PermissionOracle.using(em).isManagePartnersAllowed(db, user);
// check to see if there are already sites associated with this partner
int siteCount = ((Number) em.createQuery("select count(s) " + "from Site s " + "where s.activity.id in (select a.id from Activity a where a" + ".database.id = :dbId " + "AND a.dateDeleted is null" + ") " + "and s.partner.id = :partnerId " + "and s.dateDeleted is null").setParameter("dbId", cmd.getDatabaseId()).setParameter("partnerId", cmd.getPartnerId()).getSingleResult()).intValue();
if (siteCount > 0) {
return new RemoveFailedResult();
}
db.getPartners().remove(em.getReference(Partner.class, cmd.getPartnerId()));
db.setLastSchemaUpdate(new Date());
return new RemoveResult();
}
Aggregations