[OLINGO-786] Add qualifier to key
This commit is contained in:
parent
addfe512cd
commit
a88800c47a
|
@ -106,7 +106,7 @@ public class MetadataTestITCase extends AbstractTestITCase {
|
|||
assertEquals(descriptionTerm.getFullQualifiedName(),
|
||||
edm.getTerm(new FullQualifiedName("Org.OData.Core.V1.Description")).getFullQualifiedName());
|
||||
|
||||
final EdmAnnotation description = core.getAnnotation(descriptionTerm);
|
||||
final EdmAnnotation description = core.getAnnotation(descriptionTerm, null);
|
||||
assertNotNull(description);
|
||||
// assertEquals("Core terms needed to write vocabularies",
|
||||
// description.getExpression().asConstant().getValue().asPrimitive().getName());
|
||||
|
@ -119,7 +119,7 @@ public class MetadataTestITCase extends AbstractTestITCase {
|
|||
assertTrue(isLanguageDependent.getAppliesTo().contains(EdmTerm.class));
|
||||
assertEquals(edm.getTypeDefinition(new FullQualifiedName("Core.Tag")), isLanguageDependent.getType());
|
||||
assertEquals(EdmBoolean.getInstance(), ((EdmTypeDefinition) isLanguageDependent.getType()).getUnderlyingType());
|
||||
assertNotNull(isLanguageDependent.getAnnotation(descriptionTerm));
|
||||
assertNotNull(isLanguageDependent.getAnnotation(descriptionTerm, null));
|
||||
|
||||
final EdmTerm permissions = edm.getTerm(new FullQualifiedName("Core.Permissions"));
|
||||
assertNotNull(permissions);
|
||||
|
@ -133,7 +133,7 @@ public class MetadataTestITCase extends AbstractTestITCase {
|
|||
assertNotNull(scale);
|
||||
|
||||
final EdmAnnotation requiresTypeInScale =
|
||||
scale.getAnnotation(edm.getTerm(new FullQualifiedName("Core.RequiresType")));
|
||||
scale.getAnnotation(edm.getTerm(new FullQualifiedName("Core.RequiresType")), null);
|
||||
assertNotNull(requiresTypeInScale);
|
||||
assertEquals("Edm.Decimal", requiresTypeInScale.getExpression().asConstant().getValueAsString());
|
||||
|
||||
|
|
|
@ -161,7 +161,8 @@ public interface Edm {
|
|||
* Get {@link EdmAnnotations} by target.
|
||||
*
|
||||
* @param targetName <tt>edm:Annotations</tt> target
|
||||
* @param qualifier for the target. Can be <code>NULL</code>
|
||||
* @return {@link EdmAnnotations}
|
||||
*/
|
||||
EdmAnnotations getAnnotationGroup(FullQualifiedName targetName);
|
||||
EdmAnnotations getAnnotationGroup(FullQualifiedName targetName, String qualifier);
|
||||
}
|
||||
|
|
|
@ -27,9 +27,10 @@ public interface EdmAnnotatable {
|
|||
|
||||
/**
|
||||
* @param term term for annotation
|
||||
* @param qualifier for the term. Can be <code>NULL</code>
|
||||
* @return annotation according to term
|
||||
*/
|
||||
EdmAnnotation getAnnotation(EdmTerm term);
|
||||
EdmAnnotation getAnnotation(EdmTerm term, String qualifier);
|
||||
|
||||
/**
|
||||
* Get list of all annotations.
|
||||
|
|
|
@ -20,10 +20,19 @@ package org.apache.olingo.commons.api.edm;
|
|||
|
||||
import org.apache.olingo.commons.api.edm.annotation.EdmAnnotationExpression;
|
||||
|
||||
/**
|
||||
* This class models an OData Annotation which can be applied to a target.
|
||||
*/
|
||||
public interface EdmAnnotation extends EdmAnnotatable {
|
||||
|
||||
/**
|
||||
* @return the term of this annotation
|
||||
*/
|
||||
EdmTerm getTerm();
|
||||
|
||||
/**
|
||||
* @return the qualifier for this annotation. Might be <code>NULL</code>
|
||||
*/
|
||||
String getQualifier();
|
||||
|
||||
EdmAnnotationExpression getExpression();
|
||||
|
|
|
@ -76,8 +76,8 @@ public abstract class AbstractEdm implements Edm {
|
|||
private final Map<FullQualifiedName, EdmTerm> terms =
|
||||
Collections.synchronizedMap(new HashMap<FullQualifiedName, EdmTerm>());
|
||||
|
||||
private final Map<FullQualifiedName, EdmAnnotations> annotationGroups =
|
||||
Collections.synchronizedMap(new HashMap<FullQualifiedName, EdmAnnotations>());
|
||||
private final Map<TargetQualifierMapKey, EdmAnnotations> annotationGroups =
|
||||
Collections.synchronizedMap(new HashMap<TargetQualifierMapKey, EdmAnnotations>());
|
||||
|
||||
private Map<String, String> aliasToNamespaceInfo = Collections.synchronizedMap(new HashMap<String, String>());
|
||||
private boolean aliasToNamespaceInfoCreated = false;
|
||||
|
@ -296,12 +296,14 @@ public abstract class AbstractEdm implements Edm {
|
|||
}
|
||||
|
||||
@Override
|
||||
public EdmAnnotations getAnnotationGroup(final FullQualifiedName targetName) {
|
||||
EdmAnnotations _annotations = annotationGroups.get(targetName);
|
||||
public EdmAnnotations getAnnotationGroup(final FullQualifiedName targetName, String qualifier) {
|
||||
final FullQualifiedName fqn = resolvePossibleAlias(targetName);
|
||||
TargetQualifierMapKey key = new TargetQualifierMapKey(fqn, qualifier);
|
||||
EdmAnnotations _annotations = annotationGroups.get(key);
|
||||
if (_annotations == null) {
|
||||
_annotations = createAnnotationGroup(targetName);
|
||||
if (_annotations != null) {
|
||||
annotationGroups.put(targetName, _annotations);
|
||||
annotationGroups.put(key, _annotations);
|
||||
}
|
||||
}
|
||||
return _annotations;
|
||||
|
@ -411,8 +413,9 @@ public abstract class AbstractEdm implements Edm {
|
|||
|
||||
protected abstract EdmAnnotations createAnnotationGroup(FullQualifiedName targetName);
|
||||
|
||||
public void cacheAnnotationGroup(final FullQualifiedName annotationsGroupName,
|
||||
public void cacheAnnotationGroup(final FullQualifiedName targetName,
|
||||
final EdmAnnotations annotationsGroup) {
|
||||
annotationGroups.put(annotationsGroupName, annotationsGroup);
|
||||
TargetQualifierMapKey key = new TargetQualifierMapKey(targetName, annotationsGroup.getQualifier());
|
||||
annotationGroups.put(key, annotationsGroup);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,9 +6,9 @@
|
|||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
|
@ -41,14 +41,17 @@ public abstract class AbstractEdmAnnotatable implements EdmAnnotatable {
|
|||
}
|
||||
|
||||
@Override
|
||||
public EdmAnnotation getAnnotation(final EdmTerm term) {
|
||||
public EdmAnnotation getAnnotation(final EdmTerm term, String qualifier) {
|
||||
EdmAnnotation result = null;
|
||||
for (EdmAnnotation annotation : getAnnotations()) {
|
||||
if (term.getFullQualifiedName().equals(annotation.getTerm().getFullQualifiedName())) {
|
||||
result = annotation;
|
||||
if (qualifier == annotation.getQualifier()
|
||||
|| (qualifier != null && qualifier.equals(annotation.getQualifier()))) {
|
||||
result = annotation;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
|
|
@ -25,9 +25,7 @@ import java.util.LinkedHashMap;
|
|||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.olingo.commons.api.ex.ODataException;
|
||||
import org.apache.olingo.commons.api.edm.EdmAction;
|
||||
import org.apache.olingo.commons.api.edm.EdmAnnotation;
|
||||
import org.apache.olingo.commons.api.edm.EdmAnnotations;
|
||||
import org.apache.olingo.commons.api.edm.EdmComplexType;
|
||||
import org.apache.olingo.commons.api.edm.EdmEntityContainer;
|
||||
|
@ -41,8 +39,6 @@ import org.apache.olingo.commons.api.edm.EdmTypeDefinition;
|
|||
import org.apache.olingo.commons.api.edm.FullQualifiedName;
|
||||
import org.apache.olingo.commons.api.edm.provider.CsdlAction;
|
||||
import org.apache.olingo.commons.api.edm.provider.CsdlAliasInfo;
|
||||
import org.apache.olingo.commons.api.edm.provider.CsdlAnnotatable;
|
||||
import org.apache.olingo.commons.api.edm.provider.CsdlAnnotation;
|
||||
import org.apache.olingo.commons.api.edm.provider.CsdlAnnotations;
|
||||
import org.apache.olingo.commons.api.edm.provider.CsdlComplexType;
|
||||
import org.apache.olingo.commons.api.edm.provider.CsdlEdmProvider;
|
||||
|
@ -54,6 +50,7 @@ import org.apache.olingo.commons.api.edm.provider.CsdlParameter;
|
|||
import org.apache.olingo.commons.api.edm.provider.CsdlSchema;
|
||||
import org.apache.olingo.commons.api.edm.provider.CsdlTerm;
|
||||
import org.apache.olingo.commons.api.edm.provider.CsdlTypeDefinition;
|
||||
import org.apache.olingo.commons.api.ex.ODataException;
|
||||
|
||||
public class EdmProviderImpl extends AbstractEdm {
|
||||
|
||||
|
@ -344,7 +341,6 @@ public class EdmProviderImpl extends AbstractEdm {
|
|||
}
|
||||
}
|
||||
|
||||
// TODO: Check Provider annotations implementation
|
||||
@Override
|
||||
protected EdmAnnotations createAnnotationGroup(final FullQualifiedName targetName) {
|
||||
try {
|
||||
|
|
|
@ -46,7 +46,7 @@ import org.apache.olingo.commons.api.edm.provider.CsdlSchema;
|
|||
import org.apache.olingo.commons.api.edm.provider.CsdlTerm;
|
||||
import org.apache.olingo.commons.api.edm.provider.CsdlTypeDefinition;
|
||||
|
||||
public class EdmSchemaImpl implements EdmSchema {
|
||||
public class EdmSchemaImpl extends AbstractEdmAnnotatable implements EdmSchema {
|
||||
|
||||
private final CsdlSchema schema;
|
||||
private final EdmProviderImpl edm;
|
||||
|
@ -66,6 +66,7 @@ public class EdmSchemaImpl implements EdmSchema {
|
|||
private EdmEntityContainer entityContainer;
|
||||
|
||||
public EdmSchemaImpl(final EdmProviderImpl edm, final CsdlEdmProvider provider, final CsdlSchema schema) {
|
||||
super(edm, schema);
|
||||
this.edm = edm;
|
||||
this.provider = provider;
|
||||
this.schema = schema;
|
||||
|
@ -263,15 +264,15 @@ public class EdmSchemaImpl implements EdmSchema {
|
|||
schema.getAnnotationGroups();
|
||||
if (providerAnnotations != null) {
|
||||
for (CsdlAnnotations annotationGroup : providerAnnotations) {
|
||||
FullQualifiedName annotationsGroupName;
|
||||
FullQualifiedName targetName;
|
||||
if (annotationGroup.getTarget().contains(".")) {
|
||||
annotationsGroupName = new FullQualifiedName(annotationGroup.getTarget());
|
||||
targetName = new FullQualifiedName(annotationGroup.getTarget());
|
||||
} else {
|
||||
annotationsGroupName = new FullQualifiedName(namespace, annotationGroup.getTarget());
|
||||
targetName = new FullQualifiedName(namespace, annotationGroup.getTarget());
|
||||
}
|
||||
EdmAnnotationsImpl annotationsImpl = new EdmAnnotationsImpl(edm, this, annotationGroup);
|
||||
annotationGroups.add(annotationsImpl);
|
||||
edm.cacheAnnotationGroup(annotationsGroupName, annotationsImpl);
|
||||
edm.cacheAnnotationGroup(targetName, annotationsImpl);
|
||||
}
|
||||
}
|
||||
return annotationGroups;
|
||||
|
@ -289,16 +290,4 @@ public class EdmSchemaImpl implements EdmSchema {
|
|||
}
|
||||
return annotations;
|
||||
}
|
||||
|
||||
@Override
|
||||
public EdmAnnotation getAnnotation(final EdmTerm term) {
|
||||
EdmAnnotation result = null;
|
||||
for (EdmAnnotation annotation : getAnnotations()) {
|
||||
if (term.getFullQualifiedName().equals(annotation.getTerm().getFullQualifiedName())) {
|
||||
result = annotation;
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,72 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.olingo.commons.core.edm;
|
||||
|
||||
import org.apache.olingo.commons.api.edm.FullQualifiedName;
|
||||
|
||||
public class TargetQualifierMapKey {
|
||||
|
||||
private final FullQualifiedName targetName;
|
||||
private final String qualifier;
|
||||
|
||||
public TargetQualifierMapKey(FullQualifiedName targetName, String qualifier) {
|
||||
this.targetName = targetName;
|
||||
this.qualifier = qualifier;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result + ((qualifier == null) ? 0 : qualifier.hashCode());
|
||||
result = prime * result + ((targetName == null) ? 0 : targetName.hashCode());
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj) {
|
||||
return true;
|
||||
}
|
||||
if (obj == null) {
|
||||
return false;
|
||||
}
|
||||
if (!(obj instanceof TargetQualifierMapKey)) {
|
||||
return false;
|
||||
}
|
||||
TargetQualifierMapKey other = (TargetQualifierMapKey) obj;
|
||||
if (qualifier == null) {
|
||||
if (other.qualifier != null) {
|
||||
return false;
|
||||
}
|
||||
} else if (!qualifier.equals(other.qualifier)) {
|
||||
return false;
|
||||
}
|
||||
if (targetName == null) {
|
||||
if (other.targetName != null) {
|
||||
return false;
|
||||
}
|
||||
} else if (!targetName.equals(other.targetName)) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -30,15 +30,19 @@ extends AbstractEdmDynamicAnnotationExpression implements EdmAnnotatable {
|
|||
|
||||
private final List<EdmAnnotation> annotations = new ArrayList<EdmAnnotation>();
|
||||
|
||||
//TODO: Can we derive this method from AbstractEdmAnnotatable?
|
||||
@Override
|
||||
public EdmAnnotation getAnnotation(final EdmTerm term) {
|
||||
public EdmAnnotation getAnnotation(final EdmTerm term, String qualifier) {
|
||||
EdmAnnotation result = null;
|
||||
for (EdmAnnotation annotation : getAnnotations()) {
|
||||
if (term.getFullQualifiedName().equals(annotation.getTerm().getFullQualifiedName())) {
|
||||
result = annotation;
|
||||
if (qualifier == annotation.getQualifier()
|
||||
|| (qualifier != null && qualifier.equals(annotation.getQualifier()))) {
|
||||
result = annotation;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
|
|
@ -22,7 +22,7 @@ import org.apache.olingo.commons.api.edm.annotation.EdmAnnotationExpression;
|
|||
import org.apache.olingo.commons.api.edm.annotation.EdmConstantAnnotationExpression;
|
||||
import org.apache.olingo.commons.api.edm.annotation.EdmDynamicAnnotationExpression;
|
||||
|
||||
public abstract class AbstractEdmAnnotationEspression implements EdmAnnotationExpression {
|
||||
public abstract class AbstractEdmAnnotationExpression implements EdmAnnotationExpression {
|
||||
|
||||
@Override
|
||||
public boolean isConstant() {
|
|
@ -45,7 +45,7 @@ import org.apache.olingo.commons.api.edm.annotation.EdmRecord;
|
|||
import org.apache.olingo.commons.api.edm.annotation.EdmUrlRef;
|
||||
|
||||
public abstract class AbstractEdmDynamicAnnotationExpression
|
||||
extends AbstractEdmAnnotationEspression implements EdmDynamicAnnotationExpression {
|
||||
extends AbstractEdmAnnotationExpression implements EdmDynamicAnnotationExpression {
|
||||
|
||||
@Override
|
||||
public boolean isNot() {
|
||||
|
|
|
@ -34,7 +34,6 @@ import java.util.Map;
|
|||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.olingo.commons.api.edm.Edm;
|
||||
import org.apache.olingo.commons.api.edm.EdmAction;
|
||||
import org.apache.olingo.commons.api.edm.EdmAnnotation;
|
||||
import org.apache.olingo.commons.api.edm.EdmAnnotations;
|
||||
import org.apache.olingo.commons.api.edm.EdmComplexType;
|
||||
import org.apache.olingo.commons.api.edm.EdmEntityContainer;
|
||||
|
|
|
@ -33,7 +33,6 @@ import java.util.Map;
|
|||
|
||||
import org.apache.olingo.commons.api.edm.Edm;
|
||||
import org.apache.olingo.commons.api.edm.EdmAction;
|
||||
import org.apache.olingo.commons.api.edm.EdmAnnotation;
|
||||
import org.apache.olingo.commons.api.edm.EdmAnnotations;
|
||||
import org.apache.olingo.commons.api.edm.EdmComplexType;
|
||||
import org.apache.olingo.commons.api.edm.EdmEntityContainer;
|
||||
|
|
Loading…
Reference in New Issue