Esempio n. 1
0
  public Map<String, String> getSource(String type) {
    Map<String, Object> parameterMap = new HashMap<String, Object>();

    if (appId != null) {
      parameterMap.put("appId", appId);
    }

    try {
      String content = httpHandler.readText(url, parameterMap);
      logger.info(content);

      JsonMapper jsonMapper = new JsonMapper();
      List<Map> list = jsonMapper.fromJson(content, List.class);

      Map<String, String> resourceMap = new LinkedHashMap<String, String>();

      for (Map map : list) {
        String access = (String) map.get("access");
        String permission = (String) map.get("permission");

        if (resourceMap.containsKey(access)) {
          String value = resourceMap.get(access);
          resourceMap.put(access, value + "," + permission);
        } else {
          resourceMap.put(access, permission);
        }
      }

      return resourceMap;
    } catch (Exception ex) {
      logger.error("", ex);
      throw new RuntimeException(ex);
    }
  }
  public UserInfo getUserInfo(String username, String appId, String repoCode) {
    Map<String, Object> parameterMap = new HashMap<String, Object>();
    parameterMap.put("username", username);
    parameterMap.put("appId", appId);
    parameterMap.put("repoCode", repoCode);

    try {
      String content = httpHandler.readText(url, parameterMap);
      logger.info(content);

      JsonMapper jsonMapper = new JsonMapper();
      Map map = jsonMapper.fromJson(content, Map.class);
      logger.debug("{}", map);

      long userId = ((Number) map.get("userId")).longValue();

      List<String> authorities = (List<String>) map.get("authorities");
      List<String> attributes = (List<String>) map.get("attributes");

      UserInfoImpl userInfo = new UserInfoImpl();
      userInfo.setUsername(username);
      userInfo.setPassword((String) map.get("password"));
      userInfo.setAuthorities(authorities);
      userInfo.setAttributes(attributes);
      userInfo.getExtra().put("userId", userId);
      userInfo.getExtra().put("appId", appId);

      return userInfo;
    } catch (Exception ex) {
      logger.error(ex.getMessage(), ex);
      throw new UsernameNotFoundException(username, ex);
    }
  }
Esempio n. 3
0
  public void handleMessage(String message) {
    try {
      ScopeDTO scopeDto = jsonMapper.fromJson(message, ScopeDTO.class);

      if (scopeDto.getName() == null) {
        scopeCache.removeScope(scopeDto);
        logger.info("remove scopeDto : {}", message);
      } else {
        scopeCache.updateScope(scopeDto);
        logger.info("update scopeDto : {}", message);
      }
    } catch (IOException ex) {
      logger.error(ex.getMessage(), ex);
    }
  }
Esempio n. 4
0
  @POST
  @Path("tasks")
  @Produces(MediaType.APPLICATION_JSON)
  public BaseDTO tasks(@HeaderParam("sessionId") String sessionId) throws Exception {
    logger.info("start");

    PimDevice pimDevice = pimDeviceManager.findUniqueBy("sessionId", sessionId);

    if (pimDevice == null) {
      BaseDTO result = new BaseDTO();
      result.setCode(401);
      result.setMessage("auth fail");

      return result;
    }

    String userId = pimDevice.getUserId();
    String tenantId = "1";
    Page page = humanTaskConnector.findPersonalTasks(userId, tenantId, 1, 10);
    List<HumanTaskDTO> humanTaskDtos = (List<HumanTaskDTO>) page.getResult();
    List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();

    DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

    for (HumanTaskDTO humanTaskDto : humanTaskDtos) {
      Map<String, Object> map = new HashMap<String, Object>();
      map.put("id", humanTaskDto.getId());
      map.put("name", humanTaskDto.getName());
      map.put("presentationSubject", humanTaskDto.getPresentationSubject());
      map.put("createTime", dateFormat.format(humanTaskDto.getCreateTime()));
      map.put("assignee", humanTaskDto.getAssignee());
      map.put("assigneeDisplayName", userConnector.findById(userId).getDisplayName());
      list.add(map);
    }

    String json = jsonMapper.toJson(list);
    BaseDTO result = new BaseDTO();
    result.setCode(200);
    result.setData(json);
    logger.info("end");

    return result;
  }
