Search in sources :

Example 1 with GeoprismUser

use of net.geoprism.GeoprismUser in project geoprism-registry by terraframe.

the class UserInfo method applyUserWithRoles.

@Transaction
public static JSONObject applyUserWithRoles(JsonObject account, String[] roleNameArray, boolean isUserInvite) {
    GeoprismUser geoprismUser = deserialize(account);
    if (roleNameArray != null && roleNameArray.length == 0) {
        // TODO : Better Error
        throw new AttributeValueException("You're attempting to apply a user with zero roles?", "");
    }
    /*
     * Make sure they have permissions to all these new roles they want to
     * assign
     */
    if (!isUserInvite && Session.getCurrentSession() != null && Session.getCurrentSession().getUser() != null) {
        Set<RoleDAOIF> myRoles = Session.getCurrentSession().getUser().authorizedRoles();
        boolean hasSRA = false;
        for (RoleDAOIF myRole : myRoles) {
            if (RegistryRole.Type.isSRA_Role(myRole.getRoleName())) {
                hasSRA = true;
            }
        }
        if (!hasSRA && roleNameArray != null) {
            for (String roleName : roleNameArray) {
                boolean hasPermission = false;
                if (RegistryRole.Type.isOrgRole(roleName) && !RegistryRole.Type.isRootOrgRole(roleName)) {
                    String orgCodeArg = RegistryRole.Type.parseOrgCode(roleName);
                    for (RoleDAOIF myRole : myRoles) {
                        if (RegistryRole.Type.isRA_Role(myRole.getRoleName())) {
                            String myOrgCode = RegistryRole.Type.parseOrgCode(myRole.getRoleName());
                            if (myOrgCode.equals(orgCodeArg)) {
                                hasPermission = true;
                                break;
                            }
                        }
                    }
                } else if (RegistryRole.Type.isSRA_Role(roleName)) {
                    SRAException ex = new SRAException();
                    throw ex;
                } else {
                    hasPermission = true;
                }
                if (!hasPermission) {
                    OrganizationRAException ex = new OrganizationRAException();
                    throw ex;
                }
            }
        }
    }
    // They're not allowed to change the admin username
    if (!geoprismUser.isNew()) {
        GeoprismUser adminUser = getAdminUser();
        if (adminUser != null && adminUser.getOid().equals(geoprismUser.getOid()) && !geoprismUser.getUsername().equals(RegistryConstants.ADMIN_USER_NAME)) {
            // TODO : Better Error
            throw new AttributeValueException("You can't change the admin username", RegistryConstants.ADMIN_USER_NAME);
        }
    }
    geoprismUser.apply();
    if (roleNameArray != null) {
        List<Roles> newRoles = new LinkedList<Roles>();
        Set<String> roleIdSet = new HashSet<String>();
        for (String roleName : roleNameArray) {
            Roles role = Roles.findRoleByName(roleName);
            roleIdSet.add(role.getOid());
            newRoles.add(role);
        }
        List<ConfigurationIF> configurations = ConfigurationService.getConfigurations();
        for (ConfigurationIF configuration : configurations) {
            configuration.configureUserRoles(roleIdSet);
        }
        UserDAOIF user = UserDAO.get(geoprismUser.getOid());
        // Remove existing roles.
        Set<RoleDAOIF> userRoles = user.assignedRoles();
        for (RoleDAOIF roleDAOIF : userRoles) {
            RoleDAO roleDAO = RoleDAO.get(roleDAOIF.getOid()).getBusinessDAO();
            if (!(geoprismUser.getUsername().equals(RegistryConstants.ADMIN_USER_NAME) && (roleDAO.getRoleName().equals(RegistryConstants.REGISTRY_SUPER_ADMIN_ROLE) || roleDAO.getRoleName().equals(DefaultConfiguration.ADMIN)))) {
                roleDAO.deassignMember(user);
            }
        }
        // Delete existing relationships with Organizations.
        QueryFactory qf = new QueryFactory();
        OrganizationUserQuery q = new OrganizationUserQuery(qf);
        q.WHERE(q.childOid().EQ(geoprismUser.getOid()));
        OIterator<? extends OrganizationUser> i = q.getIterator();
        i.forEach(r -> r.delete());
        /*
       * Assign roles and associate with the user
       */
        Set<String> organizationSet = new HashSet<String>();
        for (Roles role : newRoles) {
            RoleDAO roleDAO = (RoleDAO) BusinessFacade.getEntityDAO(role);
            roleDAO.assignMember(user);
            RegistryRole registryRole = new RegistryRoleConverter().build(role);
            if (registryRole != null) {
                String organizationCode = registryRole.getOrganizationCode();
                if (organizationCode != null && !organizationCode.equals("") && !organizationSet.contains(organizationCode)) {
                    Organization organization = Organization.getByCode(organizationCode);
                    organization.addUsers(geoprismUser).apply();
                    organizationSet.add(organizationCode);
                }
            }
        }
    }
    UserInfo info = getByUser(geoprismUser);
    if (info == null) {
        info = new UserInfo();
        info.setGeoprismUser(geoprismUser);
    } else {
        info.lock();
    }
    if (account.has(UserInfo.ALTFIRSTNAME)) {
        info.setAltFirstName(account.get(UserInfo.ALTFIRSTNAME).getAsString());
    } else {
        info.setAltFirstName("");
    }
    if (account.has(UserInfo.ALTLASTNAME)) {
        info.setAltLastName(account.get(UserInfo.ALTLASTNAME).getAsString());
    } else {
        info.setAltLastName("");
    }
    if (account.has(UserInfo.ALTPHONENUMBER)) {
        info.setAltPhoneNumber(account.get(UserInfo.ALTPHONENUMBER).getAsString());
    } else {
        info.setAltPhoneNumber("");
    }
    if (account.has(UserInfo.POSITION)) {
        info.setPosition(account.get(UserInfo.POSITION).getAsString());
    } else {
        info.setPosition("");
    }
    if (account.has(UserInfo.DEPARTMENT)) {
        info.setDepartment(account.get(UserInfo.DEPARTMENT).getAsString());
    } else {
        info.setDepartment("");
    }
    if (account.has(UserInfo.EXTERNALSYSTEMOID)) {
        info.setExternalSystemOid(account.get(UserInfo.EXTERNALSYSTEMOID).getAsString());
    } else {
        info.setExternalSystemOid("");
    }
    info.apply();
    return serialize(geoprismUser, info);
}
Also used : RegistryRole(org.commongeoregistry.adapter.metadata.RegistryRole) QueryFactory(com.runwaysdk.query.QueryFactory) Roles(com.runwaysdk.system.Roles) AttributeValueException(com.runwaysdk.dataaccess.attributes.AttributeValueException) LinkedList(java.util.LinkedList) ConfigurationIF(net.geoprism.ConfigurationIF) RegistryRoleConverter(net.geoprism.registry.conversion.RegistryRoleConverter) RoleDAO(com.runwaysdk.business.rbac.RoleDAO) GeoprismUser(net.geoprism.GeoprismUser) RoleDAOIF(com.runwaysdk.business.rbac.RoleDAOIF) UserDAOIF(com.runwaysdk.business.rbac.UserDAOIF) HashSet(java.util.HashSet) Transaction(com.runwaysdk.dataaccess.transaction.Transaction)

