示例#1
1
    public void reduce(Text key, Iterable<Text> values, Context context)
        throws IOException, InterruptedException {

      String keyS = key.toString();
      if (keyS.startsWith("O") || keyS.startsWith("P") || keyS.startsWith("S")) {
        String sum = new String();

        for (Text val : values) {

          sum += (" " + val.toString());
        }

        // String subKey = keyS.substring(0,keyS.length()-1);

        // Text t = new Text();
        // t.set(subKey);
        result.set(sum);
        context.write(key, result);
      }
      if (keyS.startsWith("L")) {
        //	String [] keyIdS = keyS.substring(1).split("[+]");

        result.set(" ");
        context.write(key, result);

        // String KeyIdS1 = keyIdS[1];
        // result.set(KeyIdS1);
        // context.write(key, result);

        // String KeyIdS2 = keyIdS[2];
        // result.set(KeyIdS2);
        // context.write(key, result);

      }
    }
 public void map(LongWritable key, Text value, Context context)
     throws IOException, InterruptedException {
   String cur_file =
       ((FileSplit) context.getInputSplit()).getPath().getParent().getParent().getName();
   String train_file = context.getConfiguration().get("train_file");
   if (cur_file.equals(train_file)) {
     StringTokenizer st = new StringTokenizer(value.toString());
     String word = st.nextToken();
     String f_id = st.nextToken();
     myKey.set(word);
     myVal.set(f_id);
     context.write(myKey, myVal);
   } else {
     StringTokenizer st = new StringTokenizer(value.toString());
     String word = st.nextToken();
     String f_id = st.nextToken();
     StringBuilder builder = new StringBuilder(dlt);
     while (st.hasMoreTokens()) {
       String filename = st.nextToken();
       String tf_idf = st.nextToken();
       builder.append(filename);
       builder.append(dlt);
       builder.append(tf_idf);
       builder.append("\t");
     }
     myKey.set(word);
     myVal.set(builder.toString());
     context.write(myKey, myVal);
   }
 }
 public static boolean testCommand(
     final Context context,
     final String command,
     final String contains,
     final List<String> arguments) {
   try {
     final List<String> commandAndArgs = new ArrayList<String>();
     commandAndArgs.add(command);
     commandAndArgs.addAll(arguments);
     final ProcessBuilder pb = new ProcessBuilder(commandAndArgs);
     logCommand(context, pb);
     final Process compilation = pb.start();
     final ConsumeStream result = ConsumeStream.start(compilation.getInputStream(), null);
     final ConsumeStream error = ConsumeStream.start(compilation.getErrorStream(), null);
     compilation.waitFor();
     result.join();
     error.join();
     return error.output.toString().contains(contains)
         || result.output.toString().contains(contains);
   } catch (IOException ex) {
     context.log(ex.getMessage());
     return false;
   } catch (InterruptedException ex) {
     context.log(ex.getMessage());
     return false;
   }
 }
示例#4
1
  private static void defineProperties(Context cx, JaggeryContext context, ScriptableObject scope) {

    JavaScriptProperty request = new JavaScriptProperty("request");
    HttpServletRequest servletRequest = (HttpServletRequest) context.getProperty(SERVLET_REQUEST);
    request.setValue(cx.newObject(scope, "Request", new Object[] {servletRequest}));
    request.setAttribute(ScriptableObject.READONLY);
    RhinoEngine.defineProperty(scope, request);

    JavaScriptProperty response = new JavaScriptProperty("response");
    HttpServletResponse servletResponse =
        (HttpServletResponse) context.getProperty(SERVLET_RESPONSE);
    response.setValue(cx.newObject(scope, "Response", new Object[] {servletResponse}));
    response.setAttribute(ScriptableObject.READONLY);
    RhinoEngine.defineProperty(scope, response);

    JavaScriptProperty session = new JavaScriptProperty("session");
    session.setValue(cx.newObject(scope, "Session", new Object[] {servletRequest.getSession()}));
    session.setAttribute(ScriptableObject.READONLY);
    RhinoEngine.defineProperty(scope, session);

    JavaScriptProperty application = new JavaScriptProperty("application");
    ServletContext servletConext = (ServletContext) context.getProperty(Constants.SERVLET_CONTEXT);
    application.setValue(cx.newObject(scope, "Application", new Object[] {servletConext}));
    application.setAttribute(ScriptableObject.READONLY);
    RhinoEngine.defineProperty(scope, application);

    if (isWebSocket(servletRequest)) {
      JavaScriptProperty websocket = new JavaScriptProperty("webSocket");
      websocket.setValue(cx.newObject(scope, "WebSocket", new Object[0]));
      websocket.setAttribute(ScriptableObject.READONLY);
      RhinoEngine.defineProperty(scope, websocket);
    }
  }
