Search in sources :

Example 11 with LookupTableRowType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.LookupTableRowType in project midpoint by Evolveum.

the class RLookupTableRow method toJAXB.

public LookupTableRowType toJAXB() {
    LookupTableRowType row = new LookupTableRowType();
    row.setId(Long.valueOf(id));
    row.setKey(key);
    row.setLastChangeTimestamp(lastChangeTimestamp);
    row.setValue(value);
    row.setLabel(RPolyString.copyToJAXB(label));
    return row;
}
Also used : LookupTableRowType(com.evolveum.midpoint.xml.ns._public.common.common_3.LookupTableRowType)

Example 12 with LookupTableRowType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.LookupTableRowType in project midpoint by Evolveum.

the class LookupTableHelper method addLookupTableRows.

private void addLookupTableRows(Session session, String tableOid, Collection<PrismContainerValue> values, int currentId, boolean deleteBeforeAdd) throws SchemaException {
    for (PrismContainerValue value : values) {
        LookupTableRowType rowType = new LookupTableRowType();
        rowType.setupContainerValue(value);
        if (deleteBeforeAdd) {
            deleteRowByKey(session, tableOid, rowType.getKey());
        }
        RLookupTableRow row = RLookupTableRow.toRepo(tableOid, rowType);
        row.setId(currentId);
        currentId++;
        session.save(row);
    }
}
Also used : RLookupTableRow(com.evolveum.midpoint.repo.sql.data.common.other.RLookupTableRow) PrismContainerValue(com.evolveum.midpoint.prism.PrismContainerValue) LookupTableRowType(com.evolveum.midpoint.xml.ns._public.common.common_3.LookupTableRowType)

Example 13 with LookupTableRowType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.LookupTableRowType in project midpoint by Evolveum.

the class LookupTableHelper method updateLoadedLookupTable.

public <T extends ObjectType> void updateLoadedLookupTable(PrismObject<T> object, Collection<SelectorOptions<GetOperationOptions>> options, Session session) throws SchemaException {
    if (!SelectorOptions.hasToLoadPath(LookupTableType.F_ROW, options)) {
        return;
    }
    LOGGER.debug("Loading lookup table data.");
    GetOperationOptions getOption = findLookupTableGetOption(options);
    RelationalValueSearchQuery queryDef = getOption == null ? null : getOption.getRelationalValueSearchQuery();
    Criteria criteria = setupLookupTableRowsQuery(session, queryDef, object.getOid());
    if (queryDef != null && queryDef.getPaging() != null) {
        ObjectPaging paging = queryDef.getPaging();
        if (paging.getOffset() != null) {
            criteria.setFirstResult(paging.getOffset());
        }
        if (paging.getMaxSize() != null) {
            criteria.setMaxResults(paging.getMaxSize());
        }
        ItemPath orderByPath = paging.getOrderBy();
        if (paging.getDirection() != null && orderByPath != null && !orderByPath.isEmpty()) {
            if (orderByPath.size() > 1 || !(orderByPath.first() instanceof NameItemPathSegment) && !(orderByPath.first() instanceof IdentifierPathSegment)) {
                throw new SchemaException("OrderBy has to consist of just one naming or identifier segment");
            }
            ItemPathSegment first = orderByPath.first();
            String orderBy = first instanceof NameItemPathSegment ? ((NameItemPathSegment) first).getName().getLocalPart() : RLookupTableRow.ID_COLUMN_NAME;
            switch(paging.getDirection()) {
                case ASCENDING:
                    criteria.addOrder(Order.asc(orderBy));
                    break;
                case DESCENDING:
                    criteria.addOrder(Order.desc(orderBy));
                    break;
            }
        }
    }
    List<RLookupTableRow> rows = criteria.list();
    if (rows == null || rows.isEmpty()) {
        return;
    }
    LookupTableType lookup = (LookupTableType) object.asObjectable();
    List<LookupTableRowType> jaxbRows = lookup.getRow();
    for (RLookupTableRow row : rows) {
        LookupTableRowType jaxbRow = row.toJAXB();
        jaxbRows.add(jaxbRow);
    }
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) RelationalValueSearchQuery(com.evolveum.midpoint.schema.RelationalValueSearchQuery) Criteria(org.hibernate.Criteria) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) RLookupTableRow(com.evolveum.midpoint.repo.sql.data.common.other.RLookupTableRow) GetOperationOptions(com.evolveum.midpoint.schema.GetOperationOptions) ObjectPaging(com.evolveum.midpoint.prism.query.ObjectPaging) LookupTableRowType(com.evolveum.midpoint.xml.ns._public.common.common_3.LookupTableRowType) LookupTableType(com.evolveum.midpoint.xml.ns._public.common.common_3.LookupTableType)

