Search in sources :

Example 11 with Database

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)));
}
Also used : User(org.activityinfo.server.database.hibernate.entity.User) Database(org.activityinfo.server.database.hibernate.entity.Database) Test(org.junit.Test)

Example 12 with Database

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;
}
Also used : UserExistsException(org.activityinfo.legacy.shared.command.result.UserExistsException) User(org.activityinfo.server.database.hibernate.entity.User) Database(org.activityinfo.server.database.hibernate.entity.Database) UserPermissionDTO(org.activityinfo.legacy.shared.model.UserPermissionDTO) UserPermission(org.activityinfo.server.database.hibernate.entity.UserPermission)

Example 13 with Database

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();
}
Also used : Database(org.activityinfo.server.database.hibernate.entity.Database) LocationType(org.activityinfo.server.database.hibernate.entity.LocationType)

Example 14 with Database

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();
}
Also used : Database(org.activityinfo.server.database.hibernate.entity.Database)

Example 15 with Database

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();
}
Also used : RemoveResult(org.activityinfo.legacy.shared.command.result.RemoveResult) RemoveFailedResult(org.activityinfo.legacy.shared.command.result.RemoveFailedResult) Database(org.activityinfo.server.database.hibernate.entity.Database) Partner(org.activityinfo.server.database.hibernate.entity.Partner) RemovePartner(org.activityinfo.legacy.shared.command.RemovePartner) Date(java.util.Date)

Aggregations

Database (org.activityinfo.server.database.hibernate.entity.Database)19 User (org.activityinfo.server.database.hibernate.entity.User)6 UserPermission (org.activityinfo.server.database.hibernate.entity.UserPermission)5 Test (org.junit.Test)5 Date (java.util.Date)4 Partner (org.activityinfo.server.database.hibernate.entity.Partner)3 ArrayList (java.util.ArrayList)2 CreateResult (org.activityinfo.legacy.shared.command.result.CreateResult)2 UserPermissionDTO (org.activityinfo.legacy.shared.model.UserPermissionDTO)2 HashMap (java.util.HashMap)1 AddProject (org.activityinfo.legacy.shared.command.AddProject)1 GetSchema (org.activityinfo.legacy.shared.command.GetSchema)1 GetSyncRegions (org.activityinfo.legacy.shared.command.GetSyncRegions)1 RemovePartner (org.activityinfo.legacy.shared.command.RemovePartner)1 UpdatePartner (org.activityinfo.legacy.shared.command.UpdatePartner)1 DuplicateCreateResult (org.activityinfo.legacy.shared.command.result.DuplicateCreateResult)1 RemoveFailedResult (org.activityinfo.legacy.shared.command.result.RemoveFailedResult)1 RemoveResult (org.activityinfo.legacy.shared.command.result.RemoveResult)1 SyncRegion (org.activityinfo.legacy.shared.command.result.SyncRegion)1 SyncRegions (org.activityinfo.legacy.shared.command.result.SyncRegions)1