示例#5
0
    public void reduce(Text key, Iterable<IntWritable> values, Context context)
        throws IOException, InterruptedException {
      int sum = 0;
      boolean filtered = true;
      String keypair = key.toString();
      String[] keys = keypair.split(" ");
      if (keys.length == 1) {
        filtered = false;
      } else {
        if (keys[0].equals("*") || keys[1].equals("*")) {
          filtered = false;
        }
      }

      if (!filtered) {
        for (IntWritable val : values) {
          sum += val.get();
        }
        context.write(key, new IntWritable(sum));
        return;
      }

      for (IntWritable val : values) {
        if (val.get() == -1) {
          filtered = false;
          continue;
        }
        sum += val.get();
      }
      // filter non-needed events
      if (filtered) return;
      context.write(key, new IntWritable(sum));
    }
示例#6
0
  public Expr dropNoncompArgs(Context ctxt) {
    if (ctxt.getFlag("debug_drop_noncomp")) {
      ctxt.w.println("Dropping non-comp arguments from term-app " + toString(ctxt));
      ctxt.w.flush();
    }
    ArrayList nX = new ArrayList();
    ArrayList no = new ArrayList();
    boolean changed = false;
    Boolean b = new Boolean(false);
    for (int i = 0, iend = X.length; i < iend; i++) {
      if (X[i].isProof(ctxt) || specarg[i]) changed = true;
      else {
        nX.add(X[i]);
        no.add(b);
      }
    }

    Expr ret = this;
    if (changed) {
      if (nX.size() == 0) ret = head;
      else ret = new TermApp(head, Parser.toExprArray(nX), Parser.toBooleanArray(no));
    }

    if (ctxt.getFlag("debug_drop_noncomp")) {
      ctxt.w.println("Returning " + ret.toString(ctxt));
      ctxt.w.flush();
    }

    return ret;
  }
示例#7
0
  public Expr classify(Context ctxt, int approx, boolean spec) {
    if (ctxt.getFlag("debug_classify_term_apps")) {
      ctxt.w.print("(Classifying ");
      print(ctxt.w, ctxt);
      ctxt.w.println("");
      ctxt.w.flush();
    }
    Expr cl = head.classify(ctxt, approx, spec).defExpandTop(ctxt, false, spec);
    Expr ret = apply_classifier(FUN_TYPE, approx, spec, ctxt, cl, 0);
    FunType ch = (FunType) ((FunType) cl).coalesce(ctxt, spec);
    boolean check_spec_terminates = ctxt.getFlag("check_spec_terminates");
    for (int i = 0; i < X.length; i++) {
      if (ch.owned[i].status == Ownership.SPEC) {
        if (check_spec_terminates) X[i].checkTermination(ctxt);
        specarg[i] = true;
      }
    }
    if (ctxt.getFlag("debug_classify_term_apps")) {
      ctxt.w.println(") Classifier is:");
      ret.print(ctxt.w, ctxt);
      ctxt.w.println("");
      ctxt.w.flush();
    }

    return ret;
  }
  @Override
  public WorkspaceItem abort(Context c, XmlWorkflowItem wi, EPerson e)
      throws AuthorizeException, SQLException, IOException {
    if (!authorizeService.isAdmin(c)) {
      throw new AuthorizeException("You must be an admin to abort a workflow");
    }

    c.turnOffAuthorisationSystem();
    // Restore permissions for the submitter
    // convert into personal workspace
    WorkspaceItem wsi = returnToWorkspace(c, wi);

    log.info(
        LogManager.getHeader(
            c,
            "abort_workflow",
            "workflow_item_id="
                + wi.getID()
                + "item_id="
                + wsi.getItem().getID()
                + "collection_id="
                + wi.getCollection().getID()
                + "eperson_id="
                + e.getID()));

    c.restoreAuthSystemState();
    return wsi;
  }
