Ejemplo n.º 1
0
  /**
   * Returns a list of scores that denotes how related a source concept is to a list of individual
   * concepts.
   *
   * @param parameters The parameters to be used in the service call, account_id, graph and concept
   *     or concepts are required.
   *     <ul>
   *       <li>String account_id - The account identifier.<br>
   *       <li>String graph - The graph name.<br>
   *       <li>String concept - The concept name.<br>
   *       <li>List&lt;String&gt; concepts - Array of concept IDs, each identifying a concept.<br>
   *     </ul>
   *
   * @return {@link Scores}
   */
  public Scores getGraphsRelationScores(Map<String, Object> parameters) {
    Validate.notNull(parameters.get(ACCOUNT_ID), "account_id can't be null");
    Validate.notNull(parameters.get(GRAPH), "graph can't be null");
    Validate.notNull(parameters.get(CONCEPT), "concept can't be null");
    Validate.notNull(parameters.get(CONCEPTS), "concepts can't be null");

    String conceptId =
        createConceptIdPath(
            (String) parameters.get(ACCOUNT_ID),
            (String) parameters.get(GRAPH),
            (String) parameters.get(CONCEPT));

    Map<String, Object> queryParameters = new HashMap<String, Object>();
    JsonObject contentJson = new JsonObject();
    JsonArray conceptsJson = new JsonArray();
    @SuppressWarnings("unchecked")
    List<String> concepts = (List<String>) parameters.get(CONCEPTS);
    for (String value : concepts) {
      conceptsJson.add(new JsonPrimitive(value));
    }
    contentJson.add(CONCEPTS, conceptsJson);
    queryParameters.put(CONCEPTS, conceptsJson.toString());

    return executeRequest(conceptId + RELATION_SCORES_PATH, queryParameters, Scores.class);
  }
Ejemplo n.º 2
0
  /**
   * Searches for documents and concepts by using partial matches on the label(s) fields.
   *
   * @param parameters The parameters to be used in the service call, account_id, corpus and query
   *     are required.
   *     <ul>
   *       <li>String account_id - The account identifier.<br>
   *       <li>String corpus - The corpus name.<br>
   *       <li>RequestedFields concept_fields - Additional fields to be included in the concept
   *           objects.<br>
   *       <li>RequestedFields document_fields - Additional fields to be included in the document
   *           objects.<br>
   *       <li>Boolean concepts - Whether to return concepts that have a label match.<br>
   *       <li>String query - The query string.<br>
   *       <li>Boolean prefix - Whether the query string should be treated as a prefix.<br>
   *       <li>Integer limit - The maximum number of concepts to be returned.<br>
   *     </ul>
   *
   * @return {@link Matches}
   */
  public Matches searchCorpusByLabel(Map<String, Object> parameters) {
    Validate.notNull(parameters.get(ACCOUNT_ID), "account_id can't be null");
    Validate.notNull(parameters.get(CORPUS), "corpus can't be null");
    Validate.notNull(parameters.get(QUERY), "query can't be null");

    String corpusId =
        createCorpusIdPath((String) parameters.get(ACCOUNT_ID), (String) parameters.get(CORPUS));

    Map<String, Object> queryParameters = new HashMap<String, Object>();
    String[] queryParams = new String[] {QUERY, PREFIX, LIMIT, CONCEPTS};
    for (String param : queryParams) {
      if (parameters.containsKey(param)) queryParameters.put(param, parameters.get(param));
    }

    if (parameters.get(CONCEPT_FIELDS) != null) {
      RequestedFields fields = (RequestedFields) parameters.get(CONCEPT_FIELDS);
      if (fields != null && fields.getFields() != null && !fields.getFields().isEmpty())
        queryParameters.put(CONCEPT_FIELDS, fields.toString());
    }

    if (parameters.get(DOCUMENT_FIELDS) != null) {
      RequestedFields fields = (RequestedFields) parameters.get(DOCUMENT_FIELDS);
      if (fields != null && fields.getFields() != null && !fields.getFields().isEmpty())
        queryParameters.put(DOCUMENT_FIELDS, fields.toString());
    }
    return executeRequest(corpusId + LABEL_SEARCH_PATH, queryParameters, Matches.class);
  }
