/** * @param importDeclaration * import declaration * @return list of namespaces that available from imported model */ public static List<String> getImportedNamespaces(ImportDeclaration importDeclaration) { ZenModel zenModel = importDeclaration.getImportedModel(); List<String> result = new ArrayList<>(); if (zenModel != null) { String namespace = ((zenModel.getNamespace() != null) ? zenModel.getNamespace() + "." : "")// + zenModel.getName(); result.addAll(zenModel.getResourceAPIs().stream()// .map(rapi -> namespace + "." + rapi.getName()).collect(Collectors.toList())); result.addAll(zenModel.getDataModels().stream()// .map(dm -> namespace + "." + dm.getName()).collect(Collectors.toList())); Optional.ofNullable(zenModel.getSecuritySchemesLibrary())// .filter(it -> !it.getSecuritySchemes().isEmpty())// .ifPresent(it -> result.add(namespace + "." + it.getName())); } return Collections.unmodifiableList(result); }
/** * @param model * model * @return list of resource definitions that imported using import RESTfulInterfaces */ static List<ResourceDefinition> getImportedResources(ZenModel model) { ArrayList<ResourceDefinition> result = new ArrayList<>(); for (ImportDeclaration importDecl : model.getImports()) { String uri = importDecl.getImportURI(); if (!Strings.isNullOrEmpty(uri)) { Resource modelResource = importDecl.eResource(); Resource resource = getResource(modelResource, uri); if (resource != null && resource.getErrors().isEmpty() && !resource.getContents().isEmpty()) { ZenModel zenModel = (ZenModel) resource.getContents().get(0); String namespace = Strings.isNullOrEmpty(zenModel.getNamespace()) ? zenModel.getName() : zenModel .getNamespace() + "." + zenModel.getName(); //$NON-NLS-1$ for (ResourceAPI resourceAPI : zenModel.getResourceAPIs()) { String ifaceFQN = namespace + "." + resourceAPI.getName(); //$NON-NLS-1$ if (ifaceFQN.equals(importDecl.getImportedNamespace())) { result.addAll(resourceAPI.getOwnedResourceDefinitions()); } } } } } return result; }
@SuppressWarnings("unused") private QualifiedName qualifiedName(ZenModel model) { if (!Strings.isEmpty(model.getNamespace())) { return QualifiedName.create(model.getNamespace().split("\\.")).append(model.getName()); //$NON-NLS-1$ } return QualifiedName.create(model.getName()); } }
public boolean addDefaultResourceAPI(final ZenModel model) { boolean _xblockexpression = false; { final ResourceAPI resourceAPI = RapidmlFactory.eINSTANCE.createResourceAPI(); resourceAPI.setBaseURI("http://localhost"); resourceAPI.setName(model.getName()); _xblockexpression = model.getResourceAPIs().add(resourceAPI); } return _xblockexpression; }
protected ObjectNode getJsonSchemaNode(final ZenModel model) { final ObjectNode root = this.mapper.createObjectNode(); ObjectNode _put = root.put("$schema", "http://json-schema.org/draft-04/schema#"); StringConcatenation _builder = new StringConcatenation(); _builder.append("Schema for "); String _name = model.getName(); _builder.append(_name); _builder.append(" model"); _put.put("description", _builder.toString()).put("type", "object").put("title", model.getName()); final ObjectNode definitions = this.jsonSchemaNodeFactory.generateDefinitionsNode(model); root.set("definitions", definitions); final ObjectNode properties = root.putObject("properties"); ArrayList<Map.Entry<String, JsonNode>> _newArrayList = Lists.<Map.Entry<String, JsonNode>>newArrayList(definitions.fields()); for (final Map.Entry<String, JsonNode> definition : _newArrayList) { { final String key = definition.getKey(); properties.putObject(key).put("$ref", ("#/definitions/" + key)); } } return root; } }
protected Collection<Enumeration> _getUsedEnums(final ZenModel model) { final Function1<ResourceAPI, Collection<Enumeration>> _function = (ResourceAPI it) -> { return this.getUsedEnums(it); }; return IterableExtensions.<Enumeration>toSet(Iterables.<Enumeration>concat(ListExtensions.<ResourceAPI, Collection<Enumeration>>map(model.getResourceAPIs(), _function))); }
if (model.getDataModels().size() == 1) { DataModel firstInterfaceDataModel = model.getDataModels().get(0); if (firstInterfaceDataModel.getName() != null && model.getName() != null) { QualifiedName importedNamespace = QualifiedName.create(model.getName(), firstInterfaceDataModel.getName()); return Optional.of(importedNamespace); && (context instanceof HasSecurityValue)) { ZenModel model = context instanceof ZenModel ? (ZenModel) context : RapidmlModelUtils.getZenModel(context); SecuritySchemeLibrary securitySchemeLibrary = model.getSecuritySchemesLibrary(); if (securitySchemeLibrary != null && securitySchemeLibrary.getName() != null && model.getName() != null) { QualifiedName importedNamespace = QualifiedName.create(model.getName(), securitySchemeLibrary.getName()); return Optional.of(importedNamespace);
private JsonNode createMetadata(ZenModel model) { ObjectNode root = newObjectNode(); ObjectNode modelNode = root.putObject("models").putObject(model.getName()); ObjectNode dmsNode = modelNode.putObject("dataModels"); for (DataModel dm : model.getDataModels()) { dmsNode.set(dm.getName(), createDataModelMetadata(dm)); } return root; }
private CharSequence generateXsdNamespaceDeclarations(final ZenModel zenModel) { StringConcatenation _builder = new StringConcatenation(); { EList<DataModel> _dataModels = zenModel.getDataModels(); for(final DataModel interfaceDataModel : _dataModels) { Object _generateNamespaceDeclaration = this.generateNamespaceDeclaration(interfaceDataModel); _builder.append(_generateNamespaceDeclaration); _builder.newLineIfNotEmpty(); } } { EList<ResourceAPI> _resourceAPIs = zenModel.getResourceAPIs(); for(final ResourceAPI resourceAPI : _resourceAPIs) { CharSequence _generateNamespaceDeclaration_1 = this.generateNamespaceDeclaration(resourceAPI); _builder.append(_generateNamespaceDeclaration_1); _builder.newLineIfNotEmpty(); } } return _builder; }
_builder.newLine(); EList<ResourceAPI> _resourceAPIs = model.getResourceAPIs(); for(final ResourceAPI resourceAPI : _resourceAPIs) { _builder.append(" "); EList<DataModel> _dataModels = model.getDataModels(); for(final DataModel dataModel : _dataModels) { _builder.append(" "); Documentation _documentation = model.getDocumentation(); boolean _tripleNotEquals = (_documentation != null); if (_tripleNotEquals) {
@Check public void checkDataModelNameUniqueness(ZenModel model) { Set<String> names = Sets.newHashSet(); for (DataModel dataModel : model.getDataModels()) { if (names.contains(dataModel.getName())) { error(String.format("Duplicate name of data model '%s'", dataModel.getName()), dataModel, RapidmlPackage.Literals.DATA_MODEL__NAME); } names.add(dataModel.getName()); } }
public ArrayList<SecurityScheme> getAllUsedSecuritySchemes(final ZenModel model) { final ArrayList<SecurityScheme> result = Lists.<SecurityScheme>newArrayList(); SecuritySchemeLibrary _securitySchemesLibrary = model.getSecuritySchemesLibrary(); boolean _tripleNotEquals = (_securitySchemesLibrary != null); if (_tripleNotEquals) { result.addAll(model.getSecuritySchemesLibrary().getSecuritySchemes()); } final Function1<HasSecurityValue, EList<AuthenticationMethod>> _function = (HasSecurityValue it) -> { return it.getSecuredBy(); }; final Consumer<AuthenticationMethod> _function_1 = (AuthenticationMethod it) -> { result.add(it.getScheme()); }; Iterables.<AuthenticationMethod>concat(ListExtensions.<HasSecurityValue, EList<AuthenticationMethod>>map(IteratorExtensions.<HasSecurityValue>toList(Iterators.<HasSecurityValue>filter(model.eAllContents(), HasSecurityValue.class)), _function)).forEach(_function_1); return result; }
public boolean hasSecuritySchemes(final ZenModel model) { boolean _xblockexpression = false; { final SecuritySchemeLibrary library = model.getSecuritySchemesLibrary(); boolean _xifexpression = false; if ((library != null)) { boolean _isEmpty = library.getSecuritySchemes().isEmpty(); _xifexpression = (!_isEmpty); } else { _xifexpression = false; } _xblockexpression = _xifexpression; } return _xblockexpression; } }
@Override protected IScope getLocalElementsScope(IScope parent, final EObject context, final EReference reference) { IScope local = super.getLocalElementsScope(parent, context, reference); Optional<QualifiedName> localElementsQN = getLocalElementsQualifiedName(context, reference); if (localElementsQN.isPresent()) { QualifiedName importedNamespace = localElementsQN.get(); ZenModel model = context instanceof ZenModel ? (ZenModel) context : RapidmlModelUtils.getZenModel(context); if (!Strings.isEmpty(model.getNamespace())) { importedNamespace = qualifiedNameConverter.toQualifiedName(model.getNamespace()) .append(importedNamespace); } List<ImportNormalizer> namespaceResolvers = singletonList( new ImportNormalizer(importedNamespace, true, isIgnoreCase(reference))); ImportScope importScope = new ImportScope(namespaceResolvers, local, null, reference.getEReferenceType(), isIgnoreCase(reference)); return importScope; } return local; }
@Check public void checkImportDeclarationUnique(ZenModel model) { HashSet<String> aliases = new HashSet<>(); HashSet<String> namespaces = new HashSet<>(); for (ImportDeclaration importDecl : model.getImports()) { if (!Strings.isNullOrEmpty(importDecl.getAlias()) && !aliases.add(importDecl.getAlias())) { error(NLS.bind(Messages.XtextDslJavaValidator_duplicateAlias, importDecl.getAlias()), importDecl, RapidmlPackage.Literals.IMPORT_DECLARATION__ALIAS); } if (!Strings.isNullOrEmpty(importDecl.getImportedNamespace()) && !namespaces.add(importDecl.getImportedNamespace())) { error(NLS.bind(Messages.XtextDslJavaValidator_duplicateNamespace, importDecl.getImportedNamespace()), importDecl, RapidmlPackage.Literals.IMPORT_DECLARATION__IMPORTED_NAMESPACE); } } }
public void validate(ZenModel model) throws IllegalArgumentException { if (rootNamespace == null) { rootNamespace = model.getName(); } checkValidName(rootNamespace, "rootNamespace"); checkValidFolder(modelsFolder, "modelsFolder"); checkValidFolder(controllersFolder, "controllersFolder"); checkValidFramework(framework); }
public void generateAutoRealizations(ZenModel model) { for (ResourceAPI resourceAPI : model.getResourceAPIs()) { new RealizationProcessor(resourceAPI).generateAutoRealizations(); } }
@Override public void generate(ZenModel model) throws GenerationException { String metadataFile = String.format("%s_metadata.yaml", model.getName()); generateFile(metadataFile, new MetadataGenerator(model)); if (context.getGenTargetParameters().get("genMetadataSkeleton") == Boolean.TRUE) { String skeletonFile = String.format("%s_metadata-skel.yaml", model.getName()); Object structSkel = context.getGenTargetParameters().get("structMetadataSkeleton"); Object primSkel = context.getGenTargetParameters().get("primFieldMetadataSkeleton"); Object refSkel = context.getGenTargetParameters().get("refFieldMetadataSkeleton"); if (!(context.getGenTargetParameters().get("omitFieldsWithoutSkeletons") == Boolean.TRUE)) { primSkel = primSkel == null ? emptyObject : primSkel; refSkel = primSkel == null ? emptyObject : refSkel; } generateFile(skeletonFile, new MetadataSkeletonGenerator(model, structSkel, primSkel, refSkel)); } for (ResourceAPI api : model.getResourceAPIs()) { for (ResourceDefinition resource : api.getOwnedResourceDefinitions()) { if (resource instanceof ServiceDataResource) { String resourcePath = String.format("handlers/%s/%s/%s.js", model.getName(), api.getName(), resource.getName()); generateFile(resourcePath, new ResourceStubGenerator((ServiceDataResource) resource)); String customPath = String.format("custom/%s/%s/%sImpl.js", model.getName(), api.getName(), resource.getName()); generateFile(customPath, new CustomCodeGenerator((ServiceDataResource) resource), false); } } } generateFile("app.js", new AppGenerator(metadataFile, context)); }
@Override public String generate() throws GenerationException { ObjectNode root = newObjectNode(); ObjectNode dataModelRoot = root.putObject("models").putObject(model.getName()).putObject("dataModels"); for (DataModel dm : model.getDataModels()) { ObjectNode structsRoot = dataModelRoot.putObject(dm.getName()).putObject("structures"); for (DataType s : dm.getOwnedDataTypes()) {
public static NameHelper forModel(final ZenModel model) { NameHelper _xblockexpression = null; { String _namespace = model.getNamespace(); String _plus = (_namespace + "."); String _name = model.getName(); final String qname = (_plus + _name); NameHelper _elvis = null; NameHelper _get = NameHelper.helpers.get(qname); if (_get != null) { _elvis = _get; } else { NameHelper _xblockexpression_1 = null; { final NameHelper helper = new NameHelper(); NameHelper.helpers.put(qname, helper); _xblockexpression_1 = helper; } _elvis = _xblockexpression_1; } _xblockexpression = _elvis; } return _xblockexpression; }