org.jooq.lambda.tuple.Tuple3 Java Examples

The following examples show how to use org.jooq.lambda.tuple.Tuple3. 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: HigherEducationTaxonomyImport.java    From waltz with Apache License 2.0 6 votes vote down vote up
/**
 * @param tx
 * @param categoryId
 * @param newCapabilities  Set of (id, name, desc) tuples
 */
private int insertNewCapabilities(DSLContext tx,
                                  long categoryId,
                                  Collection<Tuple3<String, String, String>> newCapabilities) {
    return newCapabilities
            .stream()
            .map(t -> {
                MeasurableRecord record = tx.newRecord(MEASURABLE);
                record.setMeasurableCategoryId(categoryId);
                record.setExternalId(t.v1);
                record.setName(t.v2);
                record.setDescription(t.v3);
                record.setProvenance(PROVENANCE);
                record.setLastUpdatedBy("admin");
                record.setLastUpdatedAt(DateTimeUtilities.nowUtcTimestamp());
                return record;
            })
            .collect(collectingAndThen(toSet(), tx::batchInsert))
            .execute()
            .length;
}
 
Example #2
Source File: InlineSelectFieldFactory.java    From waltz with Apache License 2.0 6 votes vote down vote up
private static Map<EntityKind, Tuple3<Table, Field<Long>, Field<String>>> mkNameFieldMappings() {
    Map<EntityKind, Tuple3<Table, Field<Long>, Field<String>>> mappings = new HashMap<>();
    mappings.put(EntityKind.ACTOR, tuple(ACTOR, ACTOR.ID, ACTOR.NAME));
    mappings.put(EntityKind.ALLOCATION_SCHEME, tuple(ALLOCATION_SCHEME, ALLOCATION_SCHEME.ID, ALLOCATION_SCHEME.NAME));
    mappings.put(EntityKind.APPLICATION, tuple(APPLICATION, APPLICATION.ID, APPLICATION.NAME));
    mappings.put(EntityKind.APP_GROUP, tuple(APPLICATION_GROUP, APPLICATION_GROUP.ID, APPLICATION_GROUP.NAME));
    mappings.put(EntityKind.CHANGE_INITIATIVE, tuple(CHANGE_INITIATIVE, CHANGE_INITIATIVE.ID, CHANGE_INITIATIVE.NAME));
    mappings.put(EntityKind.DATA_TYPE, tuple(DATA_TYPE, DATA_TYPE.ID, DATA_TYPE.NAME));
    mappings.put(EntityKind.FLOW_DIAGRAM, tuple(FLOW_DIAGRAM, FLOW_DIAGRAM.ID, FLOW_DIAGRAM.NAME));
    mappings.put(EntityKind.END_USER_APPLICATION, tuple(END_USER_APPLICATION, END_USER_APPLICATION.ID, END_USER_APPLICATION.NAME));
    mappings.put(EntityKind.ENTITY_STATISTIC, tuple(ENTITY_STATISTIC_DEFINITION, ENTITY_STATISTIC_DEFINITION.ID, ENTITY_STATISTIC_DEFINITION.NAME));
    mappings.put(EntityKind.MEASURABLE, tuple(MEASURABLE, MEASURABLE.ID, MEASURABLE.NAME));
    mappings.put(EntityKind.MEASURABLE_CATEGORY, tuple(MEASURABLE_CATEGORY, MEASURABLE_CATEGORY.ID, MEASURABLE_CATEGORY.NAME));
    mappings.put(EntityKind.ORG_UNIT, tuple(ORGANISATIONAL_UNIT, ORGANISATIONAL_UNIT.ID, ORGANISATIONAL_UNIT.NAME));
    mappings.put(EntityKind.PERSON, tuple(PERSON, PERSON.ID, PERSON.DISPLAY_NAME));
    mappings.put(EntityKind.PHYSICAL_SPECIFICATION, tuple(PHYSICAL_SPECIFICATION, PHYSICAL_SPECIFICATION.ID, PHYSICAL_SPECIFICATION.NAME));
    mappings.put(EntityKind.SERVER, tuple(SERVER_INFORMATION, SERVER_INFORMATION.ID, SERVER_INFORMATION.HOSTNAME));
    return mappings;
}
 