示例#9
0
  /**
   * Utility method which dynamically binds a Context to the current thread, if none already exists.
   */
  public static Object callMethod(
      ContextFactory factory,
      final Scriptable thisObj,
      final Function f,
      final Object[] args,
      final long argsToWrap) {
    if (f == null) {
      // See comments in getFunction
      return Undefined.instance;
    }
    if (factory == null) {
      factory = ContextFactory.getGlobal();
    }

    final Scriptable scope = f.getParentScope();
    if (argsToWrap == 0) {
      return Context.call(factory, f, scope, thisObj, args);
    }

    Context cx = Context.getCurrentContext();
    if (cx != null) {
      return doCall(cx, scope, thisObj, f, args, argsToWrap);
    } else {
      return factory.call(
          new ContextAction() {
            public Object run(Context cx) {
              return doCall(cx, scope, thisObj, f, args, argsToWrap);
            }
          });
    }
  }
  @Test(groups = "dev")
  public void autoWrapTest() throws EventDeliveryException {
    ctx.put(MongoSink.AUTO_WRAP, Boolean.toString(true));
    ctx.put(MongoSink.DB_NAME, "test_wrap");

    MongoSink sink = new MongoSink();
    Configurables.configure(sink, ctx);

    sink.setChannel(channel);
    sink.start();

    Transaction tx = channel.getTransaction();
    tx.begin();
    String msg =
        "2012/10/26 11:23:08 [error] 7289#0: *6430831 open() \"/usr/local/nginx/html/50x.html\" failed (2: No such file or directory), client: 10.160.105.161, server: sg15.redatoms.com, request: \"POST /mojo/ajax/embed HTTP/1.0\", upstream: \"fastcgi://unix:/tmp/php-fpm.sock:\", host: \"sg15.redatoms.com\", referrer: \"http://sg15.redatoms.com/mojo/mobile/package\"";

    Event e = EventBuilder.withBody(msg.getBytes());
    channel.put(e);
    tx.commit();
    tx.close();

    sink.process();
    sink.stop();

    DB db = mongo.getDB("test_wrap");
    DBCollection collection = db.getCollection("test_log");
    DBCursor cursor = collection.find(new BasicDBObject(MongoSink.DEFAULT_WRAP_FIELD, msg));
    assertTrue(cursor.hasNext());
    DBObject dbObject = cursor.next();
    assertNotNull(dbObject);
    assertEquals(dbObject.get(MongoSink.DEFAULT_WRAP_FIELD), msg);
    mongo.dropDatabase("test_wrap");
  }
  /** Only used by cache implementations */
  protected void cacheInit() {
    if (simpleCache != null || cacheWithWhereClause != null) return;
    String where = context.getEntityAttribute("where");

    String cacheKey = context.getEntityAttribute(CACHE_KEY);
    String lookupKey = context.getEntityAttribute(CACHE_LOOKUP);
    if (cacheKey != null && lookupKey == null) {
      throw new DataImportHandlerException(
          DataImportHandlerException.SEVERE,
          "'cacheKey' is specified for the entity " + entityName + " but 'cacheLookup' is missing");
    }
    if (where == null && cacheKey == null) {
      simpleCache = new HashMap<String, List<Map<String, Object>>>();
    } else {
      if (where != null) {
        String[] splits = where.split("=");
        cachePk = splits[0];
        cacheVariableName = splits[1].trim();
      } else {
        cachePk = cacheKey;
        cacheVariableName = lookupKey;
      }
      cacheWithWhereClause = new HashMap<String, Map<Object, List<Map<String, Object>>>>();
    }
  }
    public void map(LongWritable key, Text value, Context context)
        throws IOException, InterruptedException {
      HashMap<String, Integer> wordCounts = new HashMap<String, Integer>();
      String article = value.toString();
      String articleName = article.substring(0, article.indexOf("\t"));
      String articleContent = article.substring(article.indexOf("\t") + 1);
      Iterable<String> words = parseWords(context, articleContent);
      int wordCount = 0;

      for (String word : words) {
        if (!topWords.contains(word)) {
          addCount(wordCounts, word);
        }
        wordCount++;
      }

      for (java.util.Map.Entry<String, Integer> wordAndCount : wordCounts.entrySet()) {
        double frequency = ((double) wordAndCount.getValue()) / wordCount;
        String word = wordAndCount.getKey();
        textWritable.set(word);
        articleNameAndFrequency.set(articleName, frequency);
        context.write(textWritable, articleNameAndFrequency);
      }
      context.getCounter(Counters.ARTICLE_COUNTER).increment(1);
    }