Ejemplo n.º 3
0
  private static String formatDate(final Object target, final String pattern, final Locale locale) {

    Validate.notNull(target, "Cannot apply format on null");
    Validate.notNull(locale, "Locale cannot be null");

    final DateFormatKey key = new DateFormatKey(pattern, locale);

    DateFormat dateFormat = dateFormats.get(key);
    if (dateFormat == null) {
      if (pattern == null || pattern.trim().equals("")) {
        dateFormat = DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG, locale);
      } else {
        dateFormat = new SimpleDateFormat(pattern, locale);
      }
      dateFormats.put(key, dateFormat);
    }

    if (target instanceof Calendar) {
      return dateFormat.format(((Calendar) target).getTime());
    } else if (target instanceof java.util.Date) {
      return dateFormat.format((java.util.Date) target);
    } else {
      throw new IllegalArgumentException(
          "Cannot format object of class \"" + target.getClass().getName() + "\" as a date");
    }
  }
Ejemplo n.º 4
0
 @Test(groups = "method1")
 public void validateTrue() throws DMTException {
   boolean retStatus = false;
   Validate x = new Validate();
   retStatus = x.execute();
   Assert.assertTrue(retStatus);
 }
  /* (non-Javadoc)
   * @see org.jboss.arquillian.spi.ServiceLoader#all(java.lang.ClassLoader, java.lang.Class)
   */
  @Override
  public <T> Collection<T> all(ClassLoader classLoader, Class<T> serviceClass) {
    Validate.notNull(classLoader, "ClassLoader must be provided");
    Validate.notNull(serviceClass, "ServiceClass must be provided");

    return createInstances(serviceClass, load(serviceClass, classLoader));
  }
Ejemplo n.º 6
0
 public T header(String name, String value) {
   Validate.notEmpty(name, "Header name must not be empty");
   Validate.notNull(value, "Header value must not be null");
   removeHeader(name); // ensures we don't get an "accept-encoding" and a "Accept-Encoding"
   headers.put(name, value);
   return (T) this;
 }
  /**
   * {@inheritDoc}
   *
   * @see org.jboss.shrinkwrap.api.Archive#add(org.jboss.shrinkwrap.api.asset.Asset,
   *     org.jboss.shrinkwrap.api.ArchivePath)
   */
  @Override
  public T add(Asset asset, ArchivePath path) {
    Validate.notNull(asset, "No asset was specified");
    Validate.notNull(path, "No path was specified");

    return addAsset(path, asset);
  }
 /**
  * {@inheritDoc}
  *
  * @see org.jboss.shrinkwrap.api.Archive#add(org.jboss.shrinkwrap.api.Archive, java.lang.String,
  *     java.lang.Class)
  */
 @Override
 public T add(
     final Archive<?> archive, final String path, final Class<? extends StreamExporter> exporter) {
   Validate.notNull(archive, "Archive must be specified");
   Validate.notNullOrEmpty(path, "Archive Path must be specified");
   Validate.notNull(exporter, "exporter must be specified");
   return this.add(archive, ArchivePaths.create(path), exporter);
 }
Ejemplo n.º 9
0
  /**
   * Set the value in the field with the specified name in the specified object. Supports
   * inheritance.
   *
   * @param object The object to set the value in.
   * @param fieldName The name of the field.
   * @param value The value to set in the field.
   */
  public static void setFieldValue(
      final Object object, final String fieldName, final Object value) {
    Validate.notNull(object, "The object to set the value in can not be null");
    Validate.notEmpty(fieldName, "The name of the field can not be empty");

    final Field field = getField(object, fieldName);
    setValue(object, value, field);
  }
Ejemplo n.º 10
0
  /**
   * Gets the value of the field with the specified name in the specified object. Supports
   * inheritance.
   *
   * @param object The object to get the value from.
   * @param fieldClass The class of the field.
   * @param fieldName The name of the field.
   * @param <T> The class of the field.
   * @return The value in the field of the object.
   */
  public static <T> T getFieldValue(
      final Object object, final Class<T> fieldClass, final String fieldName) {
    Validate.notNull(object, "The object to get the value from can not be null");
    Validate.notNull(fieldClass, "The class of the field can not be null");
    Validate.notEmpty(fieldName, "The name of the field can not be empty");

    final Field field = getField(object, fieldName);
    return getValue(object, fieldClass, field);
  }