Example #3
Source File: AssessmentGenerator.java    From waltz with Apache License 2.0 6 votes vote down vote up
private RatingScheme getOrCreateRatingScheme(ApplicationContext ctx, String name, Tuple3<String, String, String>... options) {
    DSLContext dsl = getDsl(ctx);
    Long schemeId = dsl
            .select(RATING_SCHEME.ID)
            .from(RATING_SCHEME)
            .where(RATING_SCHEME.NAME.eq(name))
            .fetchOne(RATING_SCHEME.ID);

    if (schemeId == null) {
        schemeId = createRatingScheme(
                dsl,
                name,
                options);
    }

    RatingSchemeService ratingSchemeService = ctx.getBean(RatingSchemeService.class);
    return ratingSchemeService.getById(schemeId);
}
 
Example #4
Source File: SurveyInstanceExtractor.java    From waltz with Apache License 2.0 6 votes vote down vote up
private Tuple3<ExtractFormat, String,byte[]> prepareInstancesOfRun(ExtractFormat format,
                                                                   long runId,
                                                                   Set<SurveyInstanceStatus> statuses) throws IOException {
    Record2<String, Long> r = dsl
            .select(sr.NAME, sr.SURVEY_TEMPLATE_ID)
            .from(sr.where(sr.ID.eq(runId)))
            .fetchOne();

    String reportName = r.component1();
    long templateId = r.component2();

    List<SurveyQuestion> questions = loadQuestions(templateId);
    List<List<Object>> reportRows = prepareReportRowsForRun(questions, runId, statuses);

    return formatReport(
            format,
            reportName,
            questions,
            reportRows);
}
 
Example #5
Source File: ChangeReporter.java    From waltz with Apache License 2.0 6 votes vote down vote up
public static void main(String[] args) throws IOException {
    AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(DIConfiguration.class);
    DSLContext dsl = ctx.getBean(DSLContext.class);
    ApplicationIdSelectorFactory selectorFactory = new ApplicationIdSelectorFactory();

    LocalDateTime exerciseStart = LocalDateTime.of(2018, 06, 04, 0, 1).truncatedTo(ChronoUnit.DAYS);
    LocalDateTime dayBeforeYesterday = LocalDateTime.now().truncatedTo(ChronoUnit.DAYS).minusDays(1);
    LocalDateTime yesterday = LocalDateTime.now().truncatedTo(ChronoUnit.DAYS);

    EntityReference appGroupRef = EntityReference.mkRef(EntityKind.APP_GROUP, 10862); // BCBS239
    Select<Record1<Long>> appSelector = mkSelector(selectorFactory, appGroupRef);

    Tuple3<String, LocalDateTime, LocalDateTime> dayPeriod = Tuple.tuple("day", dayBeforeYesterday, yesterday);
    Tuple3<String, LocalDateTime, LocalDateTime> cumulativePeriod = Tuple.tuple("cumulative", exerciseStart, yesterday);

    dumpReport(dsl, dayPeriod, appGroupRef, appSelector);
    dumpReport(dsl, cumulativePeriod, appGroupRef, appSelector);
}
 
Example #6
Source File: HigherEducationTaxonomyImport.java    From waltz with Apache License 2.0 6 votes vote down vote up
/**
 * Capabilities are recorded as model elements with a type of 'Capability'
 *
 * Each capability has an identifier, a name
 *
 * @param doc  xml document
 * @return tuple(id, name, documentation)
 * @throws XPathExpressionException
 */
private Set<Tuple3<String, String, String>> parseCapabilities(Document doc) throws XPathExpressionException {
    XPathExpression capabilitiesXPath = xpathFactory
            .newXPath()
            .compile("/model/elements/element[@type='Capability']");

    XPathExpression nameXPath = xpathFactory.newXPath().compile("name");
    XPathExpression documentationXPath = xpathFactory.newXPath().compile("documentation");

    Function<Node, String> readNameFn = Unchecked.function(nameXPath::evaluate);
    Function<Node, String> readDocFn = Unchecked.function(documentationXPath::evaluate);

    return XmlUtilities
            .stream((NodeList) capabilitiesXPath.evaluate(doc, XPathConstants.NODESET))
            .map(node -> tuple(
                    node.getAttributes().getNamedItem("identifier").getTextContent(),
                    readNameFn.apply(node),
                    readDocFn.apply(node)))
            .collect(toSet());
}
 
Example #7
Source File: HigherEducationTaxonomyImport.java    From waltz with Apache License 2.0 6 votes vote down vote up
/**
 *
 * @param tx
 * @param categoryId
 * @param relationshipTuples  set of tuples (identifier, source, target)
 */
