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;
}
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);
}
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));
}
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);
}
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);
}
}
}
Aggregations