public Result<ActionPlan> createActionPlan(Map<String, String> parameters) {
   Result<ActionPlan> result = createActionPlanResult(parameters);
   if (result.ok()) {
     result.set(actionPlanService.create(result.get(), UserSession.get()));
   }
   return result;
 }
  /** Create manual issue */
  public Result<DefaultIssue> create(Map<String, String> params) {
    Result<DefaultIssue> result = Result.of();
    try {
      // mandatory parameters
      String componentKey = params.get("component");
      if (StringUtils.isBlank(componentKey)) {
        result.addError("Component is not set");
      }
      RuleKey ruleKey = null;
      String rule = params.get("rule");
      if (StringUtils.isBlank(rule)) {
        result.addError(Result.Message.ofL10n("issue.manual.missing_rule"));
      } else {
        ruleKey = RuleKey.parse(rule);
      }

      if (result.ok()) {
        DefaultIssue issue =
            issueService.createManualIssue(
                componentKey,
                ruleKey,
                RubyUtils.toInteger(params.get("line")),
                params.get("message"),
                params.get("severity"),
                RubyUtils.toDouble(params.get("effortToFix")),
                UserSession.get());
        result.set(issue);
      }

    } catch (Exception e) {
      result.addError(e.getMessage());
    }
    return result;
  }
 public Result<ActionPlan> openActionPlan(String actionPlanKey) {
   Result<ActionPlan> result = createResultForExistingActionPlan(actionPlanKey);
   if (result.ok()) {
     result.set(
         actionPlanService.setStatus(actionPlanKey, ActionPlan.STATUS_OPEN, UserSession.get()));
   }
   return result;
 }
 public Result<Issue> executeAction(String issueKey, String actionKey) {
   Result<Issue> result = Result.of();
   try {
     result.set(actionService.execute(issueKey, actionKey, UserSession.get()));
   } catch (Exception e) {
     result.addError(e.getMessage());
   }
   return result;
 }
 public Result<IssueComment> editComment(String commentKey, String newText) {
   Result<IssueComment> result = Result.of();
   try {
     result.set(commentService.editComment(commentKey, newText, UserSession.get()));
   } catch (Exception e) {
     result.addError(e.getMessage());
   }
   return result;
 }
 public Result<Issue> plan(String issueKey, @Nullable String actionPlanKey) {
   Result<Issue> result = Result.of();
   try {
     result.set(issueService.plan(issueKey, actionPlanKey, UserSession.get()));
   } catch (Exception e) {
     result.addError(e.getMessage());
   }
   return result;
 }
 public Result<IssueComment> addComment(String issueKey, String text) {
   Result<IssueComment> result = Result.of();
   try {
     result.set(commentService.addComment(issueKey, text, UserSession.get()));
   } catch (Exception e) {
     result.addError(e.getMessage());
   }
   return result;
 }
 public Result<Issue> setSeverity(String issueKey, String severity) {
   Result<Issue> result = Result.of();
   try {
     result.set(issueService.setSeverity(issueKey, severity, UserSession.get()));
   } catch (Exception e) {
     result.addError(e.getMessage());
   }
   return result;
 }
 public Result<Issue> doTransition(String issueKey, String transitionKey) {
   Result<Issue> result = Result.of();
   try {
     result.set(issueService.doTransition(issueKey, transitionKey, UserSession.get()));
   } catch (Exception e) {
     result.addError(e.getMessage());
   }
   return result;
 }
 public Result<Issue> assign(String issueKey, @Nullable String assignee) {
   Result<Issue> result = Result.of();
   try {
     result.set(
         issueService.assign(
             issueKey, StringUtils.defaultIfBlank(assignee, null), UserSession.get()));
   } catch (Exception e) {
     result.addError(e.getMessage());
   }
   return result;
 }