private void updateParentIds(DSLContext tx,
                             long categoryId,
                             Set<Tuple3<String, String, String>> relationshipTuples) {

    // clear existing external parent id's
    dsl.update(MEASURABLE)
            .setNull(MEASURABLE.EXTERNAL_PARENT_ID)
            .where(MEASURABLE.MEASURABLE_CATEGORY_ID.eq(categoryId))
            .execute();

    // add resolved parent ids
    relationshipTuples
            .stream()
            .map(t -> dsl
                    .update(MEASURABLE)
                    .set(MEASURABLE.EXTERNAL_PARENT_ID, t.v2)
                    .where(MEASURABLE.EXTERNAL_ID.eq(t.v3)))
            .collect(collectingAndThen(toSet(), tx::batch))
            .execute();

    int updated = updateParentIdsUsingExtIds(tx, categoryId);
    log("Updated %d parent ids", updated);
}
 
Example #8
Source File: TuplesRecommendationFormat.java    From RankSys with Mozilla Public License 2.0 6 votes vote down vote up
@Override
public Stream<Recommendation<U, I>> readAll() {
    BufferedReader reader = new BufferedReader(new InputStreamReader(in), 128 * 1024);

    return groupAdjacent(reader.lines().map(tupleReader), (t1, t2) -> t1.v1.equals(t2.v1))
            .map(userTuples -> {
                U user = userTuples.get(0).v1;

                List<Tuple2od<I>> items = userTuples.stream()
                        .map(Tuple3::skip1)
                        .map(Tuple2od::new)
                        .collect(toList());

                if (sortByDecreasingScore) {
                    items.sort(Comparator.comparingDouble((Tuple2od<I> r) -> r.v2)
                            .reversed());
                }

                return new Recommendation<>(user, items);
            });
}
 
Example #9
Source File: ValueTypeTest.java    From json2java4idea with Apache License 2.0 6 votes vote down vote up
@Parameters(name = "{0}")
public static Collection<Tuple3<ValueType, Object, String>> fixtures() {
    return Arrays.asList(
            Tuple.tuple(ValueType.NULL, "null", "Value 'null' is not a null"),
            Tuple.tuple(ValueType.BOOLEAN, null, "Value 'null' is not a boolean"),
            Tuple.tuple(ValueType.INT, null, "Value 'null' is not an int"),
            Tuple.tuple(ValueType.LONG, null, "Value 'null' is not a long"),
            Tuple.tuple(ValueType.FLOAT, null, "Value 'null' is not a float"),
            Tuple.tuple(ValueType.DOUBLE, null, "Value 'null' is not a double"),
            Tuple.tuple(ValueType.BIG_INTEGER, null, "Value 'null' is not a big integer"),
            Tuple.tuple(ValueType.BIG_DECIMAL, null, "Value 'null' is not a big decimal"),
            Tuple.tuple(ValueType.STRING, null, "Value 'null' is not a string"),
            Tuple.tuple(ValueType.ARRAY, null, "Value 'null' is not an array"),
            Tuple.tuple(ValueType.OBJECT, null, "Value 'null' is not an object")
    );
}
 
Example #10
Source File: ValueTypeTest.java    From json2java4idea with Apache License 2.0 6 votes vote down vote up
@Parameters(name = "{0}")
public static Collection<Tuple3<ValueType, Object, Class>> fixtures() {
    return Arrays.asList(
            Tuple.tuple(ValueType.NULL, null, JsonNull.class),
            Tuple.tuple(ValueType.BOOLEAN, true, JsonBoolean.class),
            Tuple.tuple(ValueType.INT, 42, JsonNumber.class),
            Tuple.tuple(ValueType.LONG, 42L, JsonNumber.class),
            Tuple.tuple(ValueType.FLOAT, 4.2f, JsonNumber.class),
            Tuple.tuple(ValueType.DOUBLE, 4.2d, JsonNumber.class),
            Tuple.tuple(ValueType.BIG_INTEGER, BigInteger.ONE, JsonNumber.class),
            Tuple.tuple(ValueType.BIG_DECIMAL, BigDecimal.ONE, JsonNumber.class),
            Tuple.tuple(ValueType.STRING, "foo", JsonString.class),
            Tuple.tuple(ValueType.ARRAY, Collections.emptyList(), JsonArray.class),
            Tuple.tuple(ValueType.OBJECT, Collections.emptyMap(), JsonObject.class)
    );
}
 