示例#13
0
  @Override
  public void init(Context context, Properties initProps) {
    initProps = decryptPwd(initProps);
    Object o = initProps.get(CONVERT_TYPE);
    if (o != null) convertType = Boolean.parseBoolean(o.toString());

    factory = createConnectionFactory(context, initProps);

    String bsz = initProps.getProperty("batchSize");
    if (bsz != null) {
      bsz = context.replaceTokens(bsz);
      try {
        batchSize = Integer.parseInt(bsz);
        if (batchSize == -1) batchSize = Integer.MIN_VALUE;
      } catch (NumberFormatException e) {
        LOG.warn("Invalid batch size: " + bsz);
      }
    }

    for (Map<String, String> map : context.getAllEntityFields()) {
      String n = map.get(DataImporter.COLUMN);
      String t = map.get(DataImporter.TYPE);
      if ("sint".equals(t) || "integer".equals(t)) fieldNameVsType.put(n, Types.INTEGER);
      else if ("slong".equals(t) || "long".equals(t)) fieldNameVsType.put(n, Types.BIGINT);
      else if ("float".equals(t) || "sfloat".equals(t)) fieldNameVsType.put(n, Types.FLOAT);
      else if ("double".equals(t) || "sdouble".equals(t)) fieldNameVsType.put(n, Types.DOUBLE);
      else if ("date".equals(t)) fieldNameVsType.put(n, Types.DATE);
      else if ("boolean".equals(t)) fieldNameVsType.put(n, Types.BOOLEAN);
      else if ("binary".equals(t)) fieldNameVsType.put(n, Types.BLOB);
      else fieldNameVsType.put(n, Types.VARCHAR);
    }
  }