Example 14 with LookupTableRowType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.LookupTableRowType in project midpoint by Evolveum.

the class LookupTableTest method test260ReplaceRowsExistingId.

@Test
public void test260ReplaceRowsExistingId() throws Exception {
    OperationResult result = new OperationResult("test260ReplaceRowsExistingId");
    LookupTableRowType row5 = new LookupTableRowType(prismContext);
    // dangerous
    row5.setId(5L);
    row5.setKey("key 5 plus");
    row5.setValue("value 5 plus");
    row5.setLastChangeTimestamp(XmlTypeConverter.createXMLGregorianCalendar(new Date(99, 3, 10)));
    List<ItemDelta<?, ?>> modifications = DeltaBuilder.deltaFor(LookupTableType.class, prismContext).item(F_ROW).replace(row5).asItemDeltas();
    executeAndCheckModification(modifications, result, 0, null);
}
Also used : OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ItemDelta(com.evolveum.midpoint.prism.delta.ItemDelta) LookupTableRowType(com.evolveum.midpoint.xml.ns._public.common.common_3.LookupTableRowType) LookupTableType(com.evolveum.midpoint.xml.ns._public.common.common_3.LookupTableType) Test(org.testng.annotations.Test)

Example 15 with LookupTableRowType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.LookupTableRowType in project midpoint by Evolveum.

the class LookupTableTest method test228AddKeylessRow2.

@Test(expectedExceptions = SchemaException.class)
public void test228AddKeylessRow2() throws Exception {
    OperationResult result = new OperationResult("test228AddKeylessRow2");
    LookupTableRowType row = new LookupTableRowType();
    row.setValue("value");
    List<ItemDelta<?, ?>> modifications = DeltaBuilder.deltaFor(LookupTableType.class, prismContext).item(F_ROW).add(row).asItemDeltas();
    repositoryService.modifyObject(LookupTableType.class, tableOid, modifications, null, result);
}
Also used : OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ItemDelta(com.evolveum.midpoint.prism.delta.ItemDelta) LookupTableRowType(com.evolveum.midpoint.xml.ns._public.common.common_3.LookupTableRowType) LookupTableType(com.evolveum.midpoint.xml.ns._public.common.common_3.LookupTableType) Test(org.testng.annotations.Test)

Aggregations

LookupTableRowType (com.evolveum.midpoint.xml.ns._public.common.common_3.LookupTableRowType)34 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)23 LookupTableType (com.evolveum.midpoint.xml.ns._public.common.common_3.LookupTableType)23 Test (org.testng.annotations.Test)22 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)17 Task (com.evolveum.midpoint.task.api.Task)14 ItemDelta (com.evolveum.midpoint.prism.delta.ItemDelta)10 RLookupTableRow (com.evolveum.midpoint.repo.sql.data.common.other.RLookupTableRow)4 ArrayList (java.util.ArrayList)3 RelationalValueSearchQuery (com.evolveum.midpoint.schema.RelationalValueSearchQuery)2 SelectorOptions (com.evolveum.midpoint.schema.SelectorOptions)2 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)2 QName (javax.xml.namespace.QName)2 ModelExecuteOptions (com.evolveum.midpoint.model.api.ModelExecuteOptions)1 PrismContainerValue (com.evolveum.midpoint.prism.PrismContainerValue)1 PrismObject (com.evolveum.midpoint.prism.PrismObject)1 PrismProperty (com.evolveum.midpoint.prism.PrismProperty)1 ContainerDelta (com.evolveum.midpoint.prism.delta.ContainerDelta)1 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)1 ObjectPaging (com.evolveum.midpoint.prism.query.ObjectPaging)1