Example #11
Source File: JoolTupleTest.java    From SimpleFlatMapper with MIT License 6 votes vote down vote up
@Test
public void testCsvParser() throws IOException {
    final CsvParser.StaticMapToDSL<Tuple3<Long, Integer, Short>> mapToDSL = CsvParser.mapTo(new TypeReference<Tuple3<Long, Integer, Short>>() {
    }).defaultHeaders();
    final Iterator<Tuple3<Long, Integer, Short>> iterator = mapToDSL.iterator(new StringReader("6,7,3\n7,8,9"));

    final Tuple3<Long, Integer, Short> tuple1 = iterator.next();

    assertEquals(6l, tuple1.v1().longValue());
    assertEquals(7, tuple1.v2().intValue());
    assertEquals((short)3, tuple1.v3().shortValue());

    final Tuple3<Long, Integer, Short> tuple2 = iterator.next();

    assertEquals(7l, tuple2.v1().longValue());
    assertEquals(8, tuple2.v2().intValue());
    assertEquals((short)9, tuple2.v3().shortValue());
}
 
Example #12
Source File: SimpleRatingPreferencesReader.java    From RankSys with Mozilla Public License 2.0 5 votes vote down vote up
@Override
public <U, I> Stream<Tuple3<U, I, Double>> read(InputStream in, Parser<U> up, Parser<I> ip) {
    return new BufferedReader(new InputStreamReader(in)).lines().map(line -> {
        CharSequence[] tokens = split(line, '\t', 4);
        U user = up.parse(tokens[0]);
        I item = ip.parse(tokens[1]);
        double value = parseDouble(tokens[2].toString());

        return Tuple.tuple(user, item, value);
    });
}
 
Example #13
Source File: SimpleFeaturesReader.java    From RankSys with Mozilla Public License 2.0 5 votes vote down vote up
@Override
public <I, F> Stream<Tuple3<I, F, Double>> read(InputStream in, Parser<I> ip, Parser<F> fp) {
    return new BufferedReader(new InputStreamReader(in)).lines().map(line -> {
        String[] tokens = line.split("\t", 3);
        I item = ip.parse(tokens[0]);
        F feat = fp.parse(tokens[1]);

        return Tuple.tuple(item, feat, 1.0);
    });
}
 
Example #14
Source File: InlineSelectFieldFactory.java    From waltz with Apache License 2.0 5 votes vote down vote up
private static Map<EntityKind, Tuple3<Table, Field<Long>, Field<String>>> mkLifecycleFieldMappings() {
    Map<EntityKind, Tuple3<Table, Field<Long>, Field<String>>> mappings = new HashMap<>();
    mappings.put(EntityKind.APPLICATION, tuple(APPLICATION, APPLICATION.ID, APPLICATION.ENTITY_LIFECYCLE_STATUS));
    mappings.put(EntityKind.LOGICAL_DATA_ELEMENT, tuple(LOGICAL_DATA_ELEMENT, LOGICAL_DATA_ELEMENT.ID, LOGICAL_DATA_ELEMENT.ENTITY_LIFECYCLE_STATUS));
    mappings.put(EntityKind.ACTOR, tuple(ACTOR, ACTOR.ID, DSL.val(EntityLifecycleStatus.ACTIVE.name())));
    return mappings;
}
 
Example #15
Source File: SimpleFeatureData.java    From RankSys with Mozilla Public License 2.0 5 votes vote down vote up
/**
 * Loads an instance of the class from a stream of triples.
 *
 * @param <I> type of item
 * @param <F> type of feat
 * @param <V> type of value
 * @param tuples stream of item-feat-value triples
 * @return a feature data object
 */
public static <I, F, V> SimpleFeatureData<I, F, V> load(Stream<Tuple3<I, F, V>> tuples) {
    Map<I, List<Tuple2<F, V>>> itemMap = new HashMap<>();
    Map<F, List<Tuple2<I, V>>> featMap = new HashMap<>();

    tuples.forEach(t -> {
        itemMap.computeIfAbsent(t.v1, v1 -> new ArrayList<>()).add(tuple(t.v2, t.v3));
        featMap.computeIfAbsent(t.v2, v2 -> new ArrayList<>()).add(tuple(t.v1, t.v3));
    });

    return new SimpleFeatureData<>(itemMap, featMap);
}
 