示例#14
0
  public static JaggeryContext clonedJaggeryContext(ServletContext context) {
    JaggeryContext shared = sharedJaggeryContext(context);
    RhinoEngine engine = shared.getEngine();
    Scriptable sharedScope = shared.getScope();
    Context cx = Context.getCurrentContext();
    ScriptableObject instanceScope = (ScriptableObject) cx.newObject(sharedScope);
    instanceScope.setPrototype(sharedScope);
    instanceScope.setParentScope(null);

    JaggeryContext clone = new JaggeryContext();
    clone.setEngine(engine);
    clone.setTenantId(shared.getTenantId());
    clone.setScope(instanceScope);

    clone.addProperty(Constants.SERVLET_CONTEXT, shared.getProperty(Constants.SERVLET_CONTEXT));
    clone.addProperty(LogHostObject.LOG_LEVEL, shared.getProperty(LogHostObject.LOG_LEVEL));
    clone.addProperty(
        FileHostObject.JAVASCRIPT_FILE_MANAGER,
        shared.getProperty(FileHostObject.JAVASCRIPT_FILE_MANAGER));
    clone.addProperty(
        Constants.JAGGERY_CORE_MANAGER, shared.getProperty(Constants.JAGGERY_CORE_MANAGER));
    clone.addProperty(Constants.JAGGERY_INCLUDED_SCRIPTS, new HashMap<String, Boolean>());
    clone.addProperty(Constants.JAGGERY_INCLUDES_CALLSTACK, new Stack<String>());
    clone.addProperty(Constants.JAGGERY_REQUIRED_MODULES, new HashMap<String, ScriptableObject>());

    CommonManager.setJaggeryContext(clone);

    return clone;
  }
 @NotNull
 private static List<PyGenericType> collectGenericTypes(
     @NotNull PyClass cls, @NotNull Context context) {
   boolean isGeneric = false;
   for (PyClass ancestor : cls.getAncestorClasses(context.getTypeContext())) {
     if (GENERIC_CLASSES.contains(ancestor.getQualifiedName())) {
       isGeneric = true;
       break;
     }
   }
   if (isGeneric) {
     final ArrayList<PyGenericType> results = new ArrayList<>();
     // XXX: Requires switching from stub to AST
     for (PyExpression expr : cls.getSuperClassExpressions()) {
       if (expr instanceof PySubscriptionExpression) {
         final PyExpression indexExpr = ((PySubscriptionExpression) expr).getIndexExpression();
         if (indexExpr != null) {
           for (PsiElement resolved : tryResolving(indexExpr, context.getTypeContext())) {
             final PyGenericType genericType = getGenericType(resolved, context);
             if (genericType != null) {
               results.add(genericType);
             }
           }
         }
       }
     }
     return results;
   }
   return Collections.emptyList();
 }
  @Override
  protected void setup(Context context) throws IOException, InterruptedException {
    super.setup(context);
    setupGCBins(context.getConfiguration());

    genomeAdmin = HBaseGenomeAdmin.getHBaseGenomeAdmin(context.getConfiguration());
    variationAdmin = VariationAdmin.getInstance(context.getConfiguration());

    genomeName = context.getConfiguration().get("genome");
    parentGenome = context.getConfiguration().get("parent");
    genome = genomeAdmin.getGenomeTable().getGenome(genomeName);
    if (genome == null) throw new IOException("Genome " + genome + " is missing.");

    try {
      SNVProbability table =
          (SNVProbability) variationAdmin.getTable(VariationTables.SNVP.getTableName());
      snvProbabilities = table.getProbabilities();

      SizeProbability sizeTable =
          (SizeProbability) variationAdmin.getTable(VariationTables.SIZE.getTableName());
      sizeProbabilities = sizeTable.getProbabilities();
      variationList = sizeTable.getVariationList();
      variationList.add("SNV");
    } catch (ProbabilityException e) {
      throw new InterruptedException("Failed to start mapper: " + e);
    }

    varTable = (VariationCountPerBin) variationAdmin.getTable(VariationTables.VPB.getTableName());
  }
  /**
   * Establishes a connection to a registry.
   *
   * @param queryUrl the URL of the query registry
   * @param publishUrl the URL of the publish registry
   */
  public void makeConnection(String queryUrl, String publishUrl) {

    Context context = null;
    ConnectionFactory factory = null;

    /*
     * Define connection configuration properties.
     * To publish, you need both the query URL and the
     * publish URL.
     */
    Properties props = new Properties();
    props.setProperty("javax.xml.registry.queryManagerURL", queryUrl);
    props.setProperty("javax.xml.registry.lifeCycleManagerURL", publishUrl);

    try {
      // Create the connection, passing it the
      // configuration properties
      context = new InitialContext();
      factory = (ConnectionFactory) context.lookup("java:comp/env/eis/JAXR");
      factory.setProperties(props);
      connection = factory.createConnection();
      System.out.println("Created connection to registry");
    } catch (Exception e) {
      e.printStackTrace();
      if (connection != null) {
        try {
          connection.close();
        } catch (JAXRException je) {
        }
      }
    }
  }
示例#18
0
  @Start
  public void start() {
    Log.debug("Start WSChan");
    clients = new HashMap<>();
    if (path == null) {
      path = "";
    }

    ContainerRoot model = modelService.getPendingModel();
    if (model == null) {
      model = modelService.getCurrentModel().getModel();
    }
    Channel thisChan = (Channel) model.findByPath(context.getPath());
    Set<String> inputPaths = Helper.getProvidedPortsPath(thisChan, context.getNodeName());
    Set<String> outputPaths = Helper.getRequiredPortsPath(thisChan, context.getNodeName());

    for (String path : inputPaths) {
      // create input WSMsgBroker clients
      createInputClient(path + "_" + context.getInstanceName());
    }

    for (String path : outputPaths) {
      // create output WSMsgBroker clients
      createOutputClient(path + "_" + context.getInstanceName());
    }
  }
