public static boolean start(RootDoc root) {
   ClassDoc[] classDocs = root.classes();
   if (ArrayUtils.isNotEmpty(classDocs)) {
     for (ClassDoc classDoc : root.classes()) scanClassDoc(result.docs, classDoc);
   }
   return true;
 }
Exemplo n.º 2
0
 /**
  * 发送邮件到邮件队列
  *
  * @param vo
  * @param taskId
  */
 @SuppressWarnings("rawtypes")
 public void insertEmailQueue(MailBo vo, Integer taskId) {
   try {
     String content = freeMarkerHelper.generateContent(vo.getTemplate(), vo.getTemplateMap());
     Integer emailType =
         vo.getEmailType() == null ? MailConstants.MAIL_TYPE_SIMPLIFIED : vo.getEmailType();
     if (ArrayUtils.isNotEmpty(vo.getTo()) && StringUtils.isNotBlank(content)) {
       String sql =
           "INSERT INTO email_queue(title, from_addr, to_addr, from_name, task_id, content, email_type, create_date)"
               + " VALUES(?, ?, ?, ?, ?, ?, ?, ?)";
       jdbcTemplateCount.update(
           sql,
           vo.getSubject(),
           vo.getFrom(),
           StringUtils.join(vo.getTo(), MailConstants.MAIL_ADDRESS_SEPARATE_CHAR),
           vo.getFromName(),
           taskId,
           content,
           emailType,
           new Date());
     }
   } catch (DataAccessException e) {
     e.printStackTrace();
     logger.error("  === INSEET DATA TO email_queue ON ERROR! === ");
   }
 }
Exemplo n.º 3
0
  @Test
  public void getResourcesTest() throws IOException {
    org.springframework.core.io.Resource[] resourceArray =
        resourceLoader.getResources("classpath:log/log4j.xml");

    Assert.assertTrue(ArrayUtils.isNotEmpty(resourceArray) && resourceArray.length == 1);
  }
Exemplo n.º 4
0
 @Override
 public void action(DomainMessage domainMessage) {
   long[] id = (long[]) domainMessage.getEventSource();
   id = ArrayUtils.removeElement(id, 0);
   if (ArrayUtils.isNotEmpty(id)) {
     domainMessage.setEventResult(answerRepository.forbidAnswer(id));
   }
 }
Exemplo n.º 5
0
 public static <T> T unserialize(byte[] bytes, Class<T> t) {
   if (ArrayUtils.isNotEmpty(bytes)) {
     try {
       return gson.fromJson(new String(bytes, "UTF-8"), t);
     } catch (Exception e) {
     }
   }
   return null;
 }
 public String[] getDisplayHttpExamples() {
   ArrayList<String> l = new ArrayList<String>();
   if (ArrayUtils.isNotEmpty(httpExamples)) {
     for (String example : httpExamples) {
       if (StringUtils.isNotBlank(example)) l.add(example);
     }
   }
   return l.toArray(new String[l.size()]);
 }
  private static String[] getTags(MethodDoc methodDoc, String tagName) {
    Tag[] tags = methodDoc.tags(tagName);
    if (ArrayUtils.isNotEmpty(tags)) {
      String[] a = new String[tags.length];
      for (int i = 0; i < a.length; i++) a[i] = tags[i].text();

      return a;
    } else {
      return new String[0];
    }
  }
  private static void scanClassDoc(List<ApiDoc> apiDocs, ClassDoc classDoc) {
    AnnotationDesc[] annDescs = classDoc.annotations();
    for (AnnotationDesc annDesc : annDescs) {
      if (IgnoreDocument.class.getName().equals(annDesc.annotationType().qualifiedTypeName()))
        return;
    }

    MethodDoc[] methodDocs = classDoc.methods();
    if (ArrayUtils.isNotEmpty(methodDocs)) {
      for (MethodDoc methodDoc : methodDocs) {
        ApiDoc apiDoc = scanMethodDoc(classDoc, methodDoc);
        if (apiDoc != null) apiDocs.add(apiDoc);
      }
    }

    ClassDoc[] innerClassDocs = classDoc.innerClasses();
    if (ArrayUtils.isNotEmpty(innerClassDocs)) {
      for (ClassDoc innerClassDoc : innerClassDocs) scanClassDoc(apiDocs, innerClassDoc);
    }
  }
 /**
  * Computes GCD of the given numbers by GCD (a, b, ...) = (a * b * ...) / lcm(a, b, ...)
  *
  * @param numbers
  * @return
  */
 public static long computeGcd(Long... numbers) {
   Preconditions.checkArgument(
       ArrayUtils.isNotEmpty(numbers), "The input is either empty or null.");
   Preconditions.checkArgument(
       areAllPositiveNumbers(numbers), "There are negative numbers. Cannot continue.");
   long gcd = numbers[0];
   long lcm;
   for (long integer : numbers) {
     lcm = findLcm(integer, gcd);
     gcd = (integer * gcd) / lcm;
   }
   return gcd;
 }
 /**
  * Computes the LCM of the given number by
  *
  * <ol>
  *   <li>List all the multiples of all the numbers in ascending order.
  *   <li>Pick the first commonly occurring number from all the lists.
  * </ol>
  *
  * @param numbers
  * @return
  */
 public static long computeLcm(Long... numbers) {
   Preconditions.checkArgument(
       ArrayUtils.isNotEmpty(numbers), "The input is either empty or null.");
   Preconditions.checkArgument(
       areAllPositiveNumbers(numbers), "There are negative numbers. Cannot continue.");
   long lcm = numbers[0];
   if (numbers.length > 1) {
     for (long number : numbers) {
       lcm = findLcm(number, lcm);
     }
   }
   return lcm;
 }