Example #16
Source File: SimpleBinaryPreferencesReader.java    From RankSys with Mozilla Public License 2.0 5 votes vote down vote up
@Override
public <U, I> Stream<Tuple3<U, I, Double>> read(InputStream in, Parser<U> up, Parser<I> ip) {
    return new BufferedReader(new InputStreamReader(in)).lines().map(line -> {
        CharSequence[] tokens = split(line, '\t', 3);
        U user = up.parse(tokens[0]);
        I item = ip.parse(tokens[1]);

        return Tuple.tuple(user, item, 1.0);
    });
}
 
Example #17
Source File: DataExtractor.java    From waltz with Apache License 2.0 5 votes vote down vote up
default Object writeReportResults(Response response, Tuple3<ExtractFormat, String, byte[]> reportResult) throws IOException {
    String templateName = reportResult.v2;

    HttpServletResponse httpResponse = response.raw();

    switch (reportResult.v1) {
        case XLSX:
            httpResponse.setHeader("Content-Type", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
            httpResponse.setHeader("Content-Disposition", "attachment; filename=" + templateName + ".xlsx");
            httpResponse.setHeader("Content-Transfer-Encoding", "7bit");
            break;
        case CSV:
            response.type(MimeTypes.Type.TEXT_PLAIN.name());
            response.header("Content-disposition", "attachment; filename=" + templateName + ".csv");
            break;
        default:
            break;
    }

    byte[] bytes = reportResult.v3;
    httpResponse.setContentLength(bytes.length);
    httpResponse.getOutputStream().write(bytes);
    httpResponse.getOutputStream().flush();
    httpResponse.getOutputStream().close();

    return httpResponse;
}
 
Example #18
Source File: SurveyInstanceExtractor.java    From waltz with Apache License 2.0 5 votes vote down vote up
private Tuple3<ExtractFormat, String, byte[]> formatReport(ExtractFormat format,
                                                           String reportName,
                                                           List<SurveyQuestion> questions,
                                                           List<List<Object>> reportRows) throws IOException {
    switch (format) {
        case XLSX:
            return tuple(format, reportName, mkExcelReport(reportName, questions, reportRows));
        case CSV:
            return tuple(format, reportName, mkCSVReport(questions, reportRows));
        default:
            throw new UnsupportedOperationException("This report does not support export format: " + format);
    }
}
 
Example #19
Source File: SurveyInstanceExtractor.java    From waltz with Apache License 2.0 5 votes vote down vote up
private Tuple3<ExtractFormat, String, byte[]> prepareInstancesOfTemplate(ExtractFormat format,
                                                                         long templateId,
                                                                         Set<SurveyInstanceStatus> statuses) throws IOException {
    String reportName = loadTemplateName(templateId);

    List<SurveyQuestion> questions = loadQuestions(templateId);
    List<List<Object>> reportRows = prepareReportRowsForTemplate(questions, templateId, statuses);

    return formatReport(
            format,
            reportName,
            questions,
            reportRows);
}
 
Example #20
Source File: InlineSelectFieldFactory.java    From waltz with Apache License 2.0 5 votes vote down vote up
private Select<Record1<String>> mkFieldSelect(Tuple3<Table, Field<Long>, Field<String>> mapping,
                                                    Field<Long> idCompareField) {
    // form the query to fetch entity names
    //
    // v1: entity table
    // v3: name field in the entity table
    // v2: id field in the entity table
    //
    // eg: select name from application where id = entity_statistic_value.entity_id
    //
    return DSL.select(mapping.v3())
            .from(mapping.v1())
            .where(mapping.v2().eq(idCompareField));
}
 
Example #21
Source File: InlineSelectFieldFactory.java    From waltz with Apache License 2.0 5 votes vote down vote up
private static Map<EntityKind,Tuple3<Table,Field<Long>,Field<String>>> mkExternalIdMappings() {
    Map<EntityKind, Tuple3<Table, Field<Long>, Field<String>>> mappings = new HashMap<>();
    mappings.put(EntityKind.APPLICATION, tuple(APPLICATION, APPLICATION.ID, APPLICATION.ASSET_CODE));
    mappings.put(EntityKind.CHANGE_INITIATIVE, tuple(CHANGE_INITIATIVE, CHANGE_INITIATIVE.ID, CHANGE_INITIATIVE.EXTERNAL_ID));
    mappings.put(EntityKind.DATA_TYPE, tuple(DATA_TYPE, DATA_TYPE.ID, DATA_TYPE.CODE));
    mappings.put(EntityKind.END_USER_APPLICATION, tuple(END_USER_APPLICATION, END_USER_APPLICATION.ID, END_USER_APPLICATION.EXTERNAL_ID));
    mappings.put(EntityKind.MEASURABLE, tuple(MEASURABLE, MEASURABLE.ID, MEASURABLE.EXTERNAL_ID));
    mappings.put(EntityKind.MEASURABLE_CATEGORY, tuple(MEASURABLE_CATEGORY, MEASURABLE_CATEGORY.ID, MEASURABLE_CATEGORY.EXTERNAL_ID));
    mappings.put(EntityKind.PERSON, tuple(PERSON, PERSON.ID, PERSON.EMPLOYEE_ID));
    mappings.put(EntityKind.PHYSICAL_SPECIFICATION, tuple(PHYSICAL_SPECIFICATION, PHYSICAL_SPECIFICATION.ID, PHYSICAL_SPECIFICATION.EXTERNAL_ID));
    mappings.put(EntityKind.PHYSICAL_FLOW, tuple(PHYSICAL_FLOW, PHYSICAL_FLOW.ID, PHYSICAL_FLOW.EXTERNAL_ID));
    mappings.put(EntityKind.SERVER, tuple(SERVER_INFORMATION, SERVER_INFORMATION.ID, SERVER_INFORMATION.EXTERNAL_ID));
    return mappings;
}
 
Example #22
Source File: JoolTupleTest.java    From SimpleFlatMapper with MIT License 5 votes vote down vote up
@Test
public void testMetaDataOnJoolTuple() throws Exception {


    //creates a new tuple allocated on the JVM heap

    System.out.println("super " + Tuple3.class.toString());
    for(Class<?> clazz : Tuple3.class.getInterfaces()) {
        System.out.println("I " + clazz.toString());

    }

    ClassMeta<Tuple3<Long, Integer, Short>> cm =
            ReflectionService.newInstance().getClassMeta(new TypeReference<Tuple3<Long, Integer, Short>>(){}.getType());

    final PropertyFinder<Tuple3<Long, Integer, Short>> propertyFinder = cm.newPropertyFinder();

    final PropertyMeta<Tuple3<Long, Integer, Short>, Long> fieldA = propertyFinder.findProperty(new DefaultPropertyNameMatcher("elt0", 0, true, true), new Object[0], (TypeAffinity)null, isValidPropertyMeta);
    final PropertyMeta<Tuple3<Long, Integer, Short>, Integer> fieldB = propertyFinder.findProperty(new DefaultPropertyNameMatcher("elt1", 0, true, true), new Object[0], (TypeAffinity)null, isValidPropertyMeta);
    final PropertyMeta<Tuple3<Long, Integer, Short>, Short> fieldC = propertyFinder.findProperty(new DefaultPropertyNameMatcher("elt2", 0, true, true), new Object[0], (TypeAffinity)null, isValidPropertyMeta);
    final PropertyMeta<Tuple3<Long, Integer, Short>, ?> fieldD = propertyFinder.findProperty(new DefaultPropertyNameMatcher("elt3", 0, true, true), new Object[0], (TypeAffinity)null, isValidPropertyMeta);

    assertNotNull(fieldA);
    assertNotNull(fieldB);
    assertNotNull(fieldC);
    assertNull(fieldD);

    Tuple3<Long, Integer, Short> tuple = new Tuple3<Long, Integer, Short>(6l, 7, (short)3);

    assertTrue(fieldA instanceof ConstructorPropertyMeta);
    assertTrue(fieldB instanceof ConstructorPropertyMeta);
    assertTrue(fieldC instanceof ConstructorPropertyMeta);

    Assert.assertEquals(6l, fieldA.getGetter().get(tuple).longValue());
    Assert.assertEquals(7, fieldB.getGetter().get(tuple).intValue());
    Assert.assertEquals(3, fieldC.getGetter().get(tuple).shortValue());

}
 
Example #23
Source File: PreferenceDataWrapper.java    From rival with Apache License 2.0 5 votes vote down vote up
public PreferenceDataWrapper(TemporalDataModelIF<Long, Long> data, FastUserIndex<Long> uIndex, FastItemIndex<Long> iIndex) {
    List<Tuple3<Long, Long, Double>> tuples = new ArrayList<>();
    for (Long u : data.getUsers()) {
        for (Long i : data.getUserItems(u)) {
            tuples.add(new Tuple3<>(u, i, data.getUserItemPreference(u, i)));
        }
    }
    wrapper = SimpleFastPreferenceData.load(tuples.stream(), uIndex, iIndex);
}
 
Example #24
Source File: AssessmentGenerator.java    From waltz with Apache License 2.0 5 votes vote down vote up
private Long createRatingScheme(DSLContext dsl, String name, Tuple3<String, String, String>... options) {
    // create
    RatingSchemeRecord ratingSchemeRecord = dsl.newRecord(RATING_SCHEME);
    ratingSchemeRecord.setName(name);
    ratingSchemeRecord.setDescription(name +" ratings");
    ratingSchemeRecord.insert();

    System.out.println("Inserted scheme "+ ratingSchemeRecord.getId());

    List<RatingSchemeItemRecord> ratingRecords = Stream
            .of(options)
            .map(t -> {
                RatingSchemeItemRecord itemR = dsl.newRecord(RATING_SCHEME_ITEM);
                itemR.setCode(t.v1);
                itemR.setName(t.v2);
                itemR.setColor(t.v3);
                itemR.setDescription(t.v2);
                itemR.setSchemeId(ratingSchemeRecord.getId());
                itemR.setUserSelectable(true);
                return itemR;
            })
            .collect(toList());

    dsl.batchInsert(ratingRecords).execute();

    return ratingSchemeRecord.getId();
}
 
Example #25
Source File: AssessmentGenerator.java    From waltz with Apache License 2.0 5 votes vote down vote up
private void createLotsOfAssessmentDefinitions(ApplicationContext ctx, RatingScheme ratingScheme) {
    List<Tuple3<EntityKind, String, String>> defns = ListUtilities.newArrayList(
            tuple(EntityKind.APPLICATION, "Sanctions Apply", "Indicates if sanctions apply to this application"),
            tuple(EntityKind.APPLICATION, "Records Retentions Relevancy", "Indicates what record retention rules (if any) apply to this app"),
            tuple(EntityKind.APPLICATION, "Internet facing", "Indicates if an application has a direct connection to the internet"));

    defns.forEach(d -> createAssessmentDefinition(
            getDsl(ctx),
            d.v2,
            d.v3,
            d.v1,
            ratingScheme));
}
 
Example #26
Source File: ValueTypeTest.java    From json2java4idea with Apache License 2.0 5 votes vote down vote up
@Parameters(name = "{0}")
public static Collection<Tuple3<ValueType, Object, Boolean>> fixtures() {
    return Arrays.asList(
            Tuple.tuple(ValueType.NULL, null, true),
            Tuple.tuple(ValueType.NULL, "null", false),
            Tuple.tuple(ValueType.BOOLEAN, true, true),
            Tuple.tuple(ValueType.BOOLEAN, "true", false),
            Tuple.tuple(ValueType.INT, 1024, true),
            Tuple.tuple(ValueType.INT, 1024L, false),
            Tuple.tuple(ValueType.LONG, 1024L, true),
            Tuple.tuple(ValueType.LONG, 1024, false),
            Tuple.tuple(ValueType.FLOAT, 1.0f, true),
            Tuple.tuple(ValueType.FLOAT, 1.0d, false),
            Tuple.tuple(ValueType.DOUBLE, 1.0d, true),
            Tuple.tuple(ValueType.DOUBLE, 1.0f, false),
            Tuple.tuple(ValueType.BIG_INTEGER, BigInteger.ONE, true),
            Tuple.tuple(ValueType.BIG_INTEGER, 1, false),
            Tuple.tuple(ValueType.BIG_DECIMAL, BigDecimal.ONE, true),
            Tuple.tuple(ValueType.BIG_DECIMAL, 1, false),
            Tuple.tuple(ValueType.STRING, "text", true),
            Tuple.tuple(ValueType.STRING, null, false),
            Tuple.tuple(ValueType.ARRAY, Collections.singletonList("test"), true),
            Tuple.tuple(ValueType.ARRAY, null, false),
            Tuple.tuple(ValueType.OBJECT, Collections.singletonMap("key", "test"), true),
            Tuple.tuple(ValueType.OBJECT, null, false)
    );
}
 
Example #27
Source File: PersonResolver.java    From waltz with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) {
    AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(DIBaseConfiguration.class);
    DSLContext dsl = ctx.getBean(DSLContext.class);

    InvolvementNameToIdResolver involvementNameToIdResolver = new InvolvementNameToIdResolver(dsl);
    PersonNameToEmpIdResolver personNameToEmpIdResolver = new PersonNameToEmpIdResolver(dsl);
    OrgNameToIdResolver orgNameToIdResolver = new OrgNameToIdResolver(dsl);

    Siphon<Tuple4<String, String, Optional<Long>, Optional<String>>> noOrgSiphon = mkSiphon(t -> !t.v3.isPresent());
    Siphon<Tuple4<String, String, Optional<Long>, Optional<String>>> noPersonSiphon = mkSiphon(t -> !t.v4.isPresent());


    Set<Tuple3<Long, String, Long>> orgEmpInvTuples = involvementNameToIdResolver
            .resolve(involvementKindName)
            .map(involvementKindId -> data
                    .stream()
                    .flatMap(t -> Stream
                            .of(t.v2.split(" / "))
                            .map(name -> tuple(t.v1, name)))
                    .distinct()
                    .map(t -> t.concat(orgNameToIdResolver.resolve(t.v1)))
                    .map(t -> t.concat(personNameToEmpIdResolver.resolve(t.v2)))
                    .filter(noOrgSiphon)
                    .filter(noPersonSiphon)
                    .map(t -> t
                            .skip2() // throw away raw-data
                            .map1(Optional::get) // empId
                            .map2(Optional::get) // orgId
                            .concat(involvementKindId))
                    .collect(Collectors.toSet()))
            .orElseThrow(() -> new IllegalArgumentException(format("Cannot find involvement kind: %s", involvementKindName)));

    dump("No Org", noOrgSiphon, t -> t.v1);
    dump("No Person", noPersonSiphon, t -> t.v2);

    Set<InvolvementRecord> records = map(orgEmpInvTuples, t -> new InvolvementRecord(EntityKind.ORG_UNIT.name(), t.v1, t.v2, provenance, t.v3, true));
    dsl.batchInsert(records).execute();

}
 
