Skip to content
This repository has been archived by the owner on Oct 12, 2021. It is now read-only.

Commit

Permalink
Issue 17: Fix datatype of ShaclIn
Browse files Browse the repository at this point in the history
Changed datatype of ShaclIn to String array. In addition to this fixed
more minor bugs.

Change-Id: I8713c5e97f104df38961eec83c4d6b488116f8c8
Signed-off-by: Yash Khatri <yash.khatri@scania.com>
  • Loading branch information
yashkhatri committed Oct 11, 2018
1 parent 1ad9e3f commit 0024147
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 247 deletions.
129 changes: 0 additions & 129 deletions src/main/java/org/eclipse/lyo/validation/constants/DataType.java

This file was deleted.

17 changes: 10 additions & 7 deletions src/main/java/org/eclipse/lyo/validation/shacl/Property.java
Expand Up @@ -37,7 +37,6 @@
import org.eclipse.lyo.oslc4j.core.model.Occurs;
import org.eclipse.lyo.oslc4j.core.model.OslcConstants;
import org.eclipse.lyo.oslc4j.core.model.ValueType;
import org.eclipse.lyo.validation.constants.DataType;

/**
* @author Yash Khatri
Expand All @@ -54,7 +53,7 @@ public class Property extends AbstractResource {

//Value Type Constraints
private URI classType;
private DataType dataType;
private ValueType dataType;
private URI nodeKind;

//Cardinality Constraints
Expand All @@ -75,7 +74,7 @@ public class Property extends AbstractResource {
private Boolean uniqueLang;

//Values Based Constraints
private Object[] in;
private String[] in;

//Non Validating Property Shape Characteristics.
private String name;
Expand All @@ -102,7 +101,7 @@ public Property() {
super();
}

public Property(final URI path, final DataType dataType, final BigInteger minCount,
public Property(final URI path, final ValueType dataType, final BigInteger minCount,
final BigInteger maxCount) {
this();

Expand Down Expand Up @@ -199,8 +198,12 @@ public URI getDataType() {
return null;
}

public void setDataType(DataType dataType) {
this.dataType = dataType;
public void setDataType(URI dataType) {
if (dataType != null) {
this.dataType = ValueType.fromString(dataType.toString());
} else {
this.dataType = null;
}
}

@OslcDescription("Specifies the description")
Expand Down Expand Up @@ -428,7 +431,7 @@ public Object[] getIn() {
return in;
}

public void setIn(Object[] in) {
public void setIn(String[] in) {
this.in = in;
}

Expand Down
115 changes: 13 additions & 102 deletions src/main/java/org/eclipse/lyo/validation/shacl/ShaclShapeFactory.java
Expand Up @@ -52,7 +52,6 @@
import org.eclipse.lyo.oslc4j.core.model.Occurs;
import org.eclipse.lyo.oslc4j.core.model.ResourceShapeFactory;
import org.eclipse.lyo.oslc4j.core.model.ValueType;
import org.eclipse.lyo.validation.constants.DataType;
import org.eclipse.lyo.validation.shacl.annotations.RDFType;
import org.eclipse.lyo.validation.shacl.annotations.RdfsIsDefinedBy;
import org.eclipse.lyo.validation.shacl.annotations.RdfsLabel;
Expand Down Expand Up @@ -407,77 +406,19 @@ private static Property createPropertiesFromOslcAnnotations(Class<?> resourceCla
if (valueTypeAnnotation != null) {
valueType = valueTypeAnnotation.value();
validateUserSpecifiedValueType(resourceClass, method, valueType, componentType);
property.setDataType(DataType.fromString(valueType.toString()));
property.setDataType(new URI(valueType.toString()));

final OslcAllowedValue oslcAllowedValue = InheritedMethodAnnotationHelper.getAnnotation(
method, OslcAllowedValue.class);
if (oslcAllowedValue != null) {

DateFormat df = new SimpleDateFormat("MM/dd/yyyy");
SimpleDateFormat formatter = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss");
DecimalFormat decimalFormat = new DecimalFormat("0.00");
decimalFormat.setMaximumFractionDigits(2);

Object[] object = new Object[oslcAllowedValue.value().length];

for (int i = 0; i < oslcAllowedValue.value().length; i++) {
if (valueType.equals(ValueType.Boolean)) {
object[i] = Boolean.parseBoolean(oslcAllowedValue.value()[i]);
} else if (valueType.equals(ValueType.Date)) {
object[i] = df.parse(oslcAllowedValue.value()[i]);
} else if (valueType.equals(ValueType.DateTime)) {
object[i] = formatter.parse(oslcAllowedValue.value()[i]);
} else if (valueType.equals(ValueType.Decimal)) {
object[i] = Float.parseFloat(df.format(oslcAllowedValue.value()[i]));
} else if (valueType.equals(ValueType.Double)) {
object[i] = Double.parseDouble(oslcAllowedValue.value()[i]);
} else if (valueType.equals(ValueType.Float)) {
object[i] = Float.parseFloat(oslcAllowedValue.value()[i]);
} else if (valueType.equals(ValueType.Integer)) {
object[i] = Integer.parseInt(oslcAllowedValue.value()[i]);
} else if (valueType.equals(ValueType.String)) {
object[i] = oslcAllowedValue.value()[i];
} else {
object[i] = oslcAllowedValue.value()[i];
}
}

property.setIn(object);
property.setIn(oslcAllowedValue.value());
}

final OslcAllowedValues oslcAllowedValues = InheritedMethodAnnotationHelper
.getAnnotation(
method, OslcAllowedValues.class);
if (oslcAllowedValues != null) {

DateFormat df = new SimpleDateFormat("MM/dd/yyyy");
SimpleDateFormat formatter = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss");
DecimalFormat decimalFormat = new DecimalFormat("0.00");
decimalFormat.setMaximumFractionDigits(2);

Object object = new Object();

if (valueType.equals(ValueType.Boolean)) {
object = Boolean.parseBoolean(oslcAllowedValues.value());
} else if (valueType.equals(ValueType.Date)) {
object = df.parse(oslcAllowedValues.value());
} else if (valueType.equals(ValueType.DateTime)) {
object = formatter.parse(oslcAllowedValues.value());
} else if (valueType.equals(ValueType.Decimal)) {
object = Float.parseFloat(df.format(oslcAllowedValues.value()));
} else if (valueType.equals(ValueType.Double)) {
object = Double.parseDouble(oslcAllowedValues.value());
} else if (valueType.equals(ValueType.Float)) {
object = Float.parseFloat(oslcAllowedValues.value());
} else if (valueType.equals(ValueType.Integer)) {
object = Integer.parseInt(oslcAllowedValues.value());
} else if (valueType.equals(ValueType.String)) {
object = oslcAllowedValues.value();
} else {
object = oslcAllowedValues.value();
}

property.addIn(object);
property.addIn(oslcAllowedValues);
}

}
Expand Down Expand Up @@ -557,49 +498,19 @@ private static Property createPropertiesFromShaclAnnotations(final Class<?> reso
property.setPath(new URI(propertyDefinitionAnnotation.value()));

//Setting Value Type
DataType dataType = null;
ValueType dataType = null;
final ShaclDataType dataTypeAnnotation = InheritedMethodAnnotationHelper.getAnnotation(
method, ShaclDataType.class);
if (dataTypeAnnotation != null) {
dataType = dataTypeAnnotation.value();
property.setDataType(dataType);
shaclShape.setReadShaclAnnotations(true);

//Other Constraint Components
final ShaclIn inAnnotation = InheritedMethodAnnotationHelper.getAnnotation(method,
ShaclIn.class);
if (inAnnotation != null) {

DateFormat df = new SimpleDateFormat("MM/dd/yyyy");
SimpleDateFormat formatter = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss");
DecimalFormat decimalFormat = new DecimalFormat("0.00");
decimalFormat.setMaximumFractionDigits(2);

Object[] object = new Object[inAnnotation.value().length];
for (int i = 0; i < inAnnotation.value().length; i++) {
if (dataType == DataType.Integer) {
object[i] = new BigInteger(inAnnotation.value()[i]);
} else if (dataType == DataType.String) {
object[i] = inAnnotation.value()[i];
} else if (dataType == DataType.URI) {
object[i] = new URI(inAnnotation.value()[i]);
} else if (dataType == DataType.Boolean) {
object[i] = Boolean.parseBoolean(inAnnotation.value()[i]);
} else if (dataType == DataType.Date) {
object[i] = df.parse(inAnnotation.value()[i]);
} else if (dataType == DataType.DateTime) {
object[i] = formatter.parse(inAnnotation.value().toString());
} else if (dataType == DataType.Double) {
object[i] = Double.parseDouble(inAnnotation.value()[i]);
} else if (dataType == DataType.Float) {
object[i] = Float.parseFloat(inAnnotation.value()[i]);
} else if (dataType == DataType.Decimal) {
object[i] = Float.parseFloat(inAnnotation.value()[i]);
}
}
property.setIn(object);
shaclShape.setReadShaclAnnotations(true);
}
property.setDataType(new URI(dataType.toString()));
shaclShape.setReadShaclAnnotations(true);
}
// Other Constraint Components
final ShaclIn inAnnotation = InheritedMethodAnnotationHelper.getAnnotation(method, ShaclIn.class);
if (inAnnotation != null) {
property.setIn(inAnnotation.value());
shaclShape.setReadShaclAnnotations(true);
}

final ShaclDescription shaclDescription = InheritedMethodAnnotationHelper.getAnnotation(
Expand All @@ -611,7 +522,7 @@ private static Property createPropertiesFromShaclAnnotations(final Class<?> reso
final ShaclDataType dataTypeAnotation = InheritedMethodAnnotationHelper.getAnnotation(
method, ShaclDataType.class);
if (dataTypeAnotation != null) {
property.setDataType(dataTypeAnotation.value());
property.setDataType(new URI(dataTypeAnotation.value().toString()));
shaclShape.setReadShaclAnnotations(true);
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/eclipse/lyo/validation/shacl/Shape.java
Expand Up @@ -139,7 +139,7 @@ public List<Property> getShaclProperties() {
properties.values().toArray(new Property[properties.size()]));
}

public void setShaclProperties(final Property[] properties) {
public void setShaclProperties(final List<Property> properties) {
this.properties.clear();
if (properties != null) {
for (Property prop : properties) {
Expand Down
Expand Up @@ -21,7 +21,8 @@
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import org.eclipse.lyo.validation.constants.DataType;

import org.eclipse.lyo.oslc4j.core.model.ValueType;

/**
* @author Yash Khatri
Expand All @@ -33,6 +34,6 @@
@Target(ElementType.METHOD)
public @interface ShaclDataType {

DataType value();
ValueType value();

}

0 comments on commit 0024147

Please sign in to comment.