Search in sources :

Example 16 with Profile

use of com.walmartlabs.concord.runtime.v2.model.Profile in project concord by walmartlabs.

the class ProjectLoaderV2Test method testMultiProjectFiles.

@Test
@SuppressWarnings("unchecked")
public void testMultiProjectFiles() throws Exception {
    ProjectLoaderV2 loader = new ProjectLoaderV2(mock(ImportManager.class));
    URI uri = ClassLoader.getSystemResource("multiProjectFile").toURI();
    ProjectLoaderV2.Result result = loader.load(Paths.get(uri), new NoopImportsNormalizer(), ImportsListener.NOP_LISTENER);
    assertNotNull(result);
    assertNotNull(result.getProjectDefinition());
    ProcessDefinition pd = result.getProjectDefinition();
    // configuration:
    ProcessDefinitionConfiguration cfg = pd.configuration();
    assertNotNull(cfg);
    // configuration.debug: should be collected from ROOT concord.yml
    assertTrue(cfg.debug());
    // configuration.activeProfiles: should be collected from ROOT concord.yml
    assertEquals(Collections.singletonList("concord.yml"), cfg.activeProfiles());
    // configuration.entryPoint: should be collected from ROOT concord.yml
    assertEquals("root", cfg.entryPoint());
    // configuration.dependencies: should be collected from ALL *.concord.yml
    assertEquals(Arrays.asList("2.concord.yml", "concord.yml"), cfg.dependencies());
    // configuration.arguments: should be collected from ALL *.concord.yml and mereged
    assertEquals("ttt", cfg.arguments().get("abc"));
    assertEquals("234", ((Map<String, Object>) cfg.arguments().get("nested")).get("value"));
    // configuration.meta: should be collected from ROOT concord.yml
    assertEquals(Collections.singletonMap("k", "concord.yml"), cfg.meta());
    // configuration.events: should be collected from ROOT concord.yml
    assertEquals(EventConfiguration.builder().recordTaskInVars(true).recordTaskOutVars(true).truncateInVars(true).truncateOutVars(true).truncateMaxStringLength(1).truncateMaxArrayLength(2).truncateMaxDepth(3).inVarsBlacklist(Arrays.asList("apiKey", "apiRootToken")).recordTaskMeta(true).truncateMeta(true).build(), cfg.events());
    // configuration.requirements: should be collected from ROOT concord.yml
    assertEquals(Collections.singletonMap("req", "concord.yml"), cfg.requirements());
    // configuration.processTimeout: should be collected from ROOT concord.yml
    assertEquals("PT1H", cfg.processTimeout().toString());
    // configuration.suspendTimeout: should be collected from ROOT concord.yml
    assertEquals("PT26H", cfg.suspendTimeout().toString());
    // configuration.out: should be collected from ROOT concord.yml
    assertEquals(Collections.singletonList("from-root"), cfg.out());
    // configuration.template: should be collected from ROOT concord.yml
    assertNotNull(cfg.template());
    assertEquals("mytemplate", cfg.template());
    // flows: should be collected from ALL *.concord.yml
    // if flow has same name then most recent used
    assertEquals(new HashSet<>(Arrays.asList("default", "flowN3")), pd.flows().keySet());
    assertEquals(1, pd.flows().get("default").size());
    assertTrue(pd.flows().get("default").get(0) instanceof Checkpoint);
    assertEquals("root", ((Checkpoint) pd.flows().get("default").get(0)).getName());
    // publicFlows: should be collected from ROOT concord.yml
    assertEquals(Collections.singleton("root"), pd.publicFlows());
    // profiles: should be collected from ALL *.concord.yml
    // if profile has same name then most recent used
    assertEquals(Collections.emptyMap(), pd.profiles());
    // triggers: should be collected from ALL *.concord.yml
    assertEquals(3, pd.triggers().size());
    assertEquals(Arrays.asList("1.concord.yml", "2.concord.yml", "concord.yml"), pd.triggers().stream().map(t -> t.configuration().get("entryPoint")).collect(Collectors.toList()));
    // imports: should be collected from ALL *.concord.yml
    assertEquals(2, pd.imports().items().size());
    assertEquals(Arrays.asList("2.concord.yml", "concord.yml"), pd.imports().items().stream().map(i -> ((Import.GitDefinition) i).url()).collect(Collectors.toList()));
    // forms: should be collected from ALL *.concord.yml
    // if form has same name then most recent used
    assertEquals(1, pd.forms().size());
    assertNotNull(pd.forms().get("myForm"));
    assertEquals(1, pd.forms().get("myForm").fields().size());
    assertEquals("myName3", pd.forms().get("myForm").fields().get(0).name());
    // resources: should be collected from ALL *.concord.yml
    assertEquals(Arrays.asList("glob:concord/{**/,}{*.,}concord.{yml,yaml}", "glob:tmp/1.yml"), pd.resources().concord());
}
Also used : ImportManager(com.walmartlabs.concord.imports.ImportManager) ProcessDefinitionConfiguration(com.walmartlabs.concord.runtime.v2.model.ProcessDefinitionConfiguration) ProjectLoaderV2(com.walmartlabs.concord.runtime.v2.ProjectLoaderV2) Checkpoint(com.walmartlabs.concord.runtime.v2.model.Checkpoint) Import(com.walmartlabs.concord.imports.Import) NoopImportsNormalizer(com.walmartlabs.concord.runtime.v2.NoopImportsNormalizer) ProcessDefinition(com.walmartlabs.concord.runtime.v2.model.ProcessDefinition) URI(java.net.URI) Test(org.junit.jupiter.api.Test)