Ejemplo n.º 11
0
  /**
   * Retrieves processing state of document.
   *
   * @param accountId String the account identifier,
   * @param corpusName String the corpus name,
   * @param documentName String the document name.
   * @return {@link DocumentProcessingStatus}
   */
  public DocumentProcessingStatus getDocumentProcessingState(
      final String accountId, final String corpusName, final String documentName) {
    Validate.notNull(accountId, "accountId can't be null");
    Validate.notNull(corpusName, "corpusName can't be null");
    Validate.notNull(documentName, "documentName can't be null");

    String documentId = createDocumentIdPath(accountId, corpusName, documentName);
    return executeRequest(documentId + PROCESSING_STATE_PATH, null, DocumentProcessingStatus.class);
  }
Ejemplo n.º 12
0
  /**
   * Retrieves conceptual view of document (including annotations).
   *
   * @param accountId String the account identifier,
   * @param corpusName String the corpus name,
   * @param documentName String the document name.
   * @return {@link DocumentAnnotations}
   */
  public DocumentAnnotations getDocumentAnnotations(
      final String accountId, final String corpusName, final String documentName) {
    Validate.notNull(accountId, "accountId can't be null");
    Validate.notNull(corpusName, "corpusName can't be null");
    Validate.notNull(documentName, "documentName can't be null");

    String documentId = createDocumentIdPath(accountId, corpusName, documentName);
    return executeRequest(documentId + ANNOTATIONS_PATH, null, DocumentAnnotations.class);
  }
Ejemplo n.º 13
0
  /**
   * Retrieves a document from a corpus.
   *
   * @param accountId String the account identifier,
   * @param corpusName String the corpus name.
   * @param documentName String the document name.
   * @return {@link Document}
   */
  public Document getDocument(
      final String accountId, final String corpusName, final String documentName) {
    Validate.notNull(accountId, "accountId can't be null");
    Validate.notNull(corpusName, "corpusName can't be null");
    Validate.notNull(documentName, "documentName can't be null");

    return executeRequest(
        createDocumentIdPath(accountId, corpusName, documentName), null, Document.class);
  }
Ejemplo n.º 14
0
 /**
  * Gets processing state of a Corpus.
  *
  * @param accountId String the account identifier,
  * @param corpusName String the corpus name.
  * @return {@link CorpusProcessingState} The processing state of a given corpus.
  */
 public CorpusProcessingState getCorpusProcessingState(
     final String accountId, final String corpusName) {
   Validate.notNull(accountId, "accountId can't be null");
   Validate.notNull(corpusName, "corpusName can't be null");
   return executeRequest(
       createCorpusIdPath(accountId, corpusName) + PROCESSING_STATE_PATH,
       null,
       CorpusProcessingState.class);
 }
