com.orientechnologies.orient.core.command.OCommandContext Java Examples

The following examples show how to use com.orientechnologies.orient.core.command.OCommandContext. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: OLuceneWithinOperator.java    From orientdb-lucene with Apache License 2.0 6 votes vote down vote up
@Override
public OIndexCursor executeIndexQuery(OCommandContext iContext, OIndex<?> index, List<Object> keyParams, boolean ascSortOrder) {
  OIndexDefinition definition = index.getDefinition();
  int idxSize = definition.getFields().size();
  int paramsSize = keyParams.size();
  OIndexCursor cursor;
  Object indexResult = index.get(new OSpatialCompositeKey(keyParams).setOperation(SpatialOperation.IsWithin));
  if (indexResult == null || indexResult instanceof OIdentifiable)
    cursor = new OIndexCursorSingleValue((OIdentifiable) indexResult, new OSpatialCompositeKey(keyParams));
  else
    cursor = new OIndexCursorCollectionValue(((Collection<OIdentifiable>) indexResult).iterator(), new OSpatialCompositeKey(
        keyParams));

  iContext.setVariable("$luceneIndex", true);
  return cursor;
}
 
Example #2
Source File: OLuceneSpatialIndexManager.java    From orientdb-lucene with Apache License 2.0 6 votes vote down vote up
public Object searchIntersect(OCompositeKey key, double distance, OCommandContext context) throws IOException {

    double lat = ((Double) OType.convert(((OCompositeKey) key).getKeys().get(0), Double.class)).doubleValue();
    double lng = ((Double) OType.convert(((OCompositeKey) key).getKeys().get(1), Double.class)).doubleValue();
    SpatialOperation operation = SpatialOperation.Intersects;

    Point p = ctx.makePoint(lng, lat);
    SpatialArgs args = new SpatialArgs(operation, ctx.makeCircle(lng, lat,
        DistanceUtils.dist2Degrees(distance, DistanceUtils.EARTH_MEAN_RADIUS_KM)));
    Filter filter = strategy.makeFilter(args);
    IndexSearcher searcher = getSearcher();
    ValueSource valueSource = strategy.makeDistanceValueSource(p);
    Sort distSort = new Sort(valueSource.getSortField(false)).rewrite(searcher);

    return new LuceneResultSet(this,
        new SpatialQueryContext(context, searcher, new MatchAllDocsQuery(), filter, distSort).setSpatialArgs(args));
  }
 
Example #3
Source File: OLuceneIndexManagerAbstract.java    From orientdb-lucene with Apache License 2.0 6 votes vote down vote up
public void sendLookupTime(OCommandContext context, final TopDocs docs, final Integer limit, long startFetching) {
  if (context != null) {

    final long finalTime = System.currentTimeMillis() - startFetching;
    context.setVariable((indexName + ".lookupTime").replace(".", "_"), new HashMap<String, Object>() {
      {
        put("limit", limit);
        put("totalTime", finalTime);
        put("totalHits", docs.totalHits);
        put("returnedHits", docs.scoreDocs.length);
        put("maxScore", docs.getMaxScore());

      }
    });
  }
}
 
Example #4
Source File: OLuceneNearFunction.java    From orientdb-lucene with Apache License 2.0 6 votes vote down vote up
@Override
public Object execute(Object iThis, OIdentifiable iCurrentRecord, Object iCurrentResult, Object[] iParams,
    OCommandContext iContext) {

  String clazz = (String) iParams[0];
  String latField = (String) iParams[1];
  String lngField = (String) iParams[2];
  ODatabaseDocument databaseRecord = ODatabaseRecordThreadLocal.INSTANCE.get();
  Set<OIndex<?>> indexes = databaseRecord.getMetadata().getSchema().getClass(clazz).getInvolvedIndexes(latField, lngField);
  for (OIndex i : indexes) {
    if (OClass.INDEX_TYPE.SPATIAL.toString().equals(i.getInternal().getType())) {
      List<Object> params = new ArrayList<Object>();
      params.add(iParams[3]);
      params.add(iParams[4]);
      double distance = iParams.length > 5 ? ((Number) iParams[5]).doubleValue() : 0;
      Object ret = i.get(new OSpatialCompositeKey(params).setMaxDistance(distance));
      if (ret instanceof Collection) {
        if (context == null)
          context = new HashSet<Object>();
        context.addAll((Collection<?>) ret);
      }
      return ret;
    }
  }
  return null;
}
 
