Search in sources :

Example 36 with ResourceId

use of org.activityinfo.model.resource.ResourceId in project activityinfo by bedatadriven.

the class EnumValue method getValuesAsItems.

public Set<EnumItem> getValuesAsItems(EnumType enumType) {
    Map<ResourceId, EnumItem> map = new HashMap<>();
    for (EnumItem enumItem : enumType.getValues()) {
        map.put(enumItem.getId(), enumItem);
    }
    Set<EnumItem> items = Sets.newHashSet();
    for (final ResourceId resourceId : getResourceIds()) {
        EnumItem item = map.get(resourceId);
        if (item != null) {
            items.add(item);
        }
    }
    return items;
}
Also used : ResourceId(org.activityinfo.model.resource.ResourceId) HashMap(java.util.HashMap)

Example 37 with ResourceId

use of org.activityinfo.model.resource.ResourceId in project activityinfo by bedatadriven.

the class GetSitesHandler method buildQueries.

private void buildQueries() {
    TraceContext queryBuildTrace = Trace.startSpan("ai/cmd/GetSites/buildQuery");
    queryBuildTime.start();
    for (Map.Entry<ResourceId, FormTree> formTreeEntry : formTreeMap.entrySet()) {
        addToQueryMap(formTreeEntry, null);
    }
    if (command.isFetchLinks() && linkedFormTreeMap != null) {
        for (Map.Entry<ResourceId, FormTree> linkedFormTreeEntry : linkedFormTreeMap.entrySet()) {
            for (ActivityLink activityLink : activityLinkMap.get(CuidAdapter.getLegacyIdFromCuid(linkedFormTreeEntry.getKey()))) {
                addToQueryMap(linkedFormTreeEntry, activityLink);
            }
        }
    }
    queryBuildTime.stop();
    Trace.endSpan(queryBuildTrace);
}
Also used : FormTree(org.activityinfo.model.formTree.FormTree) ResourceId(org.activityinfo.model.resource.ResourceId) TraceContext(com.google.cloud.trace.core.TraceContext)

Example 38 with ResourceId

use of org.activityinfo.model.resource.ResourceId in project activityinfo by bedatadriven.

the class GetUsersHandler method execute.

@Override
public CommandResult execute(GetUsers cmd, User currentUser) {
    Database db = em.getReference(Database.class, cmd.getDatabaseId());
    UserPermission currentUserPermission = PermissionOracle.using(em).getPermissionByUser(db, currentUser);
    assertAuthorized(currentUserPermission);
    String whereClause = "up.database.id = :dbId and " + "up.user.id <> :currentUserId and " + "up.allowView = true";
    if (!currentUserPermission.isAllowManageAllUsers()) {
        whereClause += " and up.partner.id = " + currentUserPermission.getPartner().getId();
    }
    TypedQuery<UserPermission> query = em.createQuery("select up from UserPermission up where " + whereClause + " " + composeOrderByClause(cmd), UserPermission.class).setParameter("dbId", cmd.getDatabaseId()).setParameter("currentUserId", currentUser.getId());
    List<Folder> folders = em.createQuery("select f from Folder f where f.database.id = :dbId", Folder.class).setParameter("dbId", cmd.getDatabaseId()).getResultList();
    Map<ResourceId, Folder> folderMap = new HashMap<>();
    for (Folder folder : folders) {
        folderMap.put(CuidAdapter.folderId(folder.getId()), folder);
    }
    if (cmd.getOffset() > 0) {
        query.setFirstResult(cmd.getOffset());
    }
    if (cmd.getLimit() > 0) {
        query.setMaxResults(cmd.getLimit());
    }
    List<UserPermissionDTO> models = new ArrayList<>();
    for (UserPermission perm : query.getResultList()) {
        UserPermissionDTO dto = new UserPermissionDTO();
        dto.setEmail(perm.getUser().getEmail());
        dto.setName(perm.getUser().getName());
        dto.setOrganization(perm.getUser().getOrganization());
        dto.setJobtitle(perm.getUser().getJobtitle());
        dto.setAllowDesign(perm.isAllowDesign());
        dto.setAllowView(perm.isAllowView());
        dto.setAllowViewAll(perm.isAllowViewAll());
        dto.setAllowEdit(perm.isAllowEdit());
        dto.setAllowEditAll(perm.isAllowEditAll());
        dto.setAllowManageUsers(perm.isAllowManageUsers());
        dto.setAllowManageAllUsers(perm.isAllowManageAllUsers());
        dto.setPartner(new PartnerDTO(perm.getPartner().getId(), perm.getPartner().getName()));
        dto.setFolderLimitation(!Strings.isNullOrEmpty(perm.getModel()));
        dto.setFolders(folderList(folderMap, perm));
        models.add(dto);
    }
    return new UserResult(models, cmd.getOffset(), queryTotalCount(cmd, currentUser, whereClause));
}
Also used : PartnerDTO(org.activityinfo.legacy.shared.model.PartnerDTO) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Folder(org.activityinfo.server.database.hibernate.entity.Folder) UserPermissionDTO(org.activityinfo.legacy.shared.model.UserPermissionDTO) ResourceId(org.activityinfo.model.resource.ResourceId) Database(org.activityinfo.server.database.hibernate.entity.Database) UserResult(org.activityinfo.legacy.shared.command.result.UserResult) UserPermission(org.activityinfo.server.database.hibernate.entity.UserPermission)