Пример #11
0
 private void findValue(Class[] classes, int currentDistance, Result result) {
   if (currentDistance >= result.distance) {
     return;
   }
   for (int i = 0; i < classes.length; i++) {
     Class clazz = classes[i];
     if (class2Value.containsKey(clazz)) {
       Object value = class2Value.get(clazz);
       result.set(value, currentDistance);
     } else {
       Class[] superClassifiers = getSuperClassifiers(clazz);
       findValue(superClassifiers, currentDistance + 1, result);
     }
   }
 }
  @VisibleForTesting
  Result<ActionPlan> createActionPlanResult(
      Map<String, String> parameters, @Nullable DefaultActionPlan existingActionPlan) {
    Result<ActionPlan> result = Result.of();

    String name = parameters.get(NAME_PARAM);
    String description = parameters.get(DESCRIPTION_PARAM);
    String deadLineParam = parameters.get("deadLine");
    String projectParam = parameters.get(PROJECT_PARAM);

    checkMandatorySizeParameter(name, NAME_PARAM, 200, result);
    checkOptionalSizeParameter(description, DESCRIPTION_PARAM, 1000, result);

    // Can only set project on creation
    if (existingActionPlan == null) {
      checkProject(projectParam, result);
    }
    Date deadLine = checkAndReturnDeadline(deadLineParam, result);

    // TODO move this check in the service, on creation and update
    if (!Strings.isNullOrEmpty(projectParam)
        && !Strings.isNullOrEmpty(name)
        && isActionPlanNameAvailable(existingActionPlan, name, projectParam)) {
      result.addError(Result.Message.ofL10n("action_plans.same_name_in_same_project"));
    }

    if (result.ok()) {
      DefaultActionPlan actionPlan =
          DefaultActionPlan.create(name)
              .setDescription(description)
              .setUserLogin(UserSession.get().login())
              .setDeadLine(deadLine);

      // Can only set project on creation
      if (existingActionPlan == null) {
        actionPlan.setProjectKey(projectParam);
      } else {
        actionPlan.setProjectKey(existingActionPlan.projectKey());
      }

      result.set(actionPlan);
    }
    return result;
  }
 public Result<ActionPlan> updateActionPlan(String key, Map<String, String> parameters) {
   DefaultActionPlan existingActionPlan =
       (DefaultActionPlan) actionPlanService.findByKey(key, UserSession.get());
   if (existingActionPlan == null) {
     Result<ActionPlan> result = Result.of();
     result.addError(
         Result.Message.ofL10n(ACTION_PLANS_ERRORS_ACTION_PLAN_DOES_NOT_EXIST_MESSAGE, key));
     return result;
   } else {
     Result<ActionPlan> result = createActionPlanResult(parameters, existingActionPlan);
     if (result.ok()) {
       DefaultActionPlan actionPlan = (DefaultActionPlan) result.get();
       actionPlan.setKey(existingActionPlan.key());
       actionPlan.setUserLogin(existingActionPlan.userLogin());
       result.set(actionPlanService.update(actionPlan, UserSession.get()));
     }
     return result;
   }
 }
  /**
   * Finds a key. Values can be read with the supplied result object.
   *
   * @param key Key buffer.
   * @param offset the offset to the key in the buffer
   * @param hashMapResult The object to fill in that can read the values.
   * @param readPos Holds mutable read position for thread safety.
   * @return The state byte.
   */
  private byte getValueResult(
      byte[] key, int offset, int length, Result hashMapResult, WriteBuffers.Position readPos) {

    hashMapResult.forget();

    // First, find first record for the key.
    long ref = findKeyRefToRead(key, offset, length, readPos);
    if (ref == 0) {
      return 0;
    }

    boolean hasList = Ref.hasList(ref);

    // This relies on findKeyRefToRead doing key equality check and leaving read ptr where needed.
    long offsetAfterListRecordKeyLen = hasList ? writeBuffers.getReadPoint(readPos) : 0;

    hashMapResult.set(this, Ref.getOffset(ref), hasList, offsetAfterListRecordKeyLen, readPos);

    return Ref.getStateByte(ref);
  }
Пример #15
0
  @Nonnull
  public static Result getType(
      @Nonnull String text,
      int i,
      boolean hexMode,
      @Nonnull Result result,
      @Nonnull Engine engine) {
    if (i < 0) {
      throw new IllegalArgumentException("I must be more or equals to 0.");
    } else if (i >= text.length() && i != 0) {
      throw new IllegalArgumentException("I must be less than size of text.");
    } else if (i == 0 && text.length() == 0) {
      return result.set(MathType.text, text);
    }
    final List<MathType> mathTypes = getMathTypesByPriority();
    for (int j = 0; j < mathTypes.size(); j++) {
      final MathType mathType = mathTypes.get(j);
      final String s = App.find(mathType.getTokens(engine), text, i);
      if (s == null) {
        continue;
      }

      if (s.length() > 1) {
        if (mathType == function) {
          final int nextToken = i + s.length();
          if (nextToken < text.length()) {
            // function must have an open group symbol after its name
            if (MathType.open_group_symbol
                .getTokens()
                .contains(text.substring(nextToken, nextToken + 1))) {
              return result.set(function, s);
            }
          } else if (nextToken == text.length()) {
            // or its name should finish the expression
            return result.set(function, s);
          }
          continue;
        }
        return result.set(mathType, s);
      }

      if (hexMode || JsclMathEngine.getInstance().getNumeralBase() == NumeralBase.hex) {
        final Character ch = s.charAt(0);
        if (NumeralBase.hex.getAcceptableCharacters().contains(ch)) {
          return result.set(MathType.digit, s);
        }
      }

      if (mathType == MathType.grouping_separator) {
        if (i + 1 < text.length()
            && MathType.digit.getTokens().contains(text.substring(i + 1, i + 2))
            && i - 1 >= 0
            && MathType.digit.getTokens().contains(text.substring(i - 1, i))) {
          return result.set(mathType, s);
        }
        continue;
      }

      return result.set(mathType, s);
    }

    return result.set(MathType.text, text.substring(i));
  }