Example #5
Source File: OEdgeTransformer.java    From orientdb-etl with Apache License 2.0 6 votes vote down vote up
@Override
public void configure(OETLProcessor iProcessor, final ODocument iConfiguration, final OCommandContext iContext) {
  super.configure(iProcessor, iConfiguration, iContext);
  edgeClass = iConfiguration.field("class");
  if (iConfiguration.containsField("direction")) {
    final String direction = iConfiguration.field("direction");
    if ("out".equalsIgnoreCase(direction))
      directionOut = true;
    else if ("in".equalsIgnoreCase(direction))
      directionOut = false;
    else
      throw new OConfigurationException("Direction can be 'in' or 'out', but found: " + direction);
  }

  if (iConfiguration.containsField("targetVertexFields"))
    targetVertexFields = (ODocument) iConfiguration.field("targetVertexFields");
  if (iConfiguration.containsField("edgeFields"))
    edgeFields = (ODocument) iConfiguration.field("edgeFields");
  if (iConfiguration.containsField("skipDuplicates"))
    skipDuplicates = (Boolean) resolve(iConfiguration.field("skipDuplicates"));
}
 
Example #6
Source File: OScriptImporterListener.java    From orientdb-etl with Apache License 2.0 6 votes vote down vote up
private Object executeEvent(final ODatabaseDocumentTx db, final String iEventName, final OCommandContext iContext) {
  if (events == null)
    return null;

  OCommandScript script = scripts.get(iEventName);

  if (script == null) {
    final String code = events.get(iEventName);
    if (code != null) {
      // CACHE IT
      script = new OCommandScript(code).setLanguage("Javascript");
      scripts.put(iEventName, script);
    }
  }

  if (script != null) {
    final Map<String, Object> pars = new HashMap<String, Object>();
    pars.put("task", iContext);
    pars.put("importer", this);

    return db.command(script).execute(pars);
  }
  return null;
}
 
Example #7
Source File: Lower.java    From nexus-public with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public Object execute(final Object iThis,
                      final OIdentifiable iCurrentRecord,
                      final Object iCurrentResult,
                      final Object[] iParams,
                      final OCommandContext iContext)
{
  checkArgument(iParams.length == 1);

  final Object param = iParams[0];

  if (param == null) {
    return null;
  }

  checkArgument(param instanceof String, "lower() parameter must be a string");

  return ((String) param).toLowerCase(Locale.ENGLISH);
}
 
Example #8
Source File: ContentAuth.java    From nexus-public with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public Object execute(final Object iThis,
                      final OIdentifiable iCurrentRecord,
                      final Object iCurrentResult,
                      final Object[] iParams,
                      final OCommandContext iContext)
{
  String path = (String) iParams[0];
  String format = (String) iParams[1];
  String browsedRepositoryName = (String) iParams[2];
  boolean jexlOnly = iParams.length > 3 && (boolean) iParams[3];

  if (jexlOnly) {
    return contentAuthHelper.checkPathPermissionsJexlOnly(path, format, browsedRepositoryName);
  }

  return contentAuthHelper.checkPathPermissions(path, format, browsedRepositoryName);
}
 
Example #9
Source File: OAbstractETLComponent.java    From orientdb-etl with Apache License 2.0 5 votes vote down vote up
@Override
public void configure(final OETLProcessor iProcessor, final ODocument iConfiguration, final OCommandContext iContext) {
  processor = iProcessor;
  context = iContext;

  ifExpression = iConfiguration.field("if");

  if (iConfiguration.containsField("log"))
    logLevel = OETLProcessor.LOG_LEVELS.valueOf(iConfiguration.field("log").toString().toUpperCase());
  else
    logLevel = iProcessor.getLogLevel();

  if (iConfiguration.containsField("output"))
    output = (String) iConfiguration.field("output");
}
 