Exemplo n.º 11
0
 private void checkExeuctionErrors(ProcessReports[] processReports) {
   if (samplingCount == 0
       && ArrayUtils.isNotEmpty(this.processReports)
       && ArrayUtils.isEmpty(processReports)) {
     getListeners()
         .apply(
             new Informer<ConsoleShutdownListener>() {
               public void inform(ConsoleShutdownListener listener) {
                 listener.readyToStop(StopReason.SCRIPT_ERROR);
               }
             });
   }
 }
Exemplo n.º 12
0
  protected <T> void processOnResponses(HttpMethod httpMethod, HttpInvocation<T> httpInvocation)
      throws Exception {
    int statusCode = httpMethod.getStatusCode();
    httpInvocation.onResponseStatus(statusCode);

    Header[] responseHeaders = httpMethod.getResponseHeaders();
    if (ArrayUtils.isNotEmpty(responseHeaders)) {
      for (Header header : responseHeaders) {
        httpInvocation.onResponseHeader(header.getName(), header.getValue());
      }
    }

    httpInvocation.onResponseBody(httpMethod.getResponseBodyAsStream());
  }
Exemplo n.º 13
0
 public static boolean matchAll(
     HttpServletRequest request,
     UrlPathHelper urlPathHelper,
     PathMatcher pathMatcher,
     String[] patterns) {
   if (ArrayUtils.isNotEmpty(patterns)) {
     String lookupPath = urlPathHelper.getLookupPathForRequest(request);
     for (String pattern : patterns) {
       if (!pathMatcher.match(pattern, lookupPath)) {
         return false;
       }
     }
   }
   return true;
 }
Exemplo n.º 14
0
 @TraceCall
 @Override
 public RecordSet getPages(Context ctx, long[] pageIds) {
   RecordSet pageRecs = new RecordSet();
   if (ArrayUtils.isNotEmpty(pageIds)) {
     String sql =
         new SQLBuilder.Select()
             .select(StringUtils2.splitArray(BASIC_COLS, ",", true))
             .from(pageTable)
             .where(
                 "destroyed_time=0 AND page_id IN (${page_ids})",
                 "page_ids",
                 StringUtils2.join(pageIds, ","))
             .toString();
     SQLExecutor se = getSqlExecutor();
     se.executeRecordSet(sql, pageRecs);
     attachBasicInfo(ctx, pageRecs);
   }
   return pageRecs;
 }
  @Override
  public void removeNode(
      @NotNull String parentNodePath, @NotNull String nodeName, @NotNull Long nodeId)
      throws BackingStoreException {
    remotePreferencesService.removeNode(parentNodePath, nodeName, nodeId);

    evictValue(cacheNode, parentNodePath + CACHE_KEY_SEPARATOR + nodeName);

    final String nodePath = parentNodePath + PREFERENCES_NAME_SEPARATOR + nodeName;
    evictValue(cacheNodeNames, nodePath);

    final String[] propertyKeys =
        getValue(new EmptyCallback<String[], BackingStoreException>(), cachePropertyKeys, nodePath);
    if (ArrayUtils.isNotEmpty(propertyKeys)) {
      for (String propertyKey : propertyKeys) {
        evictValue(cacheProperty, nodePath + CACHE_KEY_SEPARATOR + propertyKey);
      }
    }

    evictValue(cachePropertyKeys, nodePath);
  }