Example 17 with Profile

use of com.walmartlabs.concord.runtime.v2.model.Profile in project android-sdk-button by getyoti.

the class CallbackIntentService method handleActionRetrieveProfile.

/**
 * Handle action Retrieve profile in the provided background thread with the provided
 * parameters - accepting the Yoti callbackURL, token and fullURL (a combination of token and callback)
 */
private void handleActionRetrieveProfile(String callbackUrl, String token, String fullUrl) {
    byte[] response = new byte[0];
    try {
        // This will be the Url to your backend.
        // If you are already using the callback Url specified in the settings of your
        // application (in dashboard) for your web SDK for example, you will have to define a
        // new endpoint in your backend that deals with json responses.
        URL url = new URL(fullUrl.replace("profile", "profile-json"));
        HttpsURLConnection urlConnection = (HttpsURLConnection) url.openConnection();
        response = getBytes(urlConnection);
    } catch (IOException e) {
        Log.e(TAG, "Error when calling our backend manually!", e);
    }
    Gson g = new GsonBuilder().create();
    try {
        Profile profile = g.fromJson(new String(response), Profile.class);
        Intent intent = new Intent(this, MainActivity.class);
        intent.putExtra(NAME_EXTRA, profile.getGivenNames() + " " + profile.getFamilyName());
        intent.putExtra(EMAIL_EXTRA, profile.getEmailAddress());
        intent.putExtra(IMAGE_EXTRA, profile.getSelfie());
        intent.putExtra(DOB_EXTRA, profile.getDateOfBirth());
        intent.putExtra(ADDRESS_EXTRA, profile.getPostalAddress());
        intent.putExtra(MOBILE_EXTRA, profile.getMobNum());
        intent.putExtra(GENDER_EXTRA, profile.getGender());
        intent.putExtra(PROFILE_EXTRA, true);
        intent.addFlags(FLAG_ACTIVITY_NEW_TASK);
        startActivity(intent);
    } catch (Exception e) {
        Intent intent = new Intent(this, MainActivity.class);
        intent.putExtra(BACKEND_DATA_ERROR_EXTRA, true);
        intent.addFlags(FLAG_ACTIVITY_NEW_TASK);
        startActivity(intent);
    }
}
Also used : GsonBuilder(com.google.gson.GsonBuilder) Gson(com.google.gson.Gson) Intent(android.content.Intent) IOException(java.io.IOException) MainActivity(com.yoti.mobile.android.sampleapp2.MainActivity) URL(java.net.URL) HttpsURLConnection(javax.net.ssl.HttpsURLConnection) Profile(com.yoti.mobile.android.sampleapp2.model.Profile) IOException(java.io.IOException)

Example 18 with Profile

use of com.walmartlabs.concord.runtime.v2.model.Profile in project java-sdk by watson-developer-cloud.

the class PersonalityInsights method profile.