Example #10
Source File: OrienteerETLProcessor.java    From Orienteer with Apache License 2.0 5 votes vote down vote up
public static OrienteerETLProcessor parseConfigRecord(OETLTaskSession taskSession,String config){
    final OCommandContext context = createDefaultContext();
    ODocument configuration = new ODocument().fromJSON("{}");
    
       configuration.merge(new ODocument().fromJSON(config, "noMap"), true, true);
       // configuration = ;
       ODocument cfgGlobal = configuration.field("config");
       if (cfgGlobal != null) {
         for (String f : cfgGlobal.fieldNames()) {
           context.setVariable(f, cfgGlobal.field(f));
         }
       }		
	return (OrienteerETLProcessor) new OrienteerETLProcessor(taskSession).parse(configuration, context);
}
 
Example #11
Source File: OVertexTransformer.java    From orientdb-etl with Apache License 2.0 5 votes vote down vote up
@Override
public void configure(final OETLProcessor iProcessor, final ODocument iConfiguration, final OCommandContext iContext) {
  super.configure(iProcessor, iConfiguration, iContext);
  if (iConfiguration.containsField("class"))
    vertexClass = (String) resolve(iConfiguration.field("class"));
  if (iConfiguration.containsField("skipDuplicates"))
    skipDuplicates = (Boolean) resolve(iConfiguration.field("skipDuplicates"));
}
 
Example #12
Source File: RandomExtractor.java    From orientdb-etl with Apache License 2.0 5 votes vote down vote up
@Override
public void configure(OETLProcessor iProcessor, ODocument iConfiguration, OCommandContext iContext) {
  super.configure(iProcessor, iConfiguration, iContext);

  if (iConfiguration.containsField("items"))
    items = ((Number) iConfiguration.field("items")).longValue();
  if (iConfiguration.containsField("fields"))
    fields = iConfiguration.field("fields");
  if (iConfiguration.containsField("delay"))
    delay = iConfiguration.field("delay");
}
 
Example #13
Source File: OLuceneFullTextIndexManager.java    From orientdb-lucene with Apache License 2.0 5 votes vote down vote up
@Override
public Object get(Object key) {
  Query q = null;
  try {
    q = OLuceneIndexType.createFullQuery(index, key, mgrWriter.getIndexWriter().getAnalyzer(), getLuceneVersion(metadata));
    OCommandContext context = null;
    if (key instanceof OFullTextCompositeKey) {
      context = ((OFullTextCompositeKey) key).getContext();
    }
    return getResults(q, context, key);
  } catch (ParseException e) {
    throw new OIndexEngineException("Error parsing lucene query ", e);
  }
}
 
Example #14
Source File: OLuceneIndexManagerAbstract.java    From orientdb-lucene with Apache License 2.0 5 votes vote down vote up
public void sendTotalHits(OCommandContext context, TopDocs docs) {
  if (context != null) {

    if (context.getVariable("totalHits") == null) {
      context.setVariable("totalHits", docs.totalHits);
    } else {
      context.setVariable("totalHits", null);
    }
    context.setVariable((indexName + ".totalHits").replace(".", "_"), docs.totalHits);
  }
}
 
Example #15
Source File: OScriptImporterListener.java    From orientdb-etl with Apache License 2.0 5 votes vote down vote up
@Override
public boolean onBeforeLine(final ODatabaseDocumentTx db, final OCommandContext iContext) {
  final Object ret = executeEvent(db, "onBeforeLine", iContext);
  if (ret != null && ret instanceof Boolean)
    return (Boolean) ret;
  return true;
}
 