Exemplo n.º 16
0
  @TraceCall
  @Override
  public RecordSet getPagesForMe(Context ctx) {
    long viewerId = ctx.getViewerId();
    if (viewerId <= 0) return new RecordSet();

    final LinkedHashSet<Long> pageIds = new LinkedHashSet<Long>();

    String sql =
        new SQLBuilder.Select()
            .select("page_id")
            .from(pageTable)
            .where("destroyed_time=0 AND creator=${v(viewer_id)}", "viewer_id", viewerId)
            .toString();
    SQLExecutor se = getSqlExecutor();
    se.executeRecordHandler(
        sql,
        new RecordHandler() {
          @Override
          public void handle(Record rec) {
            pageIds.add(rec.getInt("page_id"));
          }
        });

    //        RecordSet groupRecs = GlobalLogics.getGroup().getGroups(ctx, Constants.GROUP_ID_BEGIN,
    // Constants.GROUP_ID_END, ctx.getViewerIdString(), "", "page_id", false);
    //        for (Record groupRec : groupRecs) {
    //            long pageId = groupRec.getInt("page_id", 0L);
    //            if (pageId > 0)
    //                pageIds.add(pageId);
    //        }

    long[] followedPageIds =
        GlobalLogics.getFriendship().getFollowedPageIds(ctx, ctx.getViewerId());
    if (ArrayUtils.isNotEmpty(followedPageIds)) {
      for (long pageId : followedPageIds) pageIds.add(pageId);
    }

    return getPages(ctx, CollectionUtils2.toLongArray(pageIds));
  }
Exemplo n.º 17
0
  private void attachBasicInfo(Context ctx, Record pageRec) {
    long pageId = pageRec.getInt("page_id", 0);

    // viewer_can_update
    if (ctx.getViewerId() >= 0 && pageRec.getInt("creator") == ctx.getViewerId()) {
      pageRec.put("viewer_can_update", true);
    } else {
      pageRec.put("viewer_can_update", false);
    }

    // logo & cover url prefix
    addImagePrefix(imagePattern, pageRec);

    // followers count
    int followersCount = GlobalLogics.getFriendship().getFollowersCount(ctx, Long.toString(pageId));
    pageRec.put("followers_count", followersCount);

    // followed
    long[] followedIds =
        GlobalLogics.getFriendship().isFollowedPages(ctx, ctx.getViewerId(), new long[] {pageId});
    pageRec.put("followed", ArrayUtils.isNotEmpty(followedIds));
  }
  /**
   * @return
   * @throws IdentityProviderManagementException
   */
  public String[] getAllLocalClaimUris() throws IdentityProviderManagementException {

    try {
      String claimDialect = LOCAL_DEFAULT_CLAIM_DIALECT;
      ClaimMapping[] claimMappings =
          CarbonContext.getThreadLocalCarbonContext()
              .getUserRealm()
              .getClaimManager()
              .getAllClaimMappings(claimDialect);
      List<String> claimUris = new ArrayList<String>();
      for (ClaimMapping claimMap : claimMappings) {
        claimUris.add(claimMap.getClaim().getClaimUri());
      }
      String[] allLocalClaimUris = claimUris.toArray(new String[claimUris.size()]);
      if (ArrayUtils.isNotEmpty(allLocalClaimUris)) {
        Arrays.sort(allLocalClaimUris);
      }
      return allLocalClaimUris;
    } catch (UserStoreException e) {
      String message = "Error while reading system claims";
      log.error(message, e);
      throw new IdentityProviderManagementException(message, e);
    }
  }
