Пример #1
0
 public JobContext deserialize(
     JsonElement jejson, Type typeOfT, JsonDeserializationContext context)
     throws JsonParseException {
   try {
     JsonObject json = jejson.getAsJsonObject();
     String context_class = json.get("classname").getAsString();
     JobContext result = AppManager.instanceClassForName(context_class, JobContext.class);
     result.contextFromJson(json.getAsJsonObject("content"));
     result.neededstorages =
         AppManager.getGson().fromJson(json.get("neededstorages"), type_String_AL);
     result.hookednames = AppManager.getGson().fromJson(json.get("hookednames"), type_String_AL);
     return result;
   } catch (Exception e) {
     Loggers.Manager.error("Can't deserialize json source:\t" + jejson.toString(), e);
     throw new JsonParseException("Invalid context class: " + jejson.toString(), e);
   }
 }
Пример #2
0
    static String prepareContextKeyForTrigger(JobContext context) {
      if (context == null) {
        throw new NullPointerException("\"context\" can't to be null");
      }
      StringBuffer sb = new StringBuffer();
      sb.append(context.getClass().getName());

      if (context.neededstorages != null) {
        /** Copy storagesneeded for not alter actual order in Context. */
        ArrayList<String> storagesneeded_sorted = new ArrayList<String>();
        storagesneeded_sorted.addAll(context.neededstorages);
        Collections.sort(storagesneeded_sorted);
        for (int pos = 0; pos < storagesneeded_sorted.size(); pos++) {
          sb.append("/storage:");
          sb.append(storagesneeded_sorted.get(pos));
        }
      }

      if (context.hookednames != null) {
        /** Copy hookednames for not alter actual order in Context. */
        ArrayList<String> hookednames_sorted = new ArrayList<String>();
        hookednames_sorted.addAll(context.hookednames);
        Collections.sort(hookednames_sorted);
        for (int pos = 0; pos < hookednames_sorted.size(); pos++) {
          sb.append("/hookname:");
          sb.append(hookednames_sorted.get(pos));
        }
      }

      try {
        MessageDigest md = MessageDigest.getInstance("MD5");
        md.update(sb.toString().getBytes());
        return "jobcontext:" + MyDMAM.byteToString(md.digest());
      } catch (Exception e) {
        Loggers.Manager.error("Can't compute digest", e);
        return sb.toString();
      }
    }