Example #16
Source File: OLuceneNearOperator.java    From orientdb-lucene with Apache License 2.0 5 votes vote down vote up
@Override
public Object evaluateRecord(OIdentifiable iRecord, ODocument iCurrentResult, OSQLFilterCondition iCondition, Object iLeft,
    Object iRight, OCommandContext iContext) {

  List<Number> left = (List<Number>) iLeft;

  double lat = left.get(0).doubleValue();
  double lon = left.get(1).doubleValue();

  Shape shape = SpatialContext.GEO.makePoint(lon, lat);
  List<Number> right = (List<Number>) iRight;

  double lat1 =  right.get(0).doubleValue();
  double lon1 =  right.get(1).doubleValue();
  Shape shape1 = SpatialContext.GEO.makePoint(lon1, lat1);

  Map map = (Map) right.get(2);
  double distance = 0;

  Number n = (Number) map.get("maxDistance");
  if (n != null) {
    distance = n.doubleValue();
  }
  Point p = (Point) shape1;
  Circle circle = SpatialContext.GEO.makeCircle(p.getX(), p.getY(),
      DistanceUtils.dist2Degrees(distance, DistanceUtils.EARTH_MEAN_RADIUS_KM));
  double docDistDEG = SpatialContext.GEO.getDistCalc().distance((Point) shape, p);
  final double docDistInKM = DistanceUtils.degrees2Dist(docDistDEG, DistanceUtils.EARTH_EQUATORIAL_RADIUS_KM);
  iContext.setVariable("distance", docDistInKM);
  return shape.relate(circle) == SpatialRelation.WITHIN;
}
 
Example #17
Source File: OLuceneTextOperator.java    From orientdb-lucene with Apache License 2.0 5 votes vote down vote up
@Override
public OIndexCursor executeIndexQuery(OCommandContext iContext, OIndex<?> index, List<Object> keyParams, boolean ascSortOrder) {
  OIndexCursor cursor;
  Object indexResult = index.get(new OFullTextCompositeKey(keyParams).setContext(iContext));
  if (indexResult == null || indexResult instanceof OIdentifiable)
    cursor = new OIndexCursorSingleValue((OIdentifiable) indexResult, new OFullTextCompositeKey(keyParams));
  else
    cursor = new OIndexCursorCollectionValue(((Collection<OIdentifiable>) indexResult).iterator(), new OFullTextCompositeKey(
        keyParams));
  iContext.setVariable("$luceneIndex", true);
  return cursor;
}
 
Example #18
Source File: Concat.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public Object execute(final Object iThis,
                      final OIdentifiable iCurrentRecord,
                      final Object iCurrentResult,
                      final Object[] iParams,
                      final OCommandContext iContext)
{
  StringBuilder b = new StringBuilder();

  for (Object param : iParams) {
    b.append(param);
  }

  return b.toString();
}
 
Example #19
Source File: OLetBlock.java    From orientdb-etl with Apache License 2.0 5 votes vote down vote up
@Override
public void configure(OETLProcessor iProcessor, final ODocument iConfiguration, final OCommandContext iContext) {
  super.configure(iProcessor, iConfiguration, iContext);

  name = iConfiguration.field("name");
  if (iConfiguration.containsField("value")) {
    value = iConfiguration.field("value");
  } else
    expression = new OSQLFilter((String) iConfiguration.field("expression"), iContext, null);

  if (value == null && expression == null)
    throw new IllegalArgumentException("'value' or 'expression' parameter are mandatory in Let Transformer");
}
 
Example #20
Source File: OAbstractLookupTransformer.java    From orientdb-etl with Apache License 2.0 5 votes vote down vote up
@Override
public void configure(final OETLProcessor iProcessor, final ODocument iConfiguration, OCommandContext iContext) {
  super.configure(iProcessor, iConfiguration, iContext);

  joinFieldName = iConfiguration.field("joinFieldName");

  if (iConfiguration.containsField("joinValue"))
    joinValue = iConfiguration.field("joinValue");

  if (iConfiguration.containsField("lookup"))
    lookup = iConfiguration.field("lookup");

  if (iConfiguration.containsField("unresolvedLinkAction"))
    unresolvedLinkAction = ACTION.valueOf(iConfiguration.field("unresolvedLinkAction").toString().toUpperCase());
}
 