Exemplo n.º 19
0
 public boolean hasHttpReturnSections() {
   return StringUtils.isNotEmpty(httpReturn) || ArrayUtils.isNotEmpty(httpExamples);
 }
Exemplo n.º 20
0
 public boolean hasHttpParams() {
   return ArrayUtils.isNotEmpty(httpParams);
 }
Exemplo n.º 21
0
 public String getDisplayNames() {
   return ArrayUtils.isNotEmpty(names) ? StringUtils.join(names, ", ") : "";
 }
Exemplo n.º 22
0
 public static boolean isNotEmpty(ByteArray byteArray) {
   return byteArray != null && ArrayUtils.isNotEmpty(byteArray.getBytes());
 }
  private File getFromPattern(File directory, Pattern pattern) {
    File[] match = directory.listFiles(new PatternFileFilter(pattern));

    return ArrayUtils.isNotEmpty(match) ? match[0] : null;
  }
  @Override
  public void updateApplication(
      ServiceProvider serviceProvider, String tenantDomain, String userName)
      throws IdentityApplicationManagementException {
    try {

      try {
        startTenantFlow(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME);

        IdentityServiceProviderCacheKey cacheKey =
            new IdentityServiceProviderCacheKey(tenantDomain, serviceProvider.getApplicationName());

        IdentityServiceProviderCache.getInstance().clearCacheEntry(cacheKey);

      } finally {
        endTenantFlow();
        startTenantFlow(tenantDomain, userName);
      }

      // invoking the listeners
      List<ApplicationMgtListener> listeners = ApplicationMgtListenerServiceComponent.getListners();
      for (ApplicationMgtListener listener : listeners) {
        listener.updateApplication(serviceProvider);
      }

      // check whether use is authorized to update the application.
      if (!ApplicationConstants.LOCAL_SP.equals(serviceProvider.getApplicationName())
          && !ApplicationMgtUtil.isUserAuthorized(
              serviceProvider.getApplicationName(), serviceProvider.getApplicationID())) {
        log.warn(
            "Illegal Access! User "
                + CarbonContext.getThreadLocalCarbonContext().getUsername()
                + " does not have access to the application "
                + serviceProvider.getApplicationName());
        throw new IdentityApplicationManagementException("User not authorized");
      }

      ApplicationDAO appDAO = ApplicationMgtSystemConfig.getInstance().getApplicationDAO();
      String storedAppName = appDAO.getApplicationName(serviceProvider.getApplicationID());
      appDAO.updateApplication(serviceProvider);

      ApplicationPermission[] permissions =
          serviceProvider.getPermissionAndRoleConfig().getPermissions();
      String applicationNode =
          ApplicationMgtUtil.getApplicationPermissionPath()
              + RegistryConstants.PATH_SEPARATOR
              + storedAppName;
      org.wso2.carbon.registry.api.Registry tenantGovReg =
          CarbonContext.getThreadLocalCarbonContext().getRegistry(RegistryType.USER_GOVERNANCE);

      boolean exist = tenantGovReg.resourceExists(applicationNode);
      if (exist && !storedAppName.equals(serviceProvider.getApplicationName())) {
        ApplicationMgtUtil.renameAppPermissionPathNode(
            storedAppName, serviceProvider.getApplicationName());
      }

      if (ArrayUtils.isNotEmpty(permissions)) {
        ApplicationMgtUtil.updatePermissions(serviceProvider.getApplicationName(), permissions);
      }
    } catch (Exception e) {
      String error = "Error occurred while updating the application";
      log.error(error, e);
      throw new IdentityApplicationManagementException(error, e);
    } finally {
      endTenantFlow();
    }
  }
Exemplo n.º 25
0
 private void appendIfNotEmpty(StringBuilder sb, String label, Object[] array) {
   if (ArrayUtils.isNotEmpty(array)) {
     sb.append(label + ArrayUtils.toString(array));
   }
 }