/**
 * Get profile.
 *
 * <p>Generates a personality profile for the author of the input text. The service accepts a
 * maximum of 20 MB of input content, but it requires much less text to produce an accurate
 * profile. The service can analyze text in Arabic, English, Japanese, Korean, or Spanish. It can
 * return its results in a variety of languages.
 *
 * <p>**See also:** * [Requesting a
 * profile](https://cloud.ibm.com/docs/personality-insights?topic=personality-insights-input#input)
 * * [Providing sufficient
 * input](https://cloud.ibm.com/docs/personality-insights?topic=personality-insights-input#sufficient)
 *
 * <p>### Content types
 *
 * <p>You can provide input content as plain text (`text/plain`), HTML (`text/html`), or JSON
 * (`application/json`) by specifying the **Content-Type** parameter. The default is `text/plain`.
 * * Per the JSON specification, the default character encoding for JSON content is effectively
 * always UTF-8. * Per the HTTP specification, the default encoding for plain text and HTML is
 * ISO-8859-1 (effectively, the ASCII character set).
 *
 * <p>When specifying a content type of plain text or HTML, include the `charset` parameter to
 * indicate the character encoding of the input text; for example, `Content-Type:
 * text/plain;charset=utf-8`.
 *
 * <p>**See also:** [Specifying request and response
 * formats](https://cloud.ibm.com/docs/personality-insights?topic=personality-insights-input#formats)
 *
 * <p>### Accept types
 *
 * <p>You must request a response as JSON (`application/json`) or comma-separated values
 * (`text/csv`) by specifying the **Accept** parameter. CSV output includes a fixed number of
 * columns. Set the **csv_headers** parameter to `true` to request optional column headers for CSV
 * output.
 *
 * <p>**See also:** * [Understanding a JSON
 * profile](https://cloud.ibm.com/docs/personality-insights?topic=personality-insights-output#output)
 * * [Understanding a CSV
 * profile](https://cloud.ibm.com/docs/personality-insights?topic=personality-insights-outputCSV#outputCSV).
 *
 * @param profileOptions the {@link ProfileOptions} containing the options for the call
 * @return a {@link ServiceCall} with a result of type {@link Profile}
 */
public ServiceCall<Profile> profile(ProfileOptions profileOptions) {
    com.ibm.cloud.sdk.core.util.Validator.notNull(profileOptions, "profileOptions cannot be null");
    RequestBuilder builder = RequestBuilder.post(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/v3/profile"));
    Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("personality_insights", "v3", "profile");
    for (Entry<String, String> header : sdkHeaders.entrySet()) {
        builder.header(header.getKey(), header.getValue());
    }
    builder.header("Accept", "application/json");
    if (profileOptions.contentType() != null) {
        builder.header("Content-Type", profileOptions.contentType());
    }
    if (profileOptions.contentLanguage() != null) {
        builder.header("Content-Language", profileOptions.contentLanguage());
    }
    if (profileOptions.acceptLanguage() != null) {
        builder.header("Accept-Language", profileOptions.acceptLanguage());
    }
    builder.query("version", String.valueOf(this.version));
    if (profileOptions.rawScores() != null) {
        builder.query("raw_scores", String.valueOf(profileOptions.rawScores()));
    }
    if (profileOptions.csvHeaders() != null) {
        builder.query("csv_headers", String.valueOf(profileOptions.csvHeaders()));
    }
    if (profileOptions.consumptionPreferences() != null) {
        builder.query("consumption_preferences", String.valueOf(profileOptions.consumptionPreferences()));
    }
    builder.bodyContent(profileOptions.contentType(), profileOptions.content(), null, profileOptions.body());
    ResponseConverter<Profile> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<Profile>() {
    }.getType());
    return createServiceCall(builder.build(), responseConverter);
}
Also used : RequestBuilder(com.ibm.cloud.sdk.core.http.RequestBuilder) Profile(com.ibm.watson.personality_insights.v3.model.Profile)

Example 19 with Profile

use of com.walmartlabs.concord.runtime.v2.model.Profile in project java-sdk by watson-developer-cloud.

the class PersonalityInsightsIT method getProfileWithASingleSpanishContentItem.

/**
 * Gets the profile from a single content item in Spanish.
 *
 * @throws Exception the exception
 */