Esempio n. 5
0
  public void handleMessage(String message) {
    try {
      UserDTO userDto = jsonMapper.fromJson(message, UserDTO.class);

      Long typeId = 1L;
      Long entityId = this.getPartyEntityId(userDto.getId(), typeId);

      if (entityId == null) {
        return;
      }

      Long structTypeId = 1L;
      jdbcTemplate.update(removePartyStructSql, structTypeId, entityId, entityId);

      jdbcTemplate.update(removePartyEntitySql, entityId);

      logger.info("update user : {}", message);
    } catch (IOException ex) {
      logger.error(ex.getMessage(), ex);
    }
  }
Esempio n. 6
0
 public String getJsonData() throws Exception {
   Map<String, Object> map = new HashMap<String, Object>();
   for (Map.Entry<String, XformField> entry : fieldMap.entrySet()) {
     XformField xformField = entry.getValue();
     if (xformField.getName() == null) {
       continue;
     }
     if ("fileupload".equals(xformField.getType())) {
       if (xformField.getValue() == null) {
         continue;
       }
       Map<String, Object> data = new HashMap<String, Object>();
       data.put("key", xformField.getValue());
       data.put("label", xformField.getLabel());
       map.put(xformField.getName(), data);
     } else {
       map.put(xformField.getName(), xformField.getValue());
     }
   }
   return jsonMapper.toJson(map);
 }
Esempio n. 7
0
  @POST
  @Path("completeTask")
  @Produces(MediaType.APPLICATION_JSON)
  public BaseDTO completeTask(
      @HeaderParam("sessionId") String sessionId,
      @FormParam("taskId") String taskId,
      @FormParam("data") String data)
      throws Exception {
    logger.info("start : {} {}", taskId, data);

    String humanTaskId = taskId;

    PimDevice pimDevice = pimDeviceManager.findUniqueBy("sessionId", sessionId);

    if (pimDevice == null) {
      BaseDTO result = new BaseDTO();
      result.setCode(401);
      result.setMessage("auth fail");

      return result;
    }

    String userId = pimDevice.getUserId();
    String tenantId = "1";

    Map<String, Object> map = jsonMapper.fromJson(data, Map.class);
    map.put("taskId", humanTaskId);

    Record record = null;
    FormParameter formParameter = null;
    HumanTaskDTO humanTaskDto = null;
    FormDTO formDto = null;

    formParameter = doSaveRecord(map, userId, tenantId);

    humanTaskId = formParameter.getHumanTaskId();
    operationService.saveDraft(userId, tenantId, formParameter);

    formDto = humanTaskConnector.findTaskForm(humanTaskId);

    humanTaskDto = humanTaskConnector.findHumanTask(humanTaskId);

    String processInstanceId = humanTaskDto.getProcessInstanceId();
    record = keyValueConnector.findByRef(processInstanceId);

    record = new RecordBuilder().build(record, formParameter.getMultiValueMap(), tenantId);

    keyValueConnector.save(record);

    Xform xform =
        new XformBuilder()
            .setStoreConnector(storeConnector)
            .setContent(formDto.getContent())
            .setRecord(record)
            .build();
    Map<String, Object> taskParameters = xform.getMapData();
    logger.info("taskParameters : {}", taskParameters);

    String comment = "";
    String action = "";

    try {
      humanTaskConnector.completeTask(humanTaskId, userId, action, comment, taskParameters);
    } catch (IllegalStateException ex) {
      logger.error(ex.getMessage(), ex);

      return null;
    }

    if (record == null) {
      record = new Record();
    }

    record = new RecordBuilder().build(record, STATUS_RUNNING, humanTaskDto.getProcessInstanceId());
    keyValueConnector.save(record);

    BaseDTO result = new BaseDTO();
    result.setCode(200);
    result.setData(data);
    logger.info("end");

    return result;
  }