Example #28
Source File: ChangeReporter.java    From waltz with Apache License 2.0 5 votes vote down vote up
private static String mkFilename(Tuple3<String, LocalDateTime, LocalDateTime> period, EntityReference appGroupRef) {
    return StringUtilities.join(
                    newArrayList(
                            period.v1,
                            "activity_report",
                            appGroupRef.id(),
                            "from",
                            period.v2.format(DateTimeFormatter.ISO_DATE),
                            "to",
                            period.v3.format(DateTimeFormatter.ISO_DATE)),
                    "_") + ".csv";
}
 
Example #29
Source File: ChangeReporter.java    From waltz with Apache License 2.0 5 votes vote down vote up
private static String dumpReport(DSLContext dsl,
                                 Tuple3<String, LocalDateTime, LocalDateTime> period,
                                 EntityReference appGroupRef,
                                 Select<Record1<Long>> appSelector) throws IOException {
    String filename = mkFilename(period, appGroupRef);
    String fqn = "c:/temp/" + filename;
    FileWriter writer = new FileWriter(fqn, false);
    summarizeChangesByAppSelector(dsl, appSelector, period.v2, period.v3)
            .formatCSV(writer, ',');

    System.out.println("Done: " + period.v1 + " -> " + fqn);
    return fqn;
}
 
