public bool Match(ClassModel domainModel, OperationModel operationModel)
        {
            if (operationModel.Parameters.Count() != 1)
            {
                return(false);
            }

            if (operationModel.TypeReference.Element != null && !_decorator.Template.GetTypeInfo(operationModel.TypeReference).IsPrimitive)
            {
                return(false);
            }

            var lowerDomainName    = domainModel.Name.ToLower();
            var lowerOperationName = operationModel.Name.ToLower();

            return(new[]
            {
                "post",
                $"post{lowerDomainName}",
                "create",
                $"create{lowerDomainName}",
                $"add{lowerDomainName}",
            }
                   .Contains(lowerOperationName));
        }
Esempio n. 2
0
        public bool Match(ClassModel domainModel, OperationModel operationModel)
        {
            if (operationModel.Parameters.Any())
            {
                return(false);
            }

            if (!(operationModel?.TypeReference?.IsCollection ?? false))
            {
                return(false);
            }

            var lowerDomainName       = domainModel.Name.ToLower();
            var pluralLowerDomainName = lowerDomainName.Pluralize();
            var lowerOperationName    = operationModel.Name.ToLower();

            return(new[]
            {
                $"get",
                $"get{lowerDomainName}",
                $"get{pluralLowerDomainName}",
                $"get{pluralLowerDomainName}list",
                $"getall",
                $"getall{pluralLowerDomainName}",
                $"find",
                $"find{lowerDomainName}",
                $"find{pluralLowerDomainName}",
                "findall"
            }
                   .Contains(lowerOperationName));
        }
Esempio n. 3
0
        public string GetImplementation(ClassModel domainModel, OperationModel operationModel)
        {
            var dto = operationModel.TypeReference.Element.AsDTOModel();

            return($@"var {domainModel.Name.ToCamelCase().ToPluralName()} = {domainModel.Name.ToCamelCase()}Repository.findAll();
        return {_decorator.Template.GetDataTransferModelName(dto)}.mapFrom{domainModel.Name.ToPluralName()}({domainModel.Name.ToCamelCase().ToPluralName()}, mapper);");
        }
        public bool Match(ClassModel domainModel, OperationModel operationModel)
        {
            var lowerDomainName    = domainModel.Name.ToLower();
            var lowerOperationName = operationModel.Name.ToLower();

            if (operationModel.Parameters.Count() != 2)
            {
                return(false);
            }

            if (!operationModel.Parameters.Any(p => string.Equals(p.Name, "id", StringComparison.InvariantCultureIgnoreCase) ||
                                               string.Equals(p.Name, $"{lowerDomainName}Id", StringComparison.InvariantCultureIgnoreCase)))
            {
                return(false);
            }

            if (operationModel.TypeReference.Element != null)
            {
                return(false);
            }

            return(new[]
            {
                "put",
                $"put{lowerDomainName}",
                "update",
                $"update{lowerDomainName}",
            }
                   .Contains(lowerOperationName));
        }
        public bool Match(ClassModel domainModel, OperationModel operationModel)
        {
            var entityName         = domainModel.Name.ToLower();
            var lowerOperationName = operationModel.Name.ToLower();

            if (operationModel.Parameters.Count() != 1)
            {
                return(false);
            }

            if (!operationModel.Parameters.Any(p => string.Equals(p.Name, "id", StringComparison.InvariantCultureIgnoreCase) ||
                                               string.Equals(p.Name, $"{entityName}Id", StringComparison.InvariantCultureIgnoreCase)))
            {
                return(false);
            }

            if (operationModel?.TypeReference?.IsCollection ?? false)
            {
                return(false);
            }


            return(new[]
            {
                "get",
                $"get{entityName}",
                "find",
                "findbyid",
                $"find{entityName}",
                $"find{entityName}byid",
                entityName
            }
                   .Contains(lowerOperationName));
        }
        public string GetImplementation(ClassModel domainModel, OperationModel operationModel)
        {
            var idParam  = operationModel.Parameters.First(p => p.Name.EndsWith("id", StringComparison.OrdinalIgnoreCase));
            var dtoParam = operationModel.Parameters.First(p => !p.Name.EndsWith("id", StringComparison.OrdinalIgnoreCase));

            return($@"var {domainModel.Name.ToCamelCase()} = {domainModel.Name.ToCamelCase()}Repository.findById({idParam.Name}).get();
        {EmitPropertyAssignments(domainModel, domainModel.Name.ToCamelCase(), dtoParam)}
        { domainModel.Name.ToCamelCase() }Repository.save({domainModel.Name.ToCamelCase()});");
        }
        public string GetImplementation(ClassModel domainModel, OperationModel operationModel)
        {
            var dto = operationModel.TypeReference.Element.AsDTOModel();

            return($@"var {domainModel.Name.ToCamelCase()} = {domainModel.Name.ToCamelCase()}Repository.findById({operationModel.Parameters.First().Name.ToCamelCase()});
        if (!{domainModel.Name.ToCamelCase()}.isPresent()) {{
            return null;
        }}
        return {_decorator.Template.GetDataTransferModelName(dto)}.mapFrom{domainModel.Name.ToPascalCase()}({domainModel.Name.ToCamelCase()}.get(), mapper);");
        }
        public override string GetDecoratedImplementation(OperationModel operationModel)
        {
            if (_targetEntity == null)
            {
                return(string.Empty);
            }

            foreach (var strategy in _strategies)
            {
                if (strategy.Match(_targetEntity, operationModel))
                {
                    return(strategy.GetImplementation(_targetEntity, operationModel));
                }
            }

            return(string.Empty);
        }
        private string GetUpdateUrl(ProxyOperationModel operation)
        {
            var mappedOperation = new OperationModel((IElement)operation.Mapping.Element);

            if (mappedOperation?.Parameters.Count != operation.Parameters.Count)
            {
                throw new Exception($"Different number of properties for mapped operation [{operation.Name}] on {ServiceProxyModel.SpecializationType} [{Model.Name}]");
            }

            var path          = GetPath(operation);
            var urlParameters = mappedOperation.Parameters.Where(x => !IsComplexObject(x.Type.Element) &&
                                                                 !path.Contains($"${{{x.Name.ToCamelCase()}}}")).ToList();

            if (!urlParameters.Any())
            {
                return("");
            }

            return($@"
        url = `${{url}}?{string.Join("&", urlParameters.Select((x, index) => $"{x.Name.ToCamelCase()}=${{{operation.Parameters[index].Name.ToCamelCase()}}}"))}`;");
        }
        public string GetImplementation(ClassModel domainModel, OperationModel operationModel)
        {
            var entityName = _decorator.Template.GetTypeName(DomainModelTemplate.TemplateId, domainModel, new TemplateDiscoveryOptions()
            {
                ThrowIfNotFound = false
            });
            var statements = new List <string>();

            statements.Add($"var {domainModel.Name.ToCamelCase()} = new {entityName ?? domainModel.Name}();");

            statements.AddRange(GetPropertyAssignments(domainModel, operationModel.Parameters.Single()));

            statements.Add($"{ domainModel.Name.ToCamelCase() }Repository.save({domainModel.Name.ToCamelCase()});");

            if (operationModel.TypeReference.Element != null)
            {
                statements.Add($"{ domainModel.Name.ToCamelCase()}.getId();");
            }

            return(string.Join(@"
        ", statements));
        }
 public bool Equals(OperationModel other)
 {
     return(Equals(_element, other?._element));
 }