Example 39 with ResourceId

use of org.activityinfo.model.resource.ResourceId in project activityinfo by bedatadriven.

the class CloneDatabaseHandler method copySubForm.

private FieldType copySubForm(SubFormReferenceType subFormType) {
    ResourceId oldSubFormId = subFormType.getClassId();
    ResourceId newSubFormId = ResourceId.generateId();
    typeIdMapping.put(oldSubFormId, newSubFormId);
    FormClass targetFormClass = copyFormClass(oldSubFormId, newSubFormId);
    MySqlStorageProvider mysqlStorage = (MySqlStorageProvider) this.formCatalog.get();
    mysqlStorage.createOrUpdateFormSchema(targetFormClass);
    return new SubFormReferenceType(newSubFormId);
}
Also used : SubFormReferenceType(org.activityinfo.model.type.subform.SubFormReferenceType) ResourceId(org.activityinfo.model.resource.ResourceId) CuidAdapter.activityFormClass(org.activityinfo.model.legacy.CuidAdapter.activityFormClass) MySqlStorageProvider(org.activityinfo.store.mysql.MySqlStorageProvider)

Example 40 with ResourceId

use of org.activityinfo.model.resource.ResourceId in project activityinfo by bedatadriven.

the class CloneDatabaseHandler method copyForms.

private void copyForms() {
    // first copy all activities without payload (indicators, attributes)
    for (Activity activity : sourceDb.getActivities()) {
        if (activity.isDeleted()) {
            // skip current activity if deleted...
            continue;
        }
        copyActivity(activity);
    }
    for (Activity activity : sourceDb.getActivities()) {
        if (activity.isDeleted()) {
            // skip current activity if deleted...
            continue;
        }
        final ResourceId sourceFormId = activityFormClass(activity.getId());
        final ResourceId targetFormId = activityFormClass(activityMapping.get(activity.getId()).getId());
        if (activity.isClassicView()) {
            copyClassicActivity(activity, activityMapping.get(activity.getId()));
        } else {
            FormClass targetFormClass = copyFormClass(sourceFormId, targetFormId);
            formCatalog.get().getForm(targetFormId).get().updateFormClass(targetFormClass);
        }
    }
}
Also used : ResourceId(org.activityinfo.model.resource.ResourceId) CuidAdapter.activityFormClass(org.activityinfo.model.legacy.CuidAdapter.activityFormClass)

Aggregations

ResourceId (org.activityinfo.model.resource.ResourceId)198 Test (org.junit.Test)42 FormClass (org.activityinfo.model.form.FormClass)41 FormField (org.activityinfo.model.form.FormField)34 RecordRef (org.activityinfo.model.type.RecordRef)30 JsonValue (org.activityinfo.json.JsonValue)21 FormTree (org.activityinfo.model.formTree.FormTree)18 ReferenceValue (org.activityinfo.model.type.ReferenceValue)17 FieldValue (org.activityinfo.model.type.FieldValue)16 FormInstance (org.activityinfo.model.form.FormInstance)15 HashMap (java.util.HashMap)14 QuantityType (org.activityinfo.model.type.number.QuantityType)13 ColumnSet (org.activityinfo.model.query.ColumnSet)12 QueryModel (org.activityinfo.model.query.QueryModel)12 EnumValue (org.activityinfo.model.type.enumerated.EnumValue)11 SubFormReferenceType (org.activityinfo.model.type.subform.SubFormReferenceType)11 ReferenceType (org.activityinfo.model.type.ReferenceType)10 EnumItem (org.activityinfo.model.type.enumerated.EnumItem)10 FormStorage (org.activityinfo.store.spi.FormStorage)10 ArrayList (java.util.ArrayList)9