Example #30
Source File: XlsImporter.java    From waltz with Apache License 2.0 5 votes vote down vote up
private int updateParentIds(Long categoryId) {
    List<Tuple3<Long, String, String>> rs = dsl
            .select(MEASURABLE.ID, MEASURABLE.EXTERNAL_ID, MEASURABLE.EXTERNAL_PARENT_ID)
            .from(MEASURABLE)
            .where(MEASURABLE.MEASURABLE_CATEGORY_ID.eq(categoryId))
            .fetch(r -> tuple(
                    r.get(MEASURABLE.ID),
                    r.get(MEASURABLE.EXTERNAL_ID),
                    r.get(MEASURABLE.EXTERNAL_PARENT_ID)));

    Map<String, Long> extToId = indexBy(
            t -> t.v2,
            t -> t.v1,
            rs);

    Set<UpdateConditionStep<MeasurableRecord>> updates = rs
            .stream()
            .filter(t -> !isEmpty(t.v3))
            .map(t -> tuple(t.v1, extToId.get(t.v3)))
            .filter(t -> t.v2 != null)
            .map(t -> dsl
                    .update(MEASURABLE)
                    .set(MEASURABLE.PARENT_ID, t.v2)
                    .where(MEASURABLE.ID.eq(t.v1))
                    .and(MEASURABLE.MEASURABLE_CATEGORY_ID.eq(categoryId)))
            .collect(Collectors.toSet());

    int[] rc = dsl
            .batch(updates)
            .execute();

    log("Updated parent ids for: %d records in category: %d\n", rc.length, categoryId);

    return rc.length;
}