Exemplo n.º 26
0
 public StyGroupPredicate(String[] stygroups) {
   stygrpset = new HashSet<String>();
   if (ArrayUtils.isNotEmpty(stygroups)) {
     stygrpset.addAll(Arrays.asList(stygroups));
   }
 }
Exemplo n.º 27
0
 private static String getTag(MethodDoc methodDoc, String tagName, String def) {
   Tag[] tags = methodDoc.tags(tagName);
   return ArrayUtils.isNotEmpty(tags) ? tags[0].text() : def;
 }
Exemplo n.º 28
0
 public StyCodePredicate(String[] stycodes) {
   stycodeset = new HashSet<String>();
   if (ArrayUtils.isNotEmpty(stycodes)) {
     stycodeset.addAll(Arrays.asList(stycodes));
   }
 }
Exemplo n.º 29
0
  /** 7、数组 */
  @Test
  public void test7() {
    // 追加元素到数组尾部
    int[] array1 = {1, 2};
    array1 = ArrayUtils.add(array1, 3); // => [1, 2, 3]

    System.out.println(array1.length); // 3
    System.out.println(array1[2]); // 3

    // 删除指定位置的元素
    int[] array2 = {1, 2, 3};
    array2 = ArrayUtils.remove(array2, 2); // => [1, 2]

    System.out.println(array2.length); // 2

    // 截取部分元素
    int[] array3 = {1, 2, 3, 4};
    array3 = ArrayUtils.subarray(array3, 1, 3); // => [2, 3]

    System.out.println(array3.length); // 2

    // 数组拷贝
    String[] array4 = {"aaa", "bbb", "ccc"};
    String[] copied = (String[]) ArrayUtils.clone(array4); // => {"aaa",
    // "bbb", "ccc"}

    System.out.println(copied.length); // 3

    // 判断是否包含某元素
    String[] array5 = {"aaa", "bbb", "ccc", "bbb"};
    boolean result1 = ArrayUtils.contains(array5, "bbb"); // => true
    System.out.println(result1); // true

    // 判断某元素在数组中出现的位置(从前往后,没有返回-1)
    int result2 = ArrayUtils.indexOf(array5, "bbb"); // => 1
    System.out.println(result2); // 1

    // 判断某元素在数组中出现的位置(从后往前,没有返回-1)
    int result3 = ArrayUtils.lastIndexOf(array5, "bbb"); // => 3
    System.out.println(result3); // 3

    // 数组转Map
    Map<Object, Object> map =
        ArrayUtils.toMap(new String[][] {{"key1", "value1"}, {"key2", "value2"}});
    System.out.println(map.get("key1")); // "value1"
    System.out.println(map.get("key2")); // "value2"

    // 判断数组是否为空
    Object[] array61 = new Object[0];
    Object[] array62 = null;
    Object[] array63 = new Object[] {"aaa"};

    System.out.println(ArrayUtils.isEmpty(array61)); // true
    System.out.println(ArrayUtils.isEmpty(array62)); // true
    System.out.println(ArrayUtils.isNotEmpty(array63)); // true

    // 判断数组长度是否相等
    Object[] array71 = new Object[] {"aa", "bb", "cc"};
    Object[] array72 = new Object[] {"dd", "ee", "ff"};

    System.out.println(ArrayUtils.isSameLength(array71, array72)); // true

    // 判断数组元素内容是否相等
    Object[] array81 = new Object[] {"aa", "bb", "cc"};
    Object[] array82 = new Object[] {"aa", "bb", "cc"};

    System.out.println(ArrayUtils.isEquals(array81, array82));

    // Integer[] 转化为 int[]
    Integer[] array9 = new Integer[] {1, 2};
    int[] result = ArrayUtils.toPrimitive(array9);

    System.out.println(result.length); // 2
    System.out.println(result[0]); // 1

    // int[] 转化为 Integer[]
    int[] array10 = new int[] {1, 2};
    Integer[] result10 = ArrayUtils.toObject(array10);

    System.out.println(result.length); // 2
    System.out.println(result10[0].intValue()); // 1
  }