Example 2 with GeoprismUser

use of net.geoprism.GeoprismUser in project geoprism-registry by terraframe.

the class UserInfo method removeByUser.

@Transaction
public static void removeByUser(String userId) {
    GeoprismUser user = GeoprismUser.get(userId);
    UserInfo info = UserInfo.getByUser(user);
    if (info != null) {
        info.delete();
    }
    user.delete();
}
Also used : GeoprismUser(net.geoprism.GeoprismUser) Transaction(com.runwaysdk.dataaccess.transaction.Transaction)

Example 3 with GeoprismUser

use of net.geoprism.GeoprismUser in project geoprism-registry by terraframe.

the class UserInfo method unlockByUser.

@Transaction
public static void unlockByUser(String userId) {
    GeoprismUser user = GeoprismUser.unlock(userId);
    UserInfo info = UserInfo.getByUser(user);
    if (info != null) {
        info.unlock();
    }
}
Also used : GeoprismUser(net.geoprism.GeoprismUser) Transaction(com.runwaysdk.dataaccess.transaction.Transaction)

Example 4 with GeoprismUser

use of net.geoprism.GeoprismUser in project geoprism-registry by terraframe.

the class ETLService method getActiveImports.

@Request(RequestType.SESSION)
public JsonObject getActiveImports(String sessionId, int pageSize, int pageNumber, String sortAttr, boolean isAscending) {
    JsonArray ja = new JsonArray();
    QueryFactory qf = new QueryFactory();
    ImportHistoryQuery ihq = new ImportHistoryQuery(qf);
    ihq.WHERE(ihq.getStatus().containsExactly(AllJobStatus.RUNNING).OR(ihq.getStatus().containsExactly(AllJobStatus.NEW)).OR(ihq.getStatus().containsExactly(AllJobStatus.QUEUED)).OR(ihq.getStatus().containsExactly(AllJobStatus.FEEDBACK)));
    this.filterHistoryQueryBasedOnPermissions(ihq);
    ihq.restrictRows(pageSize, pageNumber);
    ihq.ORDER_BY(ihq.get(sortAttr), isAscending ? SortOrder.ASC : SortOrder.DESC);
    try (OIterator<? extends ImportHistory> it = ihq.getIterator()) {
        List<JsonWrapper> results = it.getAll().stream().map(hist -> {
            DataImportJob job = (DataImportJob) hist.getAllJob().getAll().get(0);
            GeoprismUser user = GeoprismUser.get(job.getRunAsUser().getOid());
            return new JsonWrapper(serializeHistory(hist, user, job));
        }).collect(Collectors.toList());
        return new Page<JsonWrapper>(ihq.getCount(), ihq.getPageNumber(), ihq.getPageSize(), results).toJSON();
    }
}
Also used : JsonArray(com.google.gson.JsonArray) JsonObject(com.google.gson.JsonObject) SortOrder(com.runwaysdk.query.OrderBy.SortOrder) Date(java.util.Date) ErrorResolution(net.geoprism.registry.etl.ImportError.ErrorResolution) ServerGeoObjectType(net.geoprism.registry.model.ServerGeoObjectType) Request(com.runwaysdk.session.Request) Condition(com.runwaysdk.query.Condition) DataExportJob(net.geoprism.registry.etl.export.DataExportJob) Organization(net.geoprism.registry.Organization) JsonWrapper(net.geoprism.registry.view.JsonWrapper) Optional(org.commongeoregistry.adapter.Optional) ServerParentTreeNodeOverTime(net.geoprism.registry.view.ServerParentTreeNodeOverTime) RoleDAOIF(com.runwaysdk.business.rbac.RoleDAOIF) JobHistory(com.runwaysdk.system.scheduler.JobHistory) Collectors(java.util.stream.Collectors) ExportHistory(net.geoprism.registry.etl.export.ExportHistory) Page(net.geoprism.registry.view.Page) List(java.util.List) JsonArray(com.google.gson.JsonArray) GraphType(net.geoprism.registry.model.GraphType) AllJobStatus(com.runwaysdk.system.scheduler.AllJobStatus) SingleActorDAOIF(com.runwaysdk.business.rbac.SingleActorDAOIF) RegistryIdService(net.geoprism.registry.service.RegistryIdService) GeoObjectImportConfiguration(net.geoprism.registry.io.GeoObjectImportConfiguration) JobHistoryRecord(com.runwaysdk.system.scheduler.JobHistoryRecord) RegistryRole(org.commongeoregistry.adapter.metadata.RegistryRole) ProgrammingErrorException(com.runwaysdk.dataaccess.ProgrammingErrorException) Transaction(com.runwaysdk.dataaccess.transaction.Transaction) GeoSynonymService(net.geoprism.registry.service.GeoSynonymService) RequestType(com.runwaysdk.session.RequestType) SimpleDateFormat(java.text.SimpleDateFormat) ExecutableJob(com.runwaysdk.system.scheduler.ExecutableJob) JsonParser(com.google.gson.JsonParser) RegistryService(net.geoprism.registry.service.RegistryService) ServiceFactory(net.geoprism.registry.service.ServiceFactory) ArrayList(java.util.ArrayList) QueryFactory(com.runwaysdk.query.QueryFactory) LinkedList(java.util.LinkedList) ImportConfiguration(net.geoprism.registry.etl.upload.ImportConfiguration) GeoObjectOverTime(org.commongeoregistry.adapter.dataaccess.GeoObjectOverTime) ServerGeoObjectIF(net.geoprism.registry.model.ServerGeoObjectIF) JsonSyntaxException(com.google.gson.JsonSyntaxException) ExportError(net.geoprism.registry.etl.export.ExportError) ServerGeoObjectService(net.geoprism.registry.geoobject.ServerGeoObjectService) IOException(java.io.IOException) ValidationResolution(net.geoprism.registry.etl.ValidationProblem.ValidationResolution) MultipartFileParameter(com.runwaysdk.controller.MultipartFileParameter) ExportErrorQuery(net.geoprism.registry.etl.export.ExportErrorQuery) OIterator(com.runwaysdk.query.OIterator) VaultFile(com.runwaysdk.system.VaultFile) GeoprismUser(net.geoprism.GeoprismUser) Session(com.runwaysdk.session.Session) RolePermissionService(net.geoprism.registry.permission.RolePermissionService) InputStream(java.io.InputStream) DataUploader(net.geoprism.DataUploader) QueryFactory(com.runwaysdk.query.QueryFactory) JsonWrapper(net.geoprism.registry.view.JsonWrapper) GeoprismUser(net.geoprism.GeoprismUser) Request(com.runwaysdk.session.Request)