Example #21
Source File: OCodeBlock.java    From orientdb-etl with Apache License 2.0 5 votes vote down vote up
@Override
public void configure(OETLProcessor iProcessor, final ODocument iConfiguration, OCommandContext iContext) {
  super.configure(iProcessor, iConfiguration, iContext);
  if (iConfiguration.containsField("language"))
    language = iConfiguration.field("language");

  if (iConfiguration.containsField("code"))
    code = iConfiguration.field("code");
  else
    throw new IllegalArgumentException("'code' parameter is mandatory in Code Transformer");

  cmd = new OCommandExecutorScript().parse(new OCommandScript(language, code));
}
 
Example #22
Source File: OCodeTransformer.java    From orientdb-etl with Apache License 2.0 5 votes vote down vote up
@Override
public void configure(OETLProcessor iProcessor, final ODocument iConfiguration, OCommandContext iContext) {
  super.configure(iProcessor, iConfiguration, iContext);
  if (iConfiguration.containsField("language"))
    language = iConfiguration.field("language");

  String code;
  if (iConfiguration.containsField("code"))
    code = iConfiguration.field("code");
  else
    throw new IllegalArgumentException("'code' parameter is mandatory in Code Transformer");

  cmd = new OCommandExecutorScript().parse(new OCommandScript(language, code));
}
 
Example #23
Source File: OBlockTransformer.java    From orientdb-etl with Apache License 2.0 5 votes vote down vote up
@Override
public void configure(OETLProcessor iProcessor, final ODocument iConfiguration, OCommandContext iContext) {
  super.configure(iProcessor, iConfiguration, iContext);
  final String[] fieldNames = iConfiguration.fieldNames();

  try {
    block = processor.getFactory().getBlock(fieldNames[0]);
    block.configure(processor, (ODocument) iConfiguration.field(fieldNames[0]), context);
  } catch (Exception e) {
    throw new OConfigurationException("[Block transformer] Error on configuring inner block", e);
  }
}
 
Example #24
Source File: OContentSource.java    From orientdb-etl with Apache License 2.0 5 votes vote down vote up
@Override
public void configure(OETLProcessor iProcessor, ODocument iConfiguration, OCommandContext iContext) {
  final Object value = iConfiguration.field("value");
  if (value != null) {
    String stringContent;
    if (value instanceof ODocument)
      stringContent = ((ODocument) value).toJSON(null);
    else if (OMultiValue.isMultiValue(value)) {
      stringContent = "[";
      int i = 0;
      for (Object o : OMultiValue.getMultiValueIterable(value)) {
        if (o != null) {
          if (i > 0)
            stringContent += ",";

          if (o instanceof ODocument)
            stringContent += ((ODocument) o).toJSON(null);
          else
            stringContent += o.toString();
          ++i;
        }
      }
      stringContent += "]";
    } else
      stringContent = value.toString();

    this.reader = new BufferedReader(new StringReader(stringContent));
  } else
    throw new IllegalArgumentException(getName() + " Source has no 'value' set");
}
 
Example #25
Source File: OHttpSource.java    From orientdb-etl with Apache License 2.0 5 votes vote down vote up
@Override
public void configure(OETLProcessor iProcessor, ODocument iConfiguration, OCommandContext iContext) {
  super.configure(iProcessor, iConfiguration, iContext);
  url = iConfiguration.field("url");
  if (url == null || url.isEmpty())
    throw new OConfigurationException("HTTP Source missing URL");
  if (iConfiguration.containsField("method"))
    method = iConfiguration.field("method");

  if (iConfiguration.containsField("headers"))
    headers = iConfiguration.field("headers");
}
 