示例#19
0
 public static File GetDefaultStorageFolder(Context context) {
   File storageFolder = context.getExternalFilesDir(null);
   if (storageFolder == null) {
     storageFolder = context.getFilesDir();
   }
   return storageFolder;
 }
  public MetaData getMetaData(int index) {
    if (indexMap == null || indexMap.length < index + 1) {
      int startFrom = 0;
      int lastIndex = index;

      if (indexMap != null) {
        startFrom = indexMap.length;
        indexMap = Arrays.copyOf(indexMap, index + 1);
      } else {
        String[] headers = context.headers();
        if (headers != null && lastIndex < headers.length) {
          lastIndex = headers.length;
        }

        int[] indexes = context.extractedFieldIndexes();
        if (indexes != null) {
          for (int i = 0; i < indexes.length; i++) {
            if (lastIndex < indexes[i]) {
              lastIndex = indexes[i];
            }
          }
        }

        indexMap = new MetaData[lastIndex + 1];
      }

      for (int i = startFrom; i < lastIndex + 1; i++) {
        indexMap[i] = new MetaData(i);
      }
    }
    return indexMap[index];
  }
示例#21
0
  private boolean funcLocMixVeloOk(Context ctx1, Context ctx2) { // boolean function 4

    String v1 = (String) ctx1.get(Context.FLD_OBJECT);
    String v2 = (String) ctx1.get(Context.FLD_TIMESTAMP);
    String v3 = (String) ctx2.get(Context.FLD_OBJECT);
    String v4 = (String) ctx2.get(Context.FLD_TIMESTAMP);
    if (v1 == null || v2 == null || v3 == null || v4 == null) {
      return false;
    }

    StringTokenizer st = new StringTokenizer(v1);
    double x1 = Double.parseDouble(st.nextToken());
    double y1 = Double.parseDouble(st.nextToken());
    st = new StringTokenizer(v3);
    double x2 = Double.parseDouble(st.nextToken());
    double y2 = Double.parseDouble(st.nextToken());
    double dist = Coordinates.calDist(x1, y1, x2, y2);
    long t = TimeFormat.convert(v4) - TimeFormat.convert(v2) - STAY_TIME; // Different here

    // The velocity should be between vmin and vmax
    boolean result = false;
    double vmin = (VELOCITY * ((double) t / 1000) - 2 * ERR) / ((double) t / 1000);
    double vmax = (VELOCITY * ((double) t / 1000) + 2 * ERR) / ((double) t / 1000);
    double ve = dist / ((double) t / 1000);
    if (ve >= vmin && ve <= vmax) {
      result = true;
    }

    return result;
  }
示例#22
0
 Class<?> getPluginClass(String packageName, String className)
     throws NameNotFoundException, ClassNotFoundException {
   Context pluginContext =
       this.mAppContext.createPackageContext(
           packageName, Context.CONTEXT_INCLUDE_CODE | Context.CONTEXT_IGNORE_SECURITY);
   ClassLoader pluginCL = pluginContext.getClassLoader();
   return pluginCL.loadClass(className);
 }
 private MetaData getMetaData(Enum<?> column) {
   String[] headers = context.headers();
   if (headers == null || headers.length == 0) {
     throw new IllegalStateException(
         "No headers parsed from input nor provided in the user settings. Only index-based operations are available.");
   }
   return getMetaData(context.indexOf(column));
 }
示例#24
0
 public static void main(final String[] args) {
   final Context context = new Context();
   final List<CompileParameter> parameters = initializeParameters(context, ".");
   final int returnCode =
       parse(args, context, parameters) ? (processContext(context, parameters) ? 0 : 1) : 2;
   context.close();
   System.exit(returnCode);
 }