Example 5 with GeoprismUser

use of net.geoprism.GeoprismUser in project geoprism-registry by terraframe.

the class ETLService method getImportDetails.

// @Request(RequestType.SESSION)
// public JSONObject getReferenceValidationProblems(String sessionId, String
// historyId, boolean onlyUnresolved, int pageSize, int pageNumber)
// {
// ImportHistory hist = ImportHistory.get(historyId);
// 
// ValidationProblemQuery vpq = new ValidationProblemQuery(new
// QueryFactory());
// vpq.WHERE(vpq.getHistory().EQ(hist).AND(vpq.getType().EQ(ParentReferenceProblem.CLASS).OR(vpq.getType().EQ(TermReferenceProblem.CLASS))));
// vpq.restrictRows(pageSize, pageNumber);
// vpq.ORDER_BY(vpq.getCreateDate(), SortOrder.ASC);
// 
// if (onlyUnresolved)
// {
// vpq.WHERE(vpq.getResolution().EQ(ErrorResolution.UNRESOLVED.name()));
// }
// 
// JSONObject page = new JSONObject();
// page.put("count", vpq.getCount());
// page.put("pageNumber", vpq.getPageNumber());
// page.put("pageSize", vpq.getPageSize());
// 
// JSONArray jaVP = new JSONArray();
// 
// OIterator<? extends ValidationProblem> it = vpq.getIterator();
// try
// {
// while (it.hasNext())
// {
// ValidationProblem vp = it.next();
// 
// jaVP.put(vp.toJSON());
// }
// }
// finally
// {
// it.close();
// }
// 
// page.put("results", jaVP);
// 
// return page;
// }
// 
// @Request(RequestType.SESSION)
// public JSONObject getRowValidationProblems(String sessionId, String
// historyId, boolean onlyUnresolved, int pageSize, int pageNumber)
// {
// ImportHistory hist = ImportHistory.get(historyId);
// 
// RowValidationProblemQuery vpq = new RowValidationProblemQuery(new
// QueryFactory());
// vpq.WHERE(vpq.getHistory().EQ(hist));
// vpq.restrictRows(pageSize, pageNumber);
// vpq.ORDER_BY(vpq.getRowNum(), SortOrder.ASC);
// 
// if (onlyUnresolved)
// {
// vpq.WHERE(vpq.getResolution().EQ(ErrorResolution.UNRESOLVED.name()));
// }
// 
// JSONObject page = new JSONObject();
// page.put("count", vpq.getCount());
// page.put("pageNumber", vpq.getPageNumber());
// page.put("pageSize", vpq.getPageSize());
// 
// JSONArray jaVP = new JSONArray();
// 
// OIterator<? extends ValidationProblem> it = vpq.getIterator();
// try
// {
// while (it.hasNext())
// {
// ValidationProblem vp = it.next();
// 
// jaVP.put(vp.toJSON());
// }
// }
// finally
// {
// it.close();
// }
// 
// page.put("results", jaVP);
// 
// return page;
// }
@Request(RequestType.SESSION)
public JsonObject getImportDetails(String sessionId, String historyId, boolean onlyUnresolved, int pageSize, int pageNumber) {
    ImportHistory hist = ImportHistory.get(historyId);
    DataImportJob job = (DataImportJob) hist.getAllJob().getAll().get(0);
    GeoprismUser user = GeoprismUser.get(job.getRunAsUser().getOid());
    hist.getConfig().enforceExecutePermissions();
    JsonObject jo = this.serializeHistory(hist, user, job);
    if (hist.getStage().get(0).equals(ImportStage.IMPORT_RESOLVE) && hist.hasImportErrors()) {
        jo.add("importErrors", this.getImportErrors(sessionId, historyId, onlyUnresolved, pageSize, pageNumber));
    } else if (hist.getStage().get(0).equals(ImportStage.VALIDATION_RESOLVE)) {
        jo.add("problems", this.getValidationProblems(sessionId, historyId, onlyUnresolved, pageSize, pageNumber));
    }
    return jo;
}
Also used : JsonObject(com.google.gson.JsonObject) GeoprismUser(net.geoprism.GeoprismUser) Request(com.runwaysdk.session.Request)