Example #26
Source File: OLinkTransformer.java    From orientdb-etl with Apache License 2.0 5 votes vote down vote up
@Override
public void configure(OETLProcessor iProcessor, final ODocument iConfiguration, OCommandContext iContext) {
  super.configure(iProcessor, iConfiguration, iContext);

  joinValue = iConfiguration.field("joinValue");
  linkFieldName = iConfiguration.field("linkFieldName");
  if (iConfiguration.containsField("linkFieldType"))
    linkFieldType = OType.valueOf((String) iConfiguration.field("linkFieldType"));
}
 
Example #27
Source File: OFlowTransformer.java    From orientdb-etl with Apache License 2.0 5 votes vote down vote up
@Override
public void configure(OETLProcessor iProcessor, final ODocument iConfiguration, OCommandContext iContext) {
  super.configure(iProcessor, iConfiguration, iContext);
  operation = iConfiguration.field("operation");
  if (operation == null)
    throw new OConfigurationException("Flow transformer has not mandatory 'operation' field");
  if (!operation.equalsIgnoreCase("halt") && !operation.equalsIgnoreCase("skip"))
    throw new OConfigurationException("Flow transformer has invalid 'operation' field='" + operation
        + "', while supported are: 'skip' and 'halt'");
}
 
Example #28
Source File: OCSVTransformer.java    From orientdb-etl with Apache License 2.0 5 votes vote down vote up
@Override
public void configure(final OETLProcessor iProcessor, final ODocument iConfiguration, final OCommandContext iContext) {
  super.configure(iProcessor, iConfiguration, iContext);

  if (iConfiguration.containsField("separator"))
    separator = iConfiguration.field("separator").toString().charAt(0);
  if (iConfiguration.containsField("columnsOnFirstLine"))
    columnsOnFirstLine = (Boolean) iConfiguration.field("columnsOnFirstLine");
  if (iConfiguration.containsField("columns")) {
    final List<String> columns = iConfiguration.field("columns");
    columnNames = new ArrayList<String>(columns.size());
    columnTypes = new ArrayList<OType>(columns.size());
    for (String c : columns) {
      final String[] parts = c.split(":");

      columnNames.add(parts[0]);
      if (parts.length > 1)
        columnTypes.add(OType.valueOf(parts[1].toUpperCase()));
      else
        columnTypes.add(OType.ANY);
    }
  }
  if (iConfiguration.containsField("skipFrom"))
    skipFrom = ((Number) iConfiguration.field("skipFrom")).longValue();
  if (iConfiguration.containsField("skipTo"))
    skipTo = ((Number) iConfiguration.field("skipTo")).longValue();
  if (iConfiguration.containsField("nullValue"))
    nullValue = iConfiguration.field("nullValue");
  if (iConfiguration.containsField("unicode"))
    unicode = iConfiguration.field("unicode");
  if (iConfiguration.containsField("stringCharacter")) {
    final String value = iConfiguration.field("stringCharacter").toString();
    if (value.isEmpty())
      stringCharacter = null;
    else
      stringCharacter = value.charAt(0);
  }
}
 
Example #29
Source File: OLogTransformer.java    From orientdb-etl with Apache License 2.0 5 votes vote down vote up
@Override
public void configure(OETLProcessor iProcessor, final ODocument iConfiguration, OCommandContext iContext) {
  super.configure(iProcessor, iConfiguration, iContext);
  if (iConfiguration.containsField("prefix"))
    prefix = iConfiguration.field("prefix");
  if (iConfiguration.containsField("postfix"))
    postfix = iConfiguration.field("postfix");
}
 
Example #30
Source File: OLuceneFullTextIndexManager.java    From orientdb-lucene with Apache License 2.0 5 votes vote down vote up
private Set<OIdentifiable> getResults(Query query, OCommandContext context, Object key) {

    try {
      IndexSearcher searcher = getSearcher();
      QueryContext queryContext = new QueryContext(context, searcher, query);
      if (facetManager.supportsFacets()) {
        facetManager.addFacetContext(queryContext, key);
      }
      return new LuceneResultSet(this, queryContext);
    } catch (IOException e) {
      throw new OIndexException("Error reading from Lucene index", e);
    }

  }