Skip to content

Commit

Permalink
add/get for lookuptable works.
Browse files Browse the repository at this point in the history
  • Loading branch information
1azyman committed Mar 11, 2015
1 parent 8fc5fc2 commit 631a8dd
Show file tree
Hide file tree
Showing 8 changed files with 125 additions and 113 deletions.
50 changes: 23 additions & 27 deletions repo/repo-sql-impl-test/src/test/resources/basic/objects.xml
Expand Up @@ -1293,37 +1293,33 @@

</objectTemplate>

<!--
<lookupTable xmlns="http://midpoint.evolveum.com/xml/ns/public/common/common-3"
xmlns:t="http://prism.evolveum.com/xml/ns/public/types-3">
<name>first lookup</name>
<description>description of lookuptable</description>
<table>
<row>
<key>first key</key>
<label>first label</label>
<lastChangeTimestamp>2013-05-07T10:38:21.350+02:00</lastChangeTimestamp>
<value>first value</value>
</row>
<row>
<key>2 key</key>
<label>
<t:orig>2 label</t:orig>
<t:norm>2 label</t:norm>
</label>
<lastChangeTimestamp>2013-05-07T10:38:21.350+02:00</lastChangeTimestamp>
<value>2 value</value>
</row>
<row>
<key>3 key</key>
<label>
<t:orig>3 label</t:orig>
<t:norm>3 label</t:norm>
</label>
<lastChangeTimestamp>2013-05-07T10:38:21.350+02:00</lastChangeTimestamp>
<value>3 value</value>
</row>
<table id="1">
<key>first key</key>
<label>first label</label>
<lastChangeTimestamp>2013-05-07T10:38:21.350+02:00</lastChangeTimestamp>
<value>first value</value>
</table>
<table id="2">
<key>2 key</key>
<label>
<t:orig>2 label</t:orig>
<t:norm>2 label</t:norm>
</label>
<lastChangeTimestamp>2013-05-07T10:38:21.350+02:00</lastChangeTimestamp>
<value>2 value</value>
</table>
<table id="3">
<key>3 key</key>
<label>
<t:orig>3 label</t:orig>
<t:norm>3 label</t:norm>
</label>
<lastChangeTimestamp>2013-05-07T10:38:21.350+02:00</lastChangeTimestamp>
<value>3 value</value>
</table>
</lookupTable>
-->
</objects>
Expand Up @@ -31,6 +31,7 @@
import com.evolveum.midpoint.repo.sql.data.common.*;
import com.evolveum.midpoint.repo.sql.data.common.any.RAnyValue;
import com.evolveum.midpoint.repo.sql.data.common.any.RValueType;
import com.evolveum.midpoint.repo.sql.data.common.other.RLookupTableRow;
import com.evolveum.midpoint.repo.sql.data.common.type.RObjectExtensionType;
import com.evolveum.midpoint.repo.sql.query.QueryEngine;
import com.evolveum.midpoint.repo.sql.query.QueryException;
Expand Down Expand Up @@ -578,6 +579,9 @@ private <T extends ObjectType> void updateFullObject(RObject object, PrismObject

if (UserType.class.equals(savedObject.getCompileTimeClass())) {
savedObject.removeProperty(UserType.F_JPEG_PHOTO);
} else if (LookupTableType.class.equals(savedObject.getCompileTimeClass())) {
PrismContainer table = savedObject.findContainer(LookupTableType.F_TABLE);
savedObject.remove(table);
}

String xml = getPrismContext().serializeObjectToString(savedObject, PrismContext.LANG_XML);
Expand Down Expand Up @@ -914,13 +918,39 @@ private <T extends ObjectType> PrismObject<T> updateLoadedObject(GetObjectResult
applyShadowAttributeDefinitions(classes[i], prismObject, session);
}
LOGGER.debug("Definitions for attributes loaded. Counts: {}", Arrays.toString(counts));
} else if (LookupTableType.class.equals(prismObject.getCompileTimeClass())) {
updateLoadedLookupTable(prismObject, options, session);
}

validateObjectType(prismObject, type);

return prismObject;
}

private <T extends ObjectType> void updateLoadedLookupTable(PrismObject<T> object,
Collection<SelectorOptions<GetOperationOptions>> options,
Session session) {
if (!SelectorOptions.hasToLoadPath(LookupTableType.F_TABLE, options)) {
return;
}

LOGGER.debug("Loading lookup table data.");
Query query = session.getNamedQuery("get.lookupTableData");
query.setString("oid", object.getOid());
List<RLookupTableRow> rows = query.list();

if (rows == null || rows.isEmpty()) {
return;
}

LookupTableType lookup = (LookupTableType) object.asObjectable();
List<LookupTableTableType> jaxbRows = lookup.getTable();
for (RLookupTableRow row : rows) {
LookupTableTableType jaxbRow = row.toJAXB();
jaxbRows.add(jaxbRow);
}
}

private void applyShadowAttributeDefinitions(Class<? extends RAnyValue> anyValueType,
PrismObject object, Session session) throws SchemaException {

Expand Down
Expand Up @@ -10,13 +10,13 @@
import com.evolveum.midpoint.schema.SelectorOptions;
import com.evolveum.midpoint.xml.ns._public.common.common_3.LookupTableTableType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.LookupTableType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType;
import org.hibernate.annotations.Cascade;
import org.hibernate.annotations.ForeignKey;

import javax.persistence.*;
import java.util.Collection;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

/**
Expand Down Expand Up @@ -60,34 +60,17 @@ public static void copyFromJAXB(LookupTableType jaxb, RLookupTable repo, PrismCo

repo.setName(RPolyString.copyFromJAXB(jaxb.getName()));

// LookupTableTableType table = jaxb.getTable();
// if (table == null) {
// return;
// }
//
// for (LookupTableRowType row : table.getRow()) {
// RLookupTableRow rRow = new RLookupTableRow();
// rRow.setOwner(repo);
// rRow.setKey(row.getKey());
// rRow.setLabel(RPolyString.copyFromJAXB(row.getLabel()));
// rRow.setLastChangeTimestamp(row.getLastChangeTimestamp());
// rRow.setValue(row.getValue());
//
// repo.getRows().add(rRow);
// }
}

protected static <T extends ObjectType> void copyToJAXB(RLookupTable repo, LookupTableType jaxb, PrismContext prismContext,
Collection<SelectorOptions<GetOperationOptions>> options)
throws DtoTranslationException {

//todo wtf with this

RObject.copyToJAXB(repo, jaxb, prismContext, options);

if (repo.getRows() != null && !repo.getRows().isEmpty()) {


List<LookupTableTableType> rows = jaxb.getTable();
for (LookupTableTableType row : rows) {
RLookupTableRow rRow = new RLookupTableRow();
rRow.setOwner(repo);
rRow.setId(RUtil.toShort(row.getId()));
rRow.setKey(row.getKey());
rRow.setLabel(RPolyString.copyFromJAXB(row.getLabel()));
rRow.setLastChangeTimestamp(row.getLastChangeTimestamp());
rRow.setValue(row.getValue());

repo.getRows().add(rRow);
}
}

Expand Down
Expand Up @@ -70,6 +70,7 @@
@NamedQuery(name = "getDefinition.ROExtReference", query = "select c.name, c.type, c.valueType from ROExtReference as c where c.ownerOid = :oid and c.ownerType = :ownerType"),
@NamedQuery(name = "isAnySubordinateAttempt.oneLowerOid", query = "select count(*) from ROrgClosure o where o.ancestorOid=:aOid and o.descendantOid=:dOid"),
@NamedQuery(name = "isAnySubordinateAttempt.moreLowerOids", query = "select count(*) from ROrgClosure o where o.ancestorOid=:aOid and o.descendantOid in (:dOids)"),
@NamedQuery(name = "get.lookupTableData", query = "select r from RLookupTableRow r where r.ownerOid = :oid"),
})
@Entity
@Table(name = "m_object", indexes = {
Expand Down
Expand Up @@ -24,15 +24,15 @@
/**
* @author lazyman
*/
public interface Container extends EntityState, Serializable {
public interface Container<T extends RObject> extends EntityState, Serializable {

RObject getOwner();
T getOwner();

String getOwnerOid();

Short getId();

void setOwner(RObject owner);
void setOwner(T owner);

void setOwnerOid(String ownerOid);

Expand Down

This file was deleted.

@@ -1,11 +1,15 @@
package com.evolveum.midpoint.repo.sql.data.common.other;

import com.evolveum.midpoint.repo.sql.data.common.RLookupTable;
import com.evolveum.midpoint.repo.sql.data.common.RObject;
import com.evolveum.midpoint.repo.sql.data.common.RUser;
import com.evolveum.midpoint.repo.sql.data.common.container.Container;
import com.evolveum.midpoint.repo.sql.data.common.embedded.RPolyString;
import com.evolveum.midpoint.repo.sql.data.common.id.RLookupTableRowId;
import com.evolveum.midpoint.repo.sql.data.common.id.RContainerId;
import com.evolveum.midpoint.repo.sql.util.RUtil;
import com.evolveum.midpoint.xml.ns._public.common.common_3.LookupTableTableType;
import org.hibernate.annotations.ForeignKey;
import org.hibernate.annotations.GenericGenerator;

import javax.persistence.*;
import javax.xml.datatype.XMLGregorianCalendar;
Expand All @@ -21,11 +25,15 @@
// @Index(name = "i_row_label_orig", columnList = "label.orig"),
// @Index(name = "i_row_label_norm", columnList = "label.norm")
})
@IdClass(RLookupTableRowId.class)
public class RLookupTableRow {
@IdClass(RContainerId.class)
public class RLookupTableRow implements Container<RLookupTable> {

//todo move to super class Container (change container to abstract class)
private Boolean trans;

private RLookupTable owner;
private String ownerOid;
private Short id;

private String key;
private String value;
Expand All @@ -36,19 +44,27 @@ public class RLookupTableRow {
@ForeignKey(name = "fk_lookup_table_owner")
@MapsId("owner")
@ManyToOne(fetch = FetchType.LAZY)
@Override
public RLookupTable getOwner() {
return owner;
}

@Id
@Column(name = "owner_oid", length = RUtil.COLUMN_LENGTH_OID)
@Column(name = "owner_oid", length = RUtil.COLUMN_LENGTH_OID, nullable = false)
public String getOwnerOid() {
if (ownerOid == null && owner != null) {
if (owner != null && ownerOid == null) {
ownerOid = owner.getOid();
}
return ownerOid;
}

@Id
@GeneratedValue(generator = "ContainerIdGenerator")
@GenericGenerator(name = "ContainerIdGenerator", strategy = "com.evolveum.midpoint.repo.sql.util.ContainerIdGenerator")
@Column(name = "id")
public Short getId() {
return id;
}

@Id
@Column(name = "row_key")
public String getKey() {
Expand Down Expand Up @@ -80,18 +96,36 @@ public String getValue() {
return value;
}

@Transient
@Override
public Boolean isTransient() {
return trans;
}

public void setValue(String value) {
this.value = value;
}

@Override
public void setOwner(RLookupTable owner) {
this.owner = owner;
}

@Override
public void setOwnerOid(String ownerOid) {
this.ownerOid = ownerOid;
}

@Override
public void setId(Short id) {
this.id = id;
}

@Override
public void setTransient(Boolean trans) {
this.trans = trans;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
Expand All @@ -116,4 +150,15 @@ public int hashCode() {
result = 31 * result + (lastChangeTimestamp != null ? lastChangeTimestamp.hashCode() : 0);
return result;
}

public LookupTableTableType toJAXB() {
LookupTableTableType row = new LookupTableTableType();
row.setId(Long.valueOf(id));
row.setKey(key);
row.setLastChangeTimestamp(lastChangeTimestamp);
row.setValue(value);
row.setLabel(RPolyString.copyToJAXB(label));

return row;
}
}
Expand Up @@ -5,6 +5,7 @@
import com.evolveum.midpoint.prism.PrismObject;
import com.evolveum.midpoint.xml.ns._public.common.common_3.AbstractRoleType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.FocusType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.LookupTableType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType;
import org.apache.cxf.common.util.StringUtils;

Expand Down Expand Up @@ -95,6 +96,10 @@ private List<PrismContainer> getChildrenContainers(PrismObject parent) {
containers.add(parent.findContainer(ObjectType.F_TRIGGER));
}

if (LookupTableType.class.isAssignableFrom(parent.getCompileTimeClass())) {
containers.add(parent.findContainer(LookupTableType.F_TABLE));
}

if (FocusType.class.isAssignableFrom(parent.getCompileTimeClass())) {
containers.add(parent.findContainer(FocusType.F_ASSIGNMENT));
}
Expand Down

0 comments on commit 631a8dd

Please sign in to comment.