@Test
public void getProfileWithASingleSpanishContentItem() throws Exception {
    File file = new File(RESOURCE + "es.txt");
    String englishText = getStringFromInputStream(new FileInputStream(file));
    ContentItem cItem = new ContentItem.Builder(englishText).language(ContentItem.Language.ES).build();
    Content content = new Content.Builder().contentItems(Collections.singletonList(cItem)).build();
    ProfileOptions options = new ProfileOptions.Builder().content(content).consumptionPreferences(true).rawScores(true).build();
    Profile profile = service.profile(options).execute().getResult();
    assertProfile(profile);
}
Also used : ProfileOptions(com.ibm.watson.personality_insights.v3.model.ProfileOptions) Content(com.ibm.watson.personality_insights.v3.model.Content) File(java.io.File) FileInputStream(java.io.FileInputStream) ContentItem(com.ibm.watson.personality_insights.v3.model.ContentItem) Profile(com.ibm.watson.personality_insights.v3.model.Profile) WatsonServiceTest(com.ibm.watson.common.WatsonServiceTest) Test(org.junit.Test)

Example 20 with Profile

use of com.walmartlabs.concord.runtime.v2.model.Profile in project java-sdk by watson-developer-cloud.

the class PersonalityInsightsIT method testReadme.

/**
 * Test example in Readme.
 */
@Test
public void testReadme() {
    // Demo content from Moby Dick by Hermann Melville (Chapter 1)
    String text = "Call me Ishmael. Some years ago-never mind how long precisely-having " + "little or no money in my purse, and nothing particular to interest me on shore, " + "I thought I would sail about a little and see the watery part of the world. " + "It is a way I have of driving off the spleen and regulating the circulation. " + "Whenever I find myself growing grim about the mouth; whenever it is a damp, " + "drizzly November in my soul; whenever I find myself involuntarily pausing before " + "coffin warehouses, and bringing up the rear of every funeral I meet; and especially " + "whenever my hypos get such an upper hand of me, that it requires a strong moral " + "principle to prevent me from deliberately stepping into the street, and methodically " + "knocking people's hats off-then, I account it high time to get to sea as soon as I can. " + "This is my substitute for pistol and ball. With a philosophical flourish Cato throws himself " + "upon his sword; I quietly take to the ship. There is nothing surprising in this. " + "If they but knew it, almost all men in their degree, some time or other, cherish " + "very nearly the same feelings towards the ocean with me. There now is your insular " + "city of the Manhattoes, belted round by wharves as Indian isles by coral reefs-commerce surrounds " + "it with her surf. Right and left, the streets take you waterward.";
    ProfileOptions options = new ProfileOptions.Builder().text(text).build();
    Profile profile = service.profile(options).execute().getResult();
    Assert.assertNotNull(profile);
// System.out.println(profile);
}
Also used : ProfileOptions(com.ibm.watson.personality_insights.v3.model.ProfileOptions) Profile(com.ibm.watson.personality_insights.v3.model.Profile) WatsonServiceTest(com.ibm.watson.common.WatsonServiceTest) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)13 Profile (com.ibm.watson.developer_cloud.personality_insights.v3.model.Profile)10 ProfileOptions (com.ibm.watson.developer_cloud.personality_insights.v3.model.ProfileOptions)9 Profile (com.ibm.watson.personality_insights.v3.model.Profile)7 ProfileOptions (com.ibm.watson.personality_insights.v3.model.ProfileOptions)6 File (java.io.File)6 FileInputStream (java.io.FileInputStream)6 WatsonServiceTest (com.ibm.watson.common.WatsonServiceTest)5 WatsonServiceTest (com.ibm.watson.developer_cloud.WatsonServiceTest)5 Content (com.ibm.watson.developer_cloud.personality_insights.v3.model.Content)4 Content (com.ibm.watson.personality_insights.v3.model.Content)4 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)4 WatsonServiceUnitTest (com.ibm.watson.developer_cloud.WatsonServiceUnitTest)3 ContentItem (com.ibm.watson.personality_insights.v3.model.ContentItem)3 ContentItem (com.ibm.watson.developer_cloud.personality_insights.v3.model.ContentItem)2 ImportManager (com.walmartlabs.concord.imports.ImportManager)2 ProjectLoaderV2 (com.walmartlabs.concord.runtime.v2.ProjectLoaderV2)2 ProcessDefinition (com.walmartlabs.concord.runtime.v2.model.ProcessDefinition)2 IOException (java.io.IOException)2 Intent (android.content.Intent)1