[OLINGO-784] Prevent NPE in combination with typeinfo objects
This commit is contained in:
parent
46cad03fed
commit
17e4a3aeff
|
@ -6,9 +6,9 @@
|
||||||
* to you under the Apache License, Version 2.0 (the
|
* to you under the Apache License, Version 2.0 (the
|
||||||
* "License"); you may not use this file except in compliance
|
* "License"); you may not use this file except in compliance
|
||||||
* with the License. You may obtain a copy of the License at
|
* with the License. You may obtain a copy of the License at
|
||||||
*
|
*
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
*
|
*
|
||||||
* Unless required by applicable law or agreed to in writing,
|
* Unless required by applicable law or agreed to in writing,
|
||||||
* software distributed under the License is distributed on an
|
* software distributed under the License is distributed on an
|
||||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
@ -33,7 +33,7 @@ public class CsdlParameter extends CsdlAbstractEdmItem implements CsdlNamed, Csd
|
||||||
|
|
||||||
private String name;
|
private String name;
|
||||||
|
|
||||||
private FullQualifiedName type;
|
private String type;
|
||||||
|
|
||||||
private boolean isCollection;
|
private boolean isCollection;
|
||||||
|
|
||||||
|
@ -74,7 +74,7 @@ public class CsdlParameter extends CsdlAbstractEdmItem implements CsdlNamed, Csd
|
||||||
* @return the type
|
* @return the type
|
||||||
*/
|
*/
|
||||||
public String getType() {
|
public String getType() {
|
||||||
return type.getFullQualifiedNameAsString();
|
return type;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -83,7 +83,7 @@ public class CsdlParameter extends CsdlAbstractEdmItem implements CsdlNamed, Csd
|
||||||
* @return the type fQN
|
* @return the type fQN
|
||||||
*/
|
*/
|
||||||
public FullQualifiedName getTypeFQN() {
|
public FullQualifiedName getTypeFQN() {
|
||||||
return type;
|
return new FullQualifiedName(type);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -93,7 +93,7 @@ public class CsdlParameter extends CsdlAbstractEdmItem implements CsdlNamed, Csd
|
||||||
* @return the type
|
* @return the type
|
||||||
*/
|
*/
|
||||||
public CsdlParameter setType(final String type) {
|
public CsdlParameter setType(final String type) {
|
||||||
this.type = new FullQualifiedName(type);
|
this.type = type;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -104,7 +104,7 @@ public class CsdlParameter extends CsdlAbstractEdmItem implements CsdlNamed, Csd
|
||||||
* @return the type
|
* @return the type
|
||||||
*/
|
*/
|
||||||
public CsdlParameter setType(final FullQualifiedName type) {
|
public CsdlParameter setType(final FullQualifiedName type) {
|
||||||
this.type = type;
|
this.type = type.getFullQualifiedNameAsString();
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -232,7 +232,7 @@ public class CsdlParameter extends CsdlAbstractEdmItem implements CsdlNamed, Csd
|
||||||
public List<CsdlAnnotation> getAnnotations() {
|
public List<CsdlAnnotation> getAnnotations() {
|
||||||
return annotations;
|
return annotations;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets a list of annotations
|
* Sets a list of annotations
|
||||||
* @param annotations list of annotations
|
* @param annotations list of annotations
|
||||||
|
|
|
@ -28,7 +28,7 @@ public class CsdlReturnType extends CsdlAbstractEdmItem {
|
||||||
|
|
||||||
private static final long serialVersionUID = 4816954124986010965L;
|
private static final long serialVersionUID = 4816954124986010965L;
|
||||||
|
|
||||||
private FullQualifiedName type;
|
private String type;
|
||||||
|
|
||||||
private boolean isCollection;
|
private boolean isCollection;
|
||||||
|
|
||||||
|
@ -49,7 +49,7 @@ public class CsdlReturnType extends CsdlAbstractEdmItem {
|
||||||
* @return the type
|
* @return the type
|
||||||
*/
|
*/
|
||||||
public String getType() {
|
public String getType() {
|
||||||
return type.getFullQualifiedNameAsString();
|
return type;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -58,7 +58,7 @@ public class CsdlReturnType extends CsdlAbstractEdmItem {
|
||||||
* @return the type fQN
|
* @return the type fQN
|
||||||
*/
|
*/
|
||||||
public FullQualifiedName getTypeFQN() {
|
public FullQualifiedName getTypeFQN() {
|
||||||
return type;
|
return new FullQualifiedName(type);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -68,7 +68,7 @@ public class CsdlReturnType extends CsdlAbstractEdmItem {
|
||||||
* @return the type
|
* @return the type
|
||||||
*/
|
*/
|
||||||
public CsdlReturnType setType(final String type) {
|
public CsdlReturnType setType(final String type) {
|
||||||
this.type = new FullQualifiedName(type);
|
this.type = type;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -79,7 +79,7 @@ public class CsdlReturnType extends CsdlAbstractEdmItem {
|
||||||
* @return the type
|
* @return the type
|
||||||
*/
|
*/
|
||||||
public CsdlReturnType setType(final FullQualifiedName type) {
|
public CsdlReturnType setType(final FullQualifiedName type) {
|
||||||
this.type = type;
|
this.type = type.getFullQualifiedNameAsString();
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -40,7 +40,6 @@ import org.apache.olingo.commons.api.edm.FullQualifiedName;
|
||||||
public abstract class AbstractEdm implements Edm {
|
public abstract class AbstractEdm implements Edm {
|
||||||
|
|
||||||
protected Map<String, EdmSchema> schemas;
|
protected Map<String, EdmSchema> schemas;
|
||||||
|
|
||||||
protected List<EdmSchema> schemaList;
|
protected List<EdmSchema> schemaList;
|
||||||
|
|
||||||
private final Map<FullQualifiedName, EdmEntityContainer> entityContainers =
|
private final Map<FullQualifiedName, EdmEntityContainer> entityContainers =
|
||||||
|
@ -79,8 +78,7 @@ public abstract class AbstractEdm implements Edm {
|
||||||
private final Map<TargetQualifierMapKey, EdmAnnotations> annotationGroups =
|
private final Map<TargetQualifierMapKey, EdmAnnotations> annotationGroups =
|
||||||
Collections.synchronizedMap(new HashMap<TargetQualifierMapKey, EdmAnnotations>());
|
Collections.synchronizedMap(new HashMap<TargetQualifierMapKey, EdmAnnotations>());
|
||||||
|
|
||||||
private Map<String, String> aliasToNamespaceInfo = Collections.synchronizedMap(new HashMap<String, String>());
|
private Map<String, String> aliasToNamespaceInfo = null;
|
||||||
private boolean aliasToNamespaceInfoCreated = false;
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<EdmSchema> getSchemas() {
|
public List<EdmSchema> getSchemas() {
|
||||||
|
@ -98,18 +96,15 @@ public abstract class AbstractEdm implements Edm {
|
||||||
|
|
||||||
EdmSchema schema = schemas.get(namespace);
|
EdmSchema schema = schemas.get(namespace);
|
||||||
if (schema == null) {
|
if (schema == null) {
|
||||||
if (!aliasToNamespaceInfoCreated) {
|
|
||||||
aliasToNamespaceInfo = createAliasToNamespaceInfo();
|
|
||||||
}
|
|
||||||
schema = schemas.get(aliasToNamespaceInfo.get(namespace));
|
schema = schemas.get(aliasToNamespaceInfo.get(namespace));
|
||||||
}
|
}
|
||||||
|
|
||||||
return schema;
|
return schema;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initSchemas() {
|
private void initSchemas() {
|
||||||
schemas = createSchemas();
|
loadAliasToNamespaceInfo();
|
||||||
aliasToNamespaceInfoCreated = true;
|
Map<String, EdmSchema> localSchemas = createSchemas();
|
||||||
|
schemas = Collections.synchronizedMap(localSchemas);
|
||||||
|
|
||||||
if (schemas == null) {
|
if (schemas == null) {
|
||||||
schemas = Collections.emptyMap();
|
schemas = Collections.emptyMap();
|
||||||
|
@ -117,6 +112,11 @@ public abstract class AbstractEdm implements Edm {
|
||||||
schemaList = Collections.unmodifiableList(new ArrayList<EdmSchema>(schemas.values()));
|
schemaList = Collections.unmodifiableList(new ArrayList<EdmSchema>(schemas.values()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void loadAliasToNamespaceInfo() {
|
||||||
|
Map<String, String> localAliasToNamespaceInfo = createAliasToNamespaceInfo();
|
||||||
|
aliasToNamespaceInfo = Collections.synchronizedMap(localAliasToNamespaceInfo);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public EdmEntityContainer getEntityContainer() {
|
public EdmEntityContainer getEntityContainer() {
|
||||||
return getEntityContainer(null);
|
return getEntityContainer(null);
|
||||||
|
@ -311,8 +311,8 @@ public abstract class AbstractEdm implements Edm {
|
||||||
}
|
}
|
||||||
|
|
||||||
private FullQualifiedName resolvePossibleAlias(final FullQualifiedName namespaceOrAliasFQN) {
|
private FullQualifiedName resolvePossibleAlias(final FullQualifiedName namespaceOrAliasFQN) {
|
||||||
if (!aliasToNamespaceInfoCreated) {
|
if (aliasToNamespaceInfo == null) {
|
||||||
aliasToNamespaceInfo = createAliasToNamespaceInfo();
|
loadAliasToNamespaceInfo();
|
||||||
}
|
}
|
||||||
FullQualifiedName finalFQN = null;
|
FullQualifiedName finalFQN = null;
|
||||||
if (namespaceOrAliasFQN != null) {
|
if (namespaceOrAliasFQN != null) {
|
||||||
|
|
|
@ -6,9 +6,9 @@
|
||||||
* to you under the Apache License, Version 2.0 (the
|
* to you under the Apache License, Version 2.0 (the
|
||||||
* "License"); you may not use this file except in compliance
|
* "License"); you may not use this file except in compliance
|
||||||
* with the License. You may obtain a copy of the License at
|
* with the License. You may obtain a copy of the License at
|
||||||
*
|
*
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
*
|
*
|
||||||
* Unless required by applicable law or agreed to in writing,
|
* Unless required by applicable law or agreed to in writing,
|
||||||
* software distributed under the License is distributed on an
|
* software distributed under the License is distributed on an
|
||||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
@ -30,13 +30,11 @@ import org.apache.olingo.commons.api.edm.provider.CsdlParameter;
|
||||||
public class EdmParameterImpl extends AbstractEdmNamed implements EdmParameter, EdmElement {
|
public class EdmParameterImpl extends AbstractEdmNamed implements EdmParameter, EdmElement {
|
||||||
|
|
||||||
private final CsdlParameter parameter;
|
private final CsdlParameter parameter;
|
||||||
private final EdmTypeInfo typeInfo;
|
|
||||||
private EdmType typeImpl;
|
private EdmType typeImpl;
|
||||||
|
|
||||||
public EdmParameterImpl(final Edm edm, final CsdlParameter parameter) {
|
public EdmParameterImpl(final Edm edm, final CsdlParameter parameter) {
|
||||||
super(edm, parameter.getName(), parameter);
|
super(edm, parameter.getName(), parameter);
|
||||||
this.parameter = parameter;
|
this.parameter = parameter;
|
||||||
typeInfo = new EdmTypeInfo.Builder().setEdm(edm).setTypeExpression(parameter.getType()).build();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -77,9 +75,12 @@ public class EdmParameterImpl extends AbstractEdmNamed implements EdmParameter,
|
||||||
@Override
|
@Override
|
||||||
public EdmType getType() {
|
public EdmType getType() {
|
||||||
if (typeImpl == null) {
|
if (typeImpl == null) {
|
||||||
typeImpl = typeInfo.getType();
|
if (parameter.getType() == null) {
|
||||||
|
throw new EdmException("Parameter " + parameter.getName() + " must hava a full qualified type.");
|
||||||
|
}
|
||||||
|
typeImpl = new EdmTypeInfo.Builder().setEdm(edm).setTypeExpression(parameter.getType()).build().getType();
|
||||||
if (typeImpl == null) {
|
if (typeImpl == null) {
|
||||||
throw new EdmException("Cannot find type with name: " + typeInfo.getFullQualifiedName());
|
throw new EdmException("Cannot find type with name: " + parameter.getTypeFQN());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,9 +6,9 @@
|
||||||
* to you under the Apache License, Version 2.0 (the
|
* to you under the Apache License, Version 2.0 (the
|
||||||
* "License"); you may not use this file except in compliance
|
* "License"); you may not use this file except in compliance
|
||||||
* with the License. You may obtain a copy of the License at
|
* with the License. You may obtain a copy of the License at
|
||||||
*
|
*
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
*
|
*
|
||||||
* Unless required by applicable law or agreed to in writing,
|
* Unless required by applicable law or agreed to in writing,
|
||||||
* software distributed under the License is distributed on an
|
* software distributed under the License is distributed on an
|
||||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
@ -30,19 +30,22 @@ import org.apache.olingo.commons.api.edm.provider.CsdlProperty;
|
||||||
public class EdmPropertyImpl extends AbstractEdmNamed implements EdmProperty, EdmElement {
|
public class EdmPropertyImpl extends AbstractEdmNamed implements EdmProperty, EdmElement {
|
||||||
|
|
||||||
private final CsdlProperty property;
|
private final CsdlProperty property;
|
||||||
private final EdmTypeInfo typeInfo;
|
private EdmTypeInfo typeInfo;
|
||||||
private EdmType propertyType;
|
private EdmType propertyType;
|
||||||
|
|
||||||
public EdmPropertyImpl(final Edm edm, final CsdlProperty property) {
|
public EdmPropertyImpl(final Edm edm, final CsdlProperty property) {
|
||||||
super(edm, property.getName(), property);
|
super(edm, property.getName(), property);
|
||||||
|
|
||||||
this.property = property;
|
this.property = property;
|
||||||
typeInfo = new EdmTypeInfo.Builder().setEdm(edm).setTypeExpression(property.getType().toString()).build();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public EdmType getType() {
|
public EdmType getType() {
|
||||||
if (propertyType == null) {
|
if (propertyType == null) {
|
||||||
|
if (typeInfo == null) {
|
||||||
|
buildTypeInfo();
|
||||||
|
}
|
||||||
propertyType = typeInfo.getType();
|
propertyType = typeInfo.getType();
|
||||||
if (propertyType == null) {
|
if (propertyType == null) {
|
||||||
throw new EdmException("Cannot find type with name: " + typeInfo.getFullQualifiedName());
|
throw new EdmException("Cannot find type with name: " + typeInfo.getFullQualifiedName());
|
||||||
|
@ -52,6 +55,13 @@ public class EdmPropertyImpl extends AbstractEdmNamed implements EdmProperty, Ed
|
||||||
return propertyType;
|
return propertyType;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void buildTypeInfo() {
|
||||||
|
if (property.getType() == null) {
|
||||||
|
throw new EdmException("Property " + property.getName() + " must hava a full qualified type.");
|
||||||
|
}
|
||||||
|
typeInfo = new EdmTypeInfo.Builder().setEdm(edm).setTypeExpression(property.getType().toString()).build();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isCollection() {
|
public boolean isCollection() {
|
||||||
return property.isCollection();
|
return property.isCollection();
|
||||||
|
@ -104,6 +114,9 @@ public class EdmPropertyImpl extends AbstractEdmNamed implements EdmProperty, Ed
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isPrimitive() {
|
public boolean isPrimitive() {
|
||||||
|
if (typeInfo == null) {
|
||||||
|
buildTypeInfo();
|
||||||
|
}
|
||||||
return typeInfo.isPrimitiveType();
|
return typeInfo.isPrimitiveType();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,9 +6,9 @@
|
||||||
* to you under the Apache License, Version 2.0 (the
|
* to you under the Apache License, Version 2.0 (the
|
||||||
* "License"); you may not use this file except in compliance
|
* "License"); you may not use this file except in compliance
|
||||||
* with the License. You may obtain a copy of the License at
|
* with the License. You may obtain a copy of the License at
|
||||||
*
|
*
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
*
|
*
|
||||||
* Unless required by applicable law or agreed to in writing,
|
* Unless required by applicable law or agreed to in writing,
|
||||||
* software distributed under the License is distributed on an
|
* software distributed under the License is distributed on an
|
||||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
@ -28,12 +28,12 @@ import org.apache.olingo.commons.api.edm.provider.CsdlReturnType;
|
||||||
public class EdmReturnTypeImpl implements EdmReturnType {
|
public class EdmReturnTypeImpl implements EdmReturnType {
|
||||||
|
|
||||||
private final CsdlReturnType returnType;
|
private final CsdlReturnType returnType;
|
||||||
private final EdmTypeInfo typeInfo;
|
private final Edm edm;
|
||||||
private EdmType typeImpl;
|
private EdmType typeImpl;
|
||||||
|
|
||||||
public EdmReturnTypeImpl(final Edm edm, final CsdlReturnType returnType) {
|
public EdmReturnTypeImpl(final Edm edm, final CsdlReturnType returnType) {
|
||||||
|
this.edm = edm;
|
||||||
this.returnType = returnType;
|
this.returnType = returnType;
|
||||||
typeInfo = new EdmTypeInfo.Builder().setEdm(edm).setTypeExpression(returnType.getType()).build();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -69,9 +69,12 @@ public class EdmReturnTypeImpl implements EdmReturnType {
|
||||||
@Override
|
@Override
|
||||||
public EdmType getType() {
|
public EdmType getType() {
|
||||||
if (typeImpl == null) {
|
if (typeImpl == null) {
|
||||||
typeImpl = typeInfo.getType();
|
if (returnType.getType() == null) {
|
||||||
|
throw new EdmException("Return types must hava a full qualified type.");
|
||||||
|
}
|
||||||
|
typeImpl = new EdmTypeInfo.Builder().setEdm(edm).setTypeExpression(returnType.getType()).build().getType();
|
||||||
if (typeImpl == null) {
|
if (typeImpl == null) {
|
||||||
throw new EdmException("Cannot find type with name: " + typeInfo.getFullQualifiedName());
|
throw new EdmException("Cannot find type with name: " + returnType.getType());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -30,23 +30,19 @@ import org.apache.olingo.commons.api.edm.FullQualifiedName;
|
||||||
import org.apache.olingo.commons.api.edm.TargetType;
|
import org.apache.olingo.commons.api.edm.TargetType;
|
||||||
import org.apache.olingo.commons.api.edm.geo.SRID;
|
import org.apache.olingo.commons.api.edm.geo.SRID;
|
||||||
import org.apache.olingo.commons.api.edm.provider.CsdlTerm;
|
import org.apache.olingo.commons.api.edm.provider.CsdlTerm;
|
||||||
import org.apache.olingo.commons.core.edm.primitivetype.EdmPrimitiveTypeFactory;
|
|
||||||
|
|
||||||
public class EdmTermImpl extends AbstractEdmNamed implements EdmTerm {
|
public class EdmTermImpl extends AbstractEdmNamed implements EdmTerm {
|
||||||
|
|
||||||
private final CsdlTerm term;
|
private final CsdlTerm term;
|
||||||
private final FullQualifiedName fqn;
|
private final FullQualifiedName fqn;
|
||||||
private final EdmTypeInfo typeInfo;
|
|
||||||
private EdmType termType;
|
private EdmType termType;
|
||||||
private EdmTerm baseTerm;
|
private EdmTerm baseTerm;
|
||||||
private List<TargetType> appliesTo;
|
private List<TargetType> appliesTo;
|
||||||
|
|
||||||
public EdmTermImpl(final Edm edm, final String namespace, final CsdlTerm term) {
|
public EdmTermImpl(final Edm edm, final String namespace, final CsdlTerm term) {
|
||||||
super(edm, term.getName(), term);
|
super(edm, term.getName(), term);
|
||||||
|
|
||||||
this.term = term;
|
this.term = term;
|
||||||
fqn = new FullQualifiedName(namespace, term.getName());
|
fqn = new FullQualifiedName(namespace, term.getName());
|
||||||
typeInfo = new EdmTypeInfo.Builder().setEdm(edm).setTypeExpression(term.getType()).build();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -57,22 +53,14 @@ public class EdmTermImpl extends AbstractEdmNamed implements EdmTerm {
|
||||||
@Override
|
@Override
|
||||||
public EdmType getType() {
|
public EdmType getType() {
|
||||||
if (termType == null) {
|
if (termType == null) {
|
||||||
termType = typeInfo.isPrimitiveType()
|
if (term.getType() == null) {
|
||||||
? EdmPrimitiveTypeFactory.getInstance(typeInfo.getPrimitiveTypeKind())
|
throw new EdmException("Terms must hava a full qualified type.");
|
||||||
: typeInfo.isTypeDefinition()
|
}
|
||||||
? typeInfo.getTypeDefinition()
|
termType = new EdmTypeInfo.Builder().setEdm(edm).setTypeExpression(term.getType()).build().getType();
|
||||||
: typeInfo.isEnumType()
|
|
||||||
? typeInfo.getEnumType()
|
|
||||||
: typeInfo.isComplexType()
|
|
||||||
? typeInfo.getComplexType()
|
|
||||||
: typeInfo.isEntityType()
|
|
||||||
? typeInfo.getEntityType()
|
|
||||||
: null;
|
|
||||||
if (termType == null) {
|
if (termType == null) {
|
||||||
throw new EdmException("Cannot find type with name: " + typeInfo.getFullQualifiedName());
|
throw new EdmException("Cannot find type with name: " + term.getType());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return termType;
|
return termType;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -20,10 +20,14 @@ package org.apache.olingo.server.core.edm.provider;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.Assert.assertFalse;
|
||||||
|
import static org.junit.Assert.assertNotNull;
|
||||||
import static org.junit.Assert.assertNull;
|
import static org.junit.Assert.assertNull;
|
||||||
|
import static org.junit.Assert.assertTrue;
|
||||||
|
import static org.junit.Assert.fail;
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
|
import org.apache.olingo.commons.api.edm.Edm;
|
||||||
import org.apache.olingo.commons.api.edm.EdmException;
|
import org.apache.olingo.commons.api.edm.EdmException;
|
||||||
import org.apache.olingo.commons.api.edm.EdmParameter;
|
import org.apache.olingo.commons.api.edm.EdmParameter;
|
||||||
import org.apache.olingo.commons.api.edm.EdmPrimitiveType;
|
import org.apache.olingo.commons.api.edm.EdmPrimitiveType;
|
||||||
|
@ -42,6 +46,29 @@ import org.junit.Test;
|
||||||
|
|
||||||
public class EdmParameterImplTest {
|
public class EdmParameterImplTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void initialParameter() {
|
||||||
|
EdmParameterImpl parameter = new EdmParameterImpl(mock(Edm.class), new CsdlParameter());
|
||||||
|
|
||||||
|
assertTrue(parameter.isNullable());
|
||||||
|
assertFalse(parameter.isCollection());
|
||||||
|
assertNull(parameter.getName());
|
||||||
|
assertNull(parameter.getMapping());
|
||||||
|
assertNull(parameter.getMaxLength());
|
||||||
|
assertNull(parameter.getPrecision());
|
||||||
|
assertNull(parameter.getScale());
|
||||||
|
assertNull(parameter.getSrid());
|
||||||
|
assertNotNull(parameter.getAnnotations());
|
||||||
|
assertTrue(parameter.getAnnotations().isEmpty());
|
||||||
|
|
||||||
|
try {
|
||||||
|
parameter.getType();
|
||||||
|
fail("EdmException expected");
|
||||||
|
} catch (EdmException e) {
|
||||||
|
assertEquals("Parameter null must hava a full qualified type.", e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getTypeReturnsPrimitiveType() {
|
public void getTypeReturnsPrimitiveType() {
|
||||||
EdmProviderImpl edm = new EdmProviderImpl(mock(CsdlEdmProvider.class));
|
EdmProviderImpl edm = new EdmProviderImpl(mock(CsdlEdmProvider.class));
|
||||||
|
|
|
@ -20,12 +20,14 @@ package org.apache.olingo.server.core.edm.provider;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.Assert.assertFalse;
|
||||||
|
import static org.junit.Assert.assertNotNull;
|
||||||
import static org.junit.Assert.assertNull;
|
import static org.junit.Assert.assertNull;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
import static org.junit.Assert.fail;
|
import static org.junit.Assert.fail;
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
|
import org.apache.olingo.commons.api.edm.Edm;
|
||||||
import org.apache.olingo.commons.api.edm.EdmException;
|
import org.apache.olingo.commons.api.edm.EdmException;
|
||||||
import org.apache.olingo.commons.api.edm.EdmPrimitiveType;
|
import org.apache.olingo.commons.api.edm.EdmPrimitiveType;
|
||||||
import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind;
|
import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind;
|
||||||
|
@ -44,6 +46,36 @@ import org.junit.Test;
|
||||||
|
|
||||||
public class EdmPropertyImplTest {
|
public class EdmPropertyImplTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void initialProperty() {
|
||||||
|
EdmProperty property = new EdmPropertyImpl(mock(Edm.class), new CsdlProperty());
|
||||||
|
|
||||||
|
assertTrue(property.isNullable());
|
||||||
|
assertFalse(property.isCollection());
|
||||||
|
assertNull(property.getName());
|
||||||
|
assertNull(property.getMapping());
|
||||||
|
assertNull(property.getMaxLength());
|
||||||
|
assertNull(property.getPrecision());
|
||||||
|
assertNull(property.getScale());
|
||||||
|
assertNull(property.getSrid());
|
||||||
|
assertNotNull(property.getAnnotations());
|
||||||
|
assertTrue(property.getAnnotations().isEmpty());
|
||||||
|
|
||||||
|
try {
|
||||||
|
property.getType();
|
||||||
|
fail("EdmException expected");
|
||||||
|
} catch (EdmException e) {
|
||||||
|
assertEquals("Property null must hava a full qualified type.", e.getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
property.isPrimitive();
|
||||||
|
fail("EdmException expected");
|
||||||
|
} catch (EdmException e) {
|
||||||
|
assertEquals("Property null must hava a full qualified type.", e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getTypeReturnsPrimitiveType() {
|
public void getTypeReturnsPrimitiveType() {
|
||||||
EdmProviderImpl edm = new EdmProviderImpl(mock(CsdlEdmProvider.class));
|
EdmProviderImpl edm = new EdmProviderImpl(mock(CsdlEdmProvider.class));
|
||||||
|
|
|
@ -22,9 +22,11 @@ import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.Assert.assertFalse;
|
||||||
import static org.junit.Assert.assertNull;
|
import static org.junit.Assert.assertNull;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
|
import static org.junit.Assert.fail;
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
|
import org.apache.olingo.commons.api.edm.Edm;
|
||||||
import org.apache.olingo.commons.api.edm.EdmComplexType;
|
import org.apache.olingo.commons.api.edm.EdmComplexType;
|
||||||
import org.apache.olingo.commons.api.edm.EdmEntityType;
|
import org.apache.olingo.commons.api.edm.EdmEntityType;
|
||||||
import org.apache.olingo.commons.api.edm.EdmEnumType;
|
import org.apache.olingo.commons.api.edm.EdmEnumType;
|
||||||
|
@ -42,6 +44,24 @@ import org.junit.Test;
|
||||||
|
|
||||||
public class EdmReturnTypeImplTest {
|
public class EdmReturnTypeImplTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void initialReturnType() {
|
||||||
|
EdmReturnType returnType = new EdmReturnTypeImpl(mock(Edm.class), new CsdlReturnType());
|
||||||
|
|
||||||
|
assertTrue(returnType.isNullable());
|
||||||
|
assertNull(returnType.getMaxLength());
|
||||||
|
assertNull(returnType.getPrecision());
|
||||||
|
assertNull(returnType.getScale());
|
||||||
|
assertNull(returnType.getSrid());
|
||||||
|
|
||||||
|
try {
|
||||||
|
returnType.getType();
|
||||||
|
fail("EdmException expected");
|
||||||
|
} catch (EdmException e) {
|
||||||
|
assertEquals("Return types must hava a full qualified type.", e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void primitiveReturnType() {
|
public void primitiveReturnType() {
|
||||||
CsdlReturnType providerType = new CsdlReturnType().setType(new FullQualifiedName("Edm", "String"));
|
CsdlReturnType providerType = new CsdlReturnType().setType(new FullQualifiedName("Edm", "String"));
|
||||||
|
|
|
@ -25,6 +25,7 @@ import static org.mockito.Mockito.mock;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.apache.olingo.commons.api.edm.Edm;
|
import org.apache.olingo.commons.api.edm.Edm;
|
||||||
|
@ -173,7 +174,7 @@ public class EdmSchemaImplTest {
|
||||||
for (EdmFunction function : functions) {
|
for (EdmFunction function : functions) {
|
||||||
FullQualifiedName functionName = new FullQualifiedName(NAMESPACE, function.getName());
|
FullQualifiedName functionName = new FullQualifiedName(NAMESPACE, function.getName());
|
||||||
assertTrue(function == edm.getUnboundFunction(functionName, null));
|
assertTrue(function == edm.getUnboundFunction(functionName, null));
|
||||||
|
|
||||||
functionName = new FullQualifiedName(ALIAS, function.getName());
|
functionName = new FullQualifiedName(ALIAS, function.getName());
|
||||||
assertTrue(function == edm.getUnboundFunction(functionName, null));
|
assertTrue(function == edm.getUnboundFunction(functionName, null));
|
||||||
}
|
}
|
||||||
|
@ -193,7 +194,6 @@ public class EdmSchemaImplTest {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getContainer() {
|
public void getContainer() {
|
||||||
EdmEntityContainer container = schema.getEntityContainer();
|
EdmEntityContainer container = schema.getEntityContainer();
|
||||||
|
@ -301,7 +301,7 @@ public class EdmSchemaImplTest {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<CsdlAliasInfo> getAliasInfos() throws ODataException {
|
public List<CsdlAliasInfo> getAliasInfos() throws ODataException {
|
||||||
throw new RuntimeException("Provider must not be called in the schema case");
|
return Collections.emptyList();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -373,17 +373,17 @@ public class EdmSchemaImplTest {
|
||||||
functions.add(new CsdlFunction().setName("function1"));
|
functions.add(new CsdlFunction().setName("function1"));
|
||||||
functions.add(new CsdlFunction().setName("function2"));
|
functions.add(new CsdlFunction().setName("function2"));
|
||||||
providerSchema.setFunctions(functions);
|
providerSchema.setFunctions(functions);
|
||||||
|
|
||||||
List<CsdlAnnotations> annotationGroups = new ArrayList<CsdlAnnotations>();
|
List<CsdlAnnotations> annotationGroups = new ArrayList<CsdlAnnotations>();
|
||||||
annotationGroups.add(new CsdlAnnotations().setTarget(NAMESPACE + ".entityType1"));
|
annotationGroups.add(new CsdlAnnotations().setTarget(NAMESPACE + ".entityType1"));
|
||||||
annotationGroups.add(new CsdlAnnotations().setTarget(NAMESPACE + ".entityType2"));
|
annotationGroups.add(new CsdlAnnotations().setTarget(NAMESPACE + ".entityType2"));
|
||||||
providerSchema.setAnnotationsGroup(annotationGroups);
|
providerSchema.setAnnotationsGroup(annotationGroups);
|
||||||
|
|
||||||
List<CsdlTerm> terms = new ArrayList<CsdlTerm>();
|
List<CsdlTerm> terms = new ArrayList<CsdlTerm>();
|
||||||
terms.add(new CsdlTerm().setName("term1").setType("Edm.String"));
|
terms.add(new CsdlTerm().setName("term1").setType("Edm.String"));
|
||||||
terms.add(new CsdlTerm().setName("term2").setType("Edm.String"));
|
terms.add(new CsdlTerm().setName("term2").setType("Edm.String"));
|
||||||
providerSchema.setTerms(terms);
|
providerSchema.setTerms(terms);
|
||||||
|
|
||||||
ArrayList<CsdlSchema> schemas = new ArrayList<CsdlSchema>();
|
ArrayList<CsdlSchema> schemas = new ArrayList<CsdlSchema>();
|
||||||
schemas.add(providerSchema);
|
schemas.add(providerSchema);
|
||||||
return schemas;
|
return schemas;
|
||||||
|
|
|
@ -54,6 +54,28 @@ public class EdmTermImplTest {
|
||||||
private EdmTerm initialTerm;
|
private EdmTerm initialTerm;
|
||||||
private EdmTerm derivedTerm;
|
private EdmTerm derivedTerm;
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void initialTerm() {
|
||||||
|
EdmTerm term = new EdmTermImpl(mock(Edm.class), "namespace", new CsdlTerm());
|
||||||
|
|
||||||
|
assertTrue(term.isNullable());
|
||||||
|
assertNull(term.getName());
|
||||||
|
assertNull(term.getMaxLength());
|
||||||
|
assertNull(term.getPrecision());
|
||||||
|
assertNull(term.getScale());
|
||||||
|
assertNull(term.getSrid());
|
||||||
|
assertNotNull(term.getAnnotations());
|
||||||
|
assertTrue(term.getAnnotations().isEmpty());
|
||||||
|
|
||||||
|
assertNotNull(term.getFullQualifiedName());
|
||||||
|
try {
|
||||||
|
term.getType();
|
||||||
|
fail("EdmException expected");
|
||||||
|
} catch (EdmException e) {
|
||||||
|
assertEquals("Terms must hava a full qualified type.", e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setupTypes() throws Exception {
|
public void setupTypes() throws Exception {
|
||||||
CsdlEdmProvider provider = mock(CsdlEdmProvider.class);
|
CsdlEdmProvider provider = mock(CsdlEdmProvider.class);
|
||||||
|
|
|
@ -190,19 +190,19 @@ public class ContainerProvider {
|
||||||
Arrays
|
Arrays
|
||||||
.asList(
|
.asList(
|
||||||
new CsdlAnnotation()
|
new CsdlAnnotation()
|
||||||
.setTerm("Core.Description")
|
.setTerm("Org.OData.Core.V1.Description")
|
||||||
.setExpression(
|
.setExpression(
|
||||||
new CsdlConstantExpression(CsdlConstantExpression.ConstantExpressionType.String)
|
new CsdlConstantExpression(CsdlConstantExpression.ConstantExpressionType.String)
|
||||||
.setValue("Contains entities with collection of each primitive type")),
|
.setValue("Contains entities with collection of each primitive type")),
|
||||||
new CsdlAnnotation()
|
new CsdlAnnotation()
|
||||||
.setTerm("Core.LongDescription")
|
.setTerm("Org.OData.Core.V1.LongDescription")
|
||||||
.setQualifier("EnabledForEntitySet")
|
.setQualifier("EnabledForEntitySet")
|
||||||
.setExpression(
|
.setExpression(
|
||||||
new CsdlConstantExpression(CsdlConstantExpression.ConstantExpressionType.String)
|
new CsdlConstantExpression(CsdlConstantExpression.ConstantExpressionType.String)
|
||||||
.setValue("System Query Options: $filter, $count, $orderby, "
|
.setValue("System Query Options: $filter, $count, $orderby, "
|
||||||
+ "$skip, $top, $expand, $select, $format; Operations: Create, Read")),
|
+ "$skip, $top, $expand, $select, $format; Operations: Create, Read")),
|
||||||
new CsdlAnnotation()
|
new CsdlAnnotation()
|
||||||
.setTerm("Core.LongDescription")
|
.setTerm("Org.OData.Core.V1.LongDescription")
|
||||||
.setQualifier("EnabledForEntity")
|
.setQualifier("EnabledForEntity")
|
||||||
.setExpression(
|
.setExpression(
|
||||||
new CsdlConstantExpression(CsdlConstantExpression.ConstantExpressionType.String)
|
new CsdlConstantExpression(CsdlConstantExpression.ConstantExpressionType.String)
|
||||||
|
|
Loading…
Reference in New Issue