示例#25
0
 private void initContext() {
   context.put(JavacTaskImpl.class, this);
   if (context.get(TaskListener.class) != null)
     context.put(TaskListener.class, (TaskListener) null);
   if (taskListener != null) context.put(TaskListener.class, ccw.wrap(taskListener));
   // initialize compiler's default locale
   context.put(Locale.class, locale);
 }
 /**
  * If the where clause is present the cache is sql Vs Map of key Vs List of Rows. Only used by
  * cache implementations.
  *
  * @param query the query string for which cached data is to be returned
  * @return the cached row corresponding to the given query after all variables have been resolved
  */
 protected Map<String, Object> getIdCacheData(String query) {
   Map<Object, List<Map<String, Object>>> rowIdVsRows = cacheWithWhereClause.get(query);
   List<Map<String, Object>> rows = null;
   Object key = context.resolve(cacheVariableName);
   if (key == null) {
     throw new DataImportHandlerException(
         DataImportHandlerException.WARN,
         "The cache lookup value : "
             + cacheVariableName
             + " is resolved to be null in the entity :"
             + context.getEntityAttribute("name"));
   }
   if (rowIdVsRows != null) {
     rows = rowIdVsRows.get(key);
     if (rows == null) return null;
     dataSourceRowCache = new ArrayList<Map<String, Object>>(rows);
     return getFromRowCacheTransformed();
   } else {
     rows = getAllNonCachedRows();
     if (rows.isEmpty()) {
       return null;
     } else {
       rowIdVsRows = new HashMap<Object, List<Map<String, Object>>>();
       for (Map<String, Object> row : rows) {
         Object k = row.get(cachePk);
         if (k == null) {
           throw new DataImportHandlerException(
               DataImportHandlerException.WARN,
               "No value available for the cache key : "
                   + cachePk
                   + " in the entity : "
                   + context.getEntityAttribute("name"));
         }
         if (!k.getClass().equals(key.getClass())) {
           throw new DataImportHandlerException(
               DataImportHandlerException.WARN,
               "The key in the cache type : "
                   + k.getClass().getName()
                   + "is not same as the lookup value type "
                   + key.getClass().getName()
                   + " in the entity "
                   + context.getEntityAttribute("name"));
         }
         if (rowIdVsRows.get(k) == null) rowIdVsRows.put(k, new ArrayList<Map<String, Object>>());
         rowIdVsRows.get(k).add(row);
       }
       cacheWithWhereClause.put(query, rowIdVsRows);
       if (!rowIdVsRows.containsKey(key)) return null;
       dataSourceRowCache = new ArrayList<Map<String, Object>>(rowIdVsRows.get(key));
       if (dataSourceRowCache.isEmpty()) {
         dataSourceRowCache = null;
         return null;
       }
       return getFromRowCacheTransformed();
     }
   }
 }
示例#27
0
 /*
  * Setup gets called exactly once for each mapper, before map() gets called the first time.
  * It's a good place to do configuration or setup that can be shared across many calls to map
  */
 @Override
 public void setup(Context context) {
   targetGram = context.getConfiguration().get("targetWord").toLowerCase();
   try {
     funcNum = Integer.parseInt(context.getConfiguration().get("funcNum"));
   } catch (NumberFormatException e) {
     /* Do nothing. */
   }
 }
示例#28
0
 private VerticleHolder getVerticleHolder() {
   Context context = vertx.getContext();
   if (context != null) {
     VerticleHolder holder = (VerticleHolder) context.getDeploymentHandle();
     return holder;
   } else {
     return null;
   }
 }
示例#29
0
  /** Load a object of type 'clazz' from a file. */
  public <T> T load(Class<T> clazz, InputStream is) throws JAXBException {
    Context context;
    T object;

    context = getContext(clazz);
    synchronized (context) {
      object = (T) context.unmarshal(is);
      return object;
    }
  }
示例#30
0
  /**
   * Build the top level menu
   *
   * @param context
   */
  private void buildMenu(Context context) {
    // build the menu
    Menu bar = new MenuImpl();
    bar.add(new MenuEntry(rb.getString("archive.button.single"), "doView_single"));
    bar.add(new MenuEntry(rb.getString("archive.button.batch"), "doView_batch"));
    bar.add(new MenuEntry(rb.getString("archive.button.download"), "doView_download"));

    context.put(Menu.CONTEXT_MENU, bar);
    context.put(Menu.CONTEXT_ACTION, "ArchiveAction");
  }