Ejemplo n.º 15
0
 /**
  * Deletes a document in a given corpus.
  *
  * @param accountId String the account identifier,
  * @param corpusName String the corpus name.
  * @param documentName String the document name.
  */
 public void deleteDocument(
     final String accountId, final String corpusName, final String documentName) {
   Validate.notNull(accountId, "accountId can't be null");
   Validate.notNull(corpusName, "corpusName can't be null");
   Validate.notNull(documentName, "documentName can't be null");
   HttpRequestBase request =
       Request.Delete(createDocumentIdPath(accountId, corpusName, documentName)).build();
   executeWithoutResponse(request);
 }
  @Override
  public WebDriverConfiguration createConfiguration(
      ArquillianDescriptor descriptor, Class<? extends Annotation> qualifier) {

    BrowserCapabilitiesRegistry registry = registryInstance.get();

    // first, try to create a BrowserCapabilities object based on Field/Parameter type of @Drone
    // annotated field
    BrowserCapabilities browser = registry.getEntryFor(getDriverReadableName());
    WebDriverConfiguration configuration =
        new WebDriverConfiguration(browser).configure(descriptor, qualifier);

    // then, check if legacy implementationClass was set in the configuration and try to update
    // accordingly
    if (browser == null && Validate.nonEmpty(configuration.getImplementationClass())) {
      browser = registry.getEntryByImplementationClassName(configuration.getImplementationClass());
      if (browser == null) {
        log.log(
            Level.FINE,
            "Available implementationClasses are {}",
            getAvailableImplementationClasses());
        throw new IllegalStateException(
            MessageFormat.format(
                "Unable to initialize WebDriver instance. Please specify a browserCapabilities property instead of implementationClass {1}. Available options are: {0}",
                getAvailableBrowserCapabilities(), configuration.getImplementationClass()));
      }
      configuration.setBrowserCapabilitiesInternal(browser);
      log.log(
          Level.WARNING,
          "Please use browserCapability to specify browser type instead of implementationClass. Available options are: {0}",
          getAvailableBrowserCapabilities());
    }
    // otherwise, we hit a webdriver configuration and we want to use browserCapabilities
    if (browser == null && Validate.nonEmpty(configuration.getBrowserCapabilities())) {
      browser = registry.getEntryFor(configuration.getBrowserCapabilities());
      if (browser == null) {
        throw new IllegalStateException(
            MessageFormat.format(
                "Unable to initialize WebDriver instance. Please specify a valid browserCapabilities instead of {1}. Available options are: {0}",
                getAvailableBrowserCapabilities(), configuration.getBrowserCapabilities()));
      }
      configuration.setBrowserCapabilitiesInternal(browser);
    }

    // if it is still null, go with defaults
    if (browser == null) {
      browser = registry.getEntryFor(WebDriverConfiguration.DEFAULT_BROWSER_CAPABILITIES);
      log.log(
          Level.INFO,
          "Property \"browserCapabilities\" was not specified, using default value of {0}",
          WebDriverConfiguration.DEFAULT_BROWSER_CAPABILITIES);
      configuration.setBrowserCapabilitiesInternal(browser);
    }

    return configuration;
  }
  /* (non-Javadoc)
   * @see org.jboss.arquillian.spi.ServiceLoader#onlyOne(java.lang.ClassLoader, java.lang.Class)
   */
  @Override
  public <T> T onlyOne(ClassLoader classLoader, Class<T> serviceClass) {
    Validate.notNull(classLoader, "ClassLoader must be provided");
    Validate.notNull(serviceClass, "ServiceClass must be provided");

    Set<Class<? extends T>> serviceImpls = load(serviceClass, classLoader);
    verifyOnlyOneOrSameImplementation(serviceClass, serviceImpls);

    return createInstance(serviceImpls.iterator().next());
  }
Ejemplo n.º 18
0
 @Test(expected = DocumentedException.class)
 public void testNoSource() throws Exception {
   final XmlElement xml =
       XmlElement.fromString(
           "<validate xmlns=\""
               + XmlNetconfConstants.URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0
               + "\"/>");
   final Validate validate = new Validate(null, NETCONF_SESSION_ID_FOR_REPORTING);
   validate.handleWithNoSubsequentOperations(null, xml);
 }
Ejemplo n.º 19
0
 /**
  * Returns information for a specific concept node in a graph.
  *
  * @param parameters The parameters to be used in the service call, account_id, graph and concept
  *     are required.
  *     <ul>
  *       <li>String account_id - The account identifier.<br>
  *       <li>String graph - The graph name.<br>
  *       <li>String concept - The concept name.<br>
  *     </ul>
  *
  * @return {@link ConceptMetadata}
  */
 public ConceptMetadata getConcept(Map<String, Object> parameters) {
   Validate.notNull(parameters.get(ACCOUNT_ID), "account_id can't be null");
   Validate.notNull(parameters.get(GRAPH), "graph can't be null");
   Validate.notNull(parameters.get(CONCEPT), "concept can't be null");
   String conceptId =
       createConceptIdPath(
           (String) parameters.get(ACCOUNT_ID),
           (String) parameters.get(GRAPH),
           (String) parameters.get(CONCEPT));
   return executeRequest(conceptId, null, ConceptMetadata.class);
 }
