com.sap.cloud.sdk.service.csn2jpa.cds.model.CdsModel Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of csn-reader Show documentation
Show all versions of csn-reader Show documentation
API for reading CDS models in CSN format
/*******************************************************************************
* * © 2018 SAP SE or an SAP affiliate company. All rights reserved. *
******************************************************************************/
package com.sap.cloud.sdk.service.csn2jpa.cds.model;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import com.google.common.collect.Lists;
public class CdsModel implements CdsNode {
List contexts = Lists.newArrayList();
List entities = Lists.newArrayList();
List types = Lists.newArrayList();
private CdsVersion version;
private String namingScheme;
public void addContext(CdsContext context) {
contexts.add(context);
}
public List getContexts() {
return contexts;
}
public List getEntities() {
return entities;
}
public void setEntities(List entities) {
this.entities = entities;
}
public List getTypes() {
return types;
}
public List getEnums() {
return types.stream().filter(e -> e.getType().isEnum()).collect(Collectors.toList());
}
public List getStructuredTypes() {
return getTypes().stream().filter(e -> e.getType().isStructured()).collect(Collectors.toList());
}
public void setTypes(List types) {
this.types = types;
}
public void addType(CdsTypeDefinition type) {
types.add(type);
}
public void addEntity(CdsEntity entity) {
entities.add(entity);
}
public Optional findEntity(String context, String name) {
return entities.stream()
.filter(e -> context.equals(e.getContext().getCanonicalName()) && name.equals(e.getName())).findFirst();
}
public List findIds(String context, String entity) {
List ids = Lists.newArrayList();
findEntity(context, entity).ifPresent(e -> ids
.addAll(e.getType().getElements().stream().filter(CdsElement::isKey).collect(Collectors.toList())));
return ids;
}
public Stream concreteEntities() {
return entities.stream().filter(e -> !e.isAbstract());
}
@Override
public void accept(CdsVisitor visitor) {
contexts.forEach(c -> c.accept(visitor));
entities.forEach(e -> e.accept(visitor));
types.forEach(t -> t.accept(visitor));
visitor.visit(this);
}
public CdsVersion getVersion() {
return version;
}
public void setVersion(CdsVersion version) {
this.version = version;
}
public String getNamingScheme() {
return namingScheme;
}
public void setNamingScheme(String namingScheme) {
this.namingScheme = namingScheme;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy