You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@syncope.apache.org by il...@apache.org on 2018/08/09 10:12:48 UTC
[2/3] syncope git commit: [SYNCOPE-1350] Smarter getValueAsString
[SYNCOPE-1350] Smarter getValueAsString
Project: http://git-wip-us.apache.org/repos/asf/syncope/repo
Commit: http://git-wip-us.apache.org/repos/asf/syncope/commit/4ea63a37
Tree: http://git-wip-us.apache.org/repos/asf/syncope/tree/4ea63a37
Diff: http://git-wip-us.apache.org/repos/asf/syncope/diff/4ea63a37
Branch: refs/heads/master
Commit: 4ea63a376e01ba629446bea13ff77cfb14409048
Parents: 34a2fdb
Author: Francesco Chicchiriccò <il...@apache.org>
Authored: Thu Aug 9 12:12:08 2018 +0200
Committer: Francesco Chicchiriccò <il...@apache.org>
Committed: Thu Aug 9 12:12:17 2018 +0200
----------------------------------------------------------------------
.../persistence/api/entity/PlainAttrValue.java | 2 +
.../jpa/entity/AbstractPlainAttrValue.java | 52 ++++++++++++--------
.../provisioning/java/MappingManagerImpl.java | 6 ++-
3 files changed, 38 insertions(+), 22 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/syncope/blob/4ea63a37/core/persistence-api/src/main/java/org/apache/syncope/core/persistence/api/entity/PlainAttrValue.java
----------------------------------------------------------------------
diff --git a/core/persistence-api/src/main/java/org/apache/syncope/core/persistence/api/entity/PlainAttrValue.java b/core/persistence-api/src/main/java/org/apache/syncope/core/persistence/api/entity/PlainAttrValue.java
index 87eac8f..67282ee 100644
--- a/core/persistence-api/src/main/java/org/apache/syncope/core/persistence/api/entity/PlainAttrValue.java
+++ b/core/persistence-api/src/main/java/org/apache/syncope/core/persistence/api/entity/PlainAttrValue.java
@@ -43,6 +43,8 @@ public interface PlainAttrValue extends Entity {
String getValueAsString(AttrSchemaType type);
+ String getValueAsString(PlainSchema schema);
+
void parseValue(PlainSchema schema, String value);
void setAttr(PlainAttr<?> attr);
http://git-wip-us.apache.org/repos/asf/syncope/blob/4ea63a37/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/entity/AbstractPlainAttrValue.java
----------------------------------------------------------------------
diff --git a/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/entity/AbstractPlainAttrValue.java b/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/entity/AbstractPlainAttrValue.java
index b8566a7..39e382a 100644
--- a/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/entity/AbstractPlainAttrValue.java
+++ b/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/entity/AbstractPlainAttrValue.java
@@ -209,18 +209,7 @@ public abstract class AbstractPlainAttrValue extends AbstractGeneratedKeyEntity
: getStringValue());
}
- @Override
- public String getValueAsString() {
- final AttrSchemaType type = getAttr() == null || getAttr().getSchema() == null
- || getAttr().getSchema().getType() == null
- ? AttrSchemaType.String
- : getAttr().getSchema().getType();
-
- return getValueAsString(type);
- }
-
- @Override
- public String getValueAsString(final AttrSchemaType type) {
+ private String getValueAsString(final AttrSchemaType type, final PlainSchema schema) {
String result;
switch (type) {
@@ -229,24 +218,21 @@ public abstract class AbstractPlainAttrValue extends AbstractGeneratedKeyEntity
break;
case Long:
- result = getAttr() == null || getAttr().getSchema() == null
- || getAttr().getSchema().getConversionPattern() == null
+ result = schema == null || schema.getConversionPattern() == null
? getLongValue().toString()
- : FormatUtils.format(getLongValue(), getAttr().getSchema().getConversionPattern());
+ : FormatUtils.format(getLongValue(), schema.getConversionPattern());
break;
case Double:
- result = getAttr() == null || getAttr().getSchema() == null
- || getAttr().getSchema().getConversionPattern() == null
+ result = schema == null || schema.getConversionPattern() == null
? getDoubleValue().toString()
- : FormatUtils.format(getDoubleValue(), getAttr().getSchema().getConversionPattern());
+ : FormatUtils.format(getDoubleValue(), schema.getConversionPattern());
break;
case Date:
- result = getAttr() == null || getAttr().getSchema() == null
- || getAttr().getSchema().getConversionPattern() == null
+ result = schema == null || schema.getConversionPattern() == null
? FormatUtils.format(getDateValue())
- : FormatUtils.format(getDateValue(), false, getAttr().getSchema().getConversionPattern());
+ : FormatUtils.format(getDateValue(), false, schema.getConversionPattern());
break;
case Binary:
@@ -265,6 +251,30 @@ public abstract class AbstractPlainAttrValue extends AbstractGeneratedKeyEntity
}
@Override
+ public String getValueAsString() {
+ PlainSchema schema = getAttr() == null || getAttr().getSchema() == null
+ ? null
+ : getAttr().getSchema();
+ AttrSchemaType type = schema == null || schema.getType() == null
+ ? AttrSchemaType.String
+ : getAttr().getSchema().getType();
+
+ return getValueAsString(type, schema);
+ }
+
+ @Override
+ public String getValueAsString(final AttrSchemaType type) {
+ return getValueAsString(
+ type,
+ getAttr() == null || getAttr().getSchema() == null ? null : getAttr().getSchema());
+ }
+
+ @Override
+ public String getValueAsString(final PlainSchema schema) {
+ return getValueAsString(schema.getType(), schema);
+ }
+
+ @Override
public String toString() {
return ReflectionToStringBuilder.toString(this, ToStringStyle.JSON_STYLE);
}
http://git-wip-us.apache.org/repos/asf/syncope/blob/4ea63a37/core/provisioning-java/src/main/java/org/apache/syncope/core/provisioning/java/MappingManagerImpl.java
----------------------------------------------------------------------
diff --git a/core/provisioning-java/src/main/java/org/apache/syncope/core/provisioning/java/MappingManagerImpl.java b/core/provisioning-java/src/main/java/org/apache/syncope/core/provisioning/java/MappingManagerImpl.java
index 5f3fcc1..fc4ac8b 100644
--- a/core/provisioning-java/src/main/java/org/apache/syncope/core/provisioning/java/MappingManagerImpl.java
+++ b/core/provisioning-java/src/main/java/org/apache/syncope/core/provisioning/java/MappingManagerImpl.java
@@ -361,7 +361,11 @@ public class MappingManagerImpl implements MappingManager {
if (FrameworkUtil.isSupportedAttributeType(schemaType.getType())) {
objValues.add(value.getValue());
} else {
- objValues.add(value.getValueAsString(schemaType));
+ if (schema instanceof PlainSchema) {
+ objValues.add(value.getValueAsString((PlainSchema) schema));
+ } else {
+ objValues.add(value.getValueAsString(schemaType));
+ }
}
}