Ejemplo n.º 20
0
  /**
   * Updates existing corpus meta-data (access and permissions).
   *
   * @param accountId String the Account identifier.
   * @param corpus {@link Corpus} the corpus to update.
   */
  public void updateCorpus(final String accountId, final Corpus corpus) {
    Validate.notNull(accountId, "account_id can't be null");
    Validate.notNull(corpus, "corpus can't be null");
    Validate.notNull(corpus.getId(), "corpus.id can't be null");

    HttpRequestBase request =
        Request.Post(createCorpusIdPath(accountId, corpus.getId()))
            .withContent(GsonSingleton.getGson().toJson(corpus), MediaType.APPLICATION_JSON)
            .build();
    executeWithoutResponse(request);
  }
Ejemplo n.º 21
0
  /**
   * Puts the list of permissions into a Bundle.
   *
   * @param bundle A Bundle in which the list of permissions should be stored.
   * @param value The List&lt;String&gt; representing the list of permissions, or null.
   * @throws NullPointerException if the passed in Bundle or permissions list are null
   */
  public static void putPermissions(Bundle bundle, List<String> value) {
    Validate.notNull(bundle, "bundle");
    Validate.notNull(value, "value");

    ArrayList<String> arrayList;
    if (value instanceof ArrayList<?>) {
      arrayList = (ArrayList<String>) value;
    } else {
      arrayList = new ArrayList<String>(value);
    }
    bundle.putStringArrayList(PERMISSIONS_KEY, arrayList);
  }
Ejemplo n.º 22
0
 @Test(expected = DocumentedException.class)
 public void testValidationException() throws Exception {
   final XmlElement xml =
       XmlElement.fromString(
           "<validate xmlns=\""
               + XmlNetconfConstants.URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0
               + "\">><source><candidate/></source></validate>");
   final ConfigSubsystemFacade facade = mock(ConfigSubsystemFacade.class);
   doThrow(ValidationException.class).when(facade).validateConfiguration();
   final Validate validate = new Validate(facade, NETCONF_SESSION_ID_FOR_REPORTING);
   validate.handleWithNoSubsequentOperations(null, xml);
 }
Ejemplo n.º 23
0
 public Connection data(String... keyvals) {
   Validate.notNull(keyvals, "Data key value pairs must not be null");
   Validate.isTrue(keyvals.length % 2 == 0, "Must supply an even number of key value pairs");
   for (int i = 0; i < keyvals.length; i += 2) {
     String key = keyvals[i];
     String value = keyvals[i + 1];
     Validate.notEmpty(key, "Data key must not be empty");
     Validate.notNull(value, "Data value must not be null");
     req.data(KeyVal.create(key, value));
   }
   return this;
 }
Ejemplo n.º 24
0
  /**
   * Updates a document in a given corpus.
   *
   * @param accountId String the account identifier,
   * @param corpusName String the corpus name.
   * @param document {@link Document} The document to update.
   */
  public void updateDocument(
      final String accountId, final String corpusName, final Document document) {
    Validate.notNull(accountId, "accountId can't be null");
    Validate.notNull(corpusName, "corpusName can't be null");
    Validate.notNull(document, "document can't be null");
    Validate.notNull(document.getId(), "document.id can't be null");

    HttpRequestBase request =
        Request.Post(createDocumentIdPath(accountId, corpusName, document.getId()))
            .withContent(GsonSingleton.getGson().toJson(document), MediaType.APPLICATION_JSON)
            .build();
    executeWithoutResponse(request);
  }
Ejemplo n.º 25
0
  /* (non-Javadoc)
   * @see org.jboss.arquillian.spi.ServiceLoader#onlyOne(java.lang.Class, java.lang.Class)
   */
  public <T> T onlyOne(Class<T> serviceClass, Class<? extends T> defaultServiceClass) {
    Validate.notNull(serviceClass, "ServiceClass must be provided");
    Validate.notNull(defaultServiceClass, "DefaultServiceClass must be provided");

    Class<? extends T> serviceImplToCreate = defaultServiceClass;

    Set<Class<? extends T>> serviceImpls =
        load(serviceClass, SecurityActions.getThreadContextClassLoader());
    if (serviceImpls.size() > 0) {
      verifySameImplementation(serviceClass, serviceImpls);
      serviceImplToCreate = serviceImpls.iterator().next();
    }
    return createInstance(serviceImplToCreate);
  }
