Search in sources :

Example 11 with UserDatabase

use of org.activityinfo.server.database.hibernate.entity.UserDatabase in project activityinfo by bedatadriven.

the class UserDatabasePolicy method create.

@Override
public Object create(User user, PropertyMap properties) {
    UserDatabase database = new UserDatabase();
    database.setCountry(findCountry(properties));
    database.setOwner(user);
    applyProperties(database, properties);
    databaseDAO.persist(database);
    return database.getId();
}
Also used : UserDatabase(org.activityinfo.server.database.hibernate.entity.UserDatabase)

Example 12 with UserDatabase

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

Example 13 with UserDatabase

use of org.activityinfo.server.database.hibernate.entity.UserDatabase in project activityinfo by bedatadriven.

the class SchemaUpdateBuilder method createAndSyncPartnerInDatabase.

private void createAndSyncPartnerInDatabase(JpaUpdateBuilder builder) throws JSONException {
    builder.executeStatement("create table if not exists PartnerInDatabase (DatabaseId integer, PartnerId int)");
    builder.executeStatement("delete from PartnerInDatabase");
    if (anyPartners()) {
        builder.beginPreparedStatement("insert into PartnerInDatabase (DatabaseId, PartnerId) values (?, ?) ");
        for (UserDatabase db : databases) {
            for (Partner partner : db.getPartners()) {
                builder.addExecution(db.getId(), partner.getId());
            }
        }
        builder.finishPreparedStatement();
    }
}
Also used : UserDatabase(org.activityinfo.server.database.hibernate.entity.UserDatabase) Partner(org.activityinfo.server.database.hibernate.entity.Partner)

Example 14 with UserDatabase

use of org.activityinfo.server.database.hibernate.entity.UserDatabase 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);
                    }
                }
            }
        }
    }
}
Also used : LocationType(org.activityinfo.server.database.hibernate.entity.LocationType) User(org.activityinfo.server.database.hibernate.entity.User) Attribute(org.activityinfo.server.database.hibernate.entity.Attribute) UserDatabase(org.activityinfo.server.database.hibernate.entity.UserDatabase) AttributeGroup(org.activityinfo.server.database.hibernate.entity.AttributeGroup) Activity(org.activityinfo.server.database.hibernate.entity.Activity) Indicator(org.activityinfo.server.database.hibernate.entity.Indicator) Project(org.activityinfo.server.database.hibernate.entity.Project) Partner(org.activityinfo.server.database.hibernate.entity.Partner) IndicatorLinkEntity(org.activityinfo.server.database.hibernate.entity.IndicatorLinkEntity)

Aggregations

UserDatabase (org.activityinfo.server.database.hibernate.entity.UserDatabase)14 Partner (org.activityinfo.server.database.hibernate.entity.Partner)7 Date (java.util.Date)6 UserPermission (org.activityinfo.server.database.hibernate.entity.UserPermission)5 Activity (org.activityinfo.server.database.hibernate.entity.Activity)4 Project (org.activityinfo.server.database.hibernate.entity.Project)4 CreateResult (org.activityinfo.shared.command.result.CreateResult)4 User (org.activityinfo.server.database.hibernate.entity.User)3 AttributeGroup (org.activityinfo.server.database.hibernate.entity.AttributeGroup)2 IllegalAccessCommandException (org.activityinfo.shared.exception.IllegalAccessCommandException)2 UpdateUserPermissionsHandler (org.activityinfo.server.command.handler.UpdateUserPermissionsHandler)1 AdminEntity (org.activityinfo.server.database.hibernate.entity.AdminEntity)1 Attribute (org.activityinfo.server.database.hibernate.entity.Attribute)1 Indicator (org.activityinfo.server.database.hibernate.entity.Indicator)1 IndicatorLinkEntity (org.activityinfo.server.database.hibernate.entity.IndicatorLinkEntity)1 LocationType (org.activityinfo.server.database.hibernate.entity.LocationType)1 LockedPeriod (org.activityinfo.server.database.hibernate.entity.LockedPeriod)1 Target (org.activityinfo.server.database.hibernate.entity.Target)1 MailSenderStub (org.activityinfo.server.mail.MailSenderStub)1 TemplateModule (org.activityinfo.server.util.TemplateModule)1