Aggregations

GeoprismUser (net.geoprism.GeoprismUser)22 Transaction (com.runwaysdk.dataaccess.transaction.Transaction)9 JsonObject (com.google.gson.JsonObject)8 Request (com.runwaysdk.session.Request)8 QueryFactory (com.runwaysdk.query.QueryFactory)7 ServerGeoObjectType (net.geoprism.registry.model.ServerGeoObjectType)6 ProgrammingErrorException (com.runwaysdk.dataaccess.ProgrammingErrorException)5 JobHistory (com.runwaysdk.system.scheduler.JobHistory)5 SimpleDateFormat (java.text.SimpleDateFormat)5 LinkedList (java.util.LinkedList)5 DataExportJob (net.geoprism.registry.etl.export.DataExportJob)5 ExportHistory (net.geoprism.registry.etl.export.ExportHistory)5 RoleDAOIF (com.runwaysdk.business.rbac.RoleDAOIF)4 SingleActorDAOIF (com.runwaysdk.business.rbac.SingleActorDAOIF)3 ArrayList (java.util.ArrayList)3 RegistryRole (org.commongeoregistry.adapter.metadata.RegistryRole)3 JsonArray (com.google.gson.JsonArray)2 JsonParser (com.google.gson.JsonParser)2 JsonSyntaxException (com.google.gson.JsonSyntaxException)2 MultipartFileParameter (com.runwaysdk.controller.MultipartFileParameter)2