Ejemplo n.º 26
0
 @Test
 public void testValidation() throws Exception {
   final XmlElement xml =
       XmlElement.fromString(
           "<validate xmlns=\""
               + XmlNetconfConstants.URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0
               + "\"><source><candidate/></source></validate>");
   final Element okElement = XmlUtil.readXmlToElement("<ok/>");
   final ConfigSubsystemFacade facade = mock(ConfigSubsystemFacade.class);
   doNothing().when(facade).validateConfiguration();
   final Validate validate = new Validate(facade, NETCONF_SESSION_ID_FOR_REPORTING);
   Element ok = validate.handleWithNoSubsequentOperations(XmlUtil.newDocument(), xml);
   assertEquals(XmlUtil.toString(okElement), XmlUtil.toString(ok));
 }
Ejemplo n.º 27
0
  /**
   * Executes sql script and returns given column values.
   *
   * @param sql script to execute
   * @param columnName column to return
   * @return {@link List}&lt;{@link String}&gt; values of the column
   * @throws DatabaseException
   */
  protected List<String> executeToStringList(String sql, String columnName)
      throws DatabaseException {
    Validate.notEmpty(sql, "[sql] parameter cannot be null or empty");
    Validate.notEmpty(columnName, "[columnName] parameter cannot be null or empty");

    try (ResultSet rs = executeQuery(sql)) {
      List<String> result = new ArrayList<>();
      while (rs.next()) {
        result.add(rs.getString(columnName));
      }
      return result;
    } catch (SQLException e) {
      throw new DatabaseException(e);
    }
  }
Ejemplo n.º 28
0
 public Connection data(Map<String, String> data) {
   Validate.notNull(data, "Data map must not be null");
   for (Map.Entry<String, String> entry : data.entrySet()) {
     req.data(KeyVal.create(entry.getKey(), entry.getValue()));
   }
   return this;
 }
Ejemplo n.º 29
0
 /**
  * 循环向上转型, 获取对象的DeclaredField, 并强制设置为可访问.
  *
  * <p>如向上转型到Object仍无法找到, 返回null.
  */
 public static Field getAccessibleField(final Object obj, final String fieldName) {
   Validate.checkNotNull(obj, "object can't be null");
   Validate.checkNotNull(fieldName, "fieldName can't be blank");
   for (Class<?> superClass = obj.getClass();
       superClass != Object.class;
       superClass = superClass.getSuperclass()) {
     try {
       Field field = superClass.getDeclaredField(fieldName);
       makeAccessible(field);
       return field;
     } catch (NoSuchFieldException e) { // NOSONAR
       // Field不在当前类定义,继续向上转型
     }
   }
   return null;
 }
Ejemplo n.º 30
0
  /**
   * Executes sql script and returns map with given column key-values.
   *
   * @param sql script to execute
   * @param columnName1 key of the map entry
   * @param columnName2 value of the map entry
   * @return {@link Map}&lt;{@link String}, {@link String}&gt; values of given columns
   * @throws DatabaseException
   */
  protected Map<String, String> executeToStringMap(
      String sql, String columnName1, String columnName2) throws DatabaseException {
    Validate.notEmpty(sql, "[sql] parameter cannot be null or empty");
    Validate.notEmpty(columnName1, "[columnName1] parameter cannot be null or empty");
    Validate.notEmpty(columnName2, "[columnName2] parameter cannot be null or empty");

    try (ResultSet rs = executeQuery(sql)) {
      Map<String, String> result = new HashMap<>();
      while (rs.next()) {
        result.put(rs.getString(columnName1), rs.getString(columnName2));
      }
      return result;
    } catch (SQLException e) {
      throw new DatabaseException(e);
    }
  }