Search in sources :

Example 1 with RESTSpecification

use of org.applause.lang.applauseDsl.RESTSpecification in project applause by applause.

the class RESTURLsRelativeRESTURLsSpec method dataSourceAccessMethodUrlShouldBe.

public void dataSourceAccessMethodUrlShouldBe(final CharSequence sequence, final String url) {
    try {
        final Model model = this._parseHelper.parse(sequence);
        EList<NamedElement> _elements = model.getElements();
        Iterable<DataSource> _filter = Iterables.<DataSource>filter(_elements, DataSource.class);
        final DataSource datasource = IterableExtensions.<DataSource>head(_filter);
        EList<DataSourceAccessMethod> _methods = datasource.getMethods();
        final DataSourceAccessMethod method = IterableExtensions.<DataSourceAccessMethod>head(_methods);
        RESTSpecification _restSpecification = method.getRestSpecification();
        RESTURL _path = _restSpecification.getPath();
        String _value = this._rESTURLExtensions.value(_path);
        Matcher<String> _is = CoreMatchers.<String>is(url);
        Assert.<String>assertThat(_value, _is);
    } catch (Throwable _e) {
        throw Exceptions.sneakyThrow(_e);
    }
}
Also used : DataSourceAccessMethod(org.applause.lang.applauseDsl.DataSourceAccessMethod) RESTSpecification(org.applause.lang.applauseDsl.RESTSpecification) Model(org.applause.lang.applauseDsl.Model) NamedElement(org.applause.lang.applauseDsl.NamedElement) RESTURL(org.applause.lang.applauseDsl.RESTURL) DataSource(org.applause.lang.applauseDsl.DataSource)

Example 2 with RESTSpecification

use of org.applause.lang.applauseDsl.RESTSpecification in project applause by applause.

the class EntityDataAccessModuleFileCompiler method compileGETLISTMethod.

public CharSequence compileGETLISTMethod(final DataSourceAccessMethod it) {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("static NSString *const ");
    String _urlConstantForRESTMethod = this.urlConstantForRESTMethod(it);
    _builder.append(_urlConstantForRESTMethod, "");
    _builder.append(" = @\"");
    RESTSpecification _restSpecification = it.getRestSpecification();
    RESTURL _path = _restSpecification.getPath();
    String _value = this._rESTURLExtensions.value(_path);
    _builder.append(_value, "");
    _builder.append("\";");
    _builder.newLineIfNotEmpty();
    _builder.newLine();
    _builder.append("+ (void)");
    String _name = it.getName();
    _builder.append(_name, "");
    _builder.append(":(void (^)(NSArray *");
    Entity _resourceType = this._entityDataAccessExtensions.resourceType(it);
    String _parameterName = this._entityDataAccessExtensions.parameterName(_resourceType);
    String _plural = this._entityDataAccessExtensions.plural(_parameterName);
    _builder.append(_plural, "");
    _builder.append(", NSError *error))block");
    _builder.newLineIfNotEmpty();
    _builder.append("{");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("[[");
    Entity _resourceType_1 = this._entityDataAccessExtensions.resourceType(it);
    String _apiClientClassName = this._aPIClientClassExtensions.apiClientClassName(_resourceType_1);
    _builder.append(_apiClientClassName, "	");
    _builder.append(" sharedClient] GET:");
    String _urlConstantForRESTMethod_1 = this.urlConstantForRESTMethod(it);
    _builder.append(_urlConstantForRESTMethod_1, "	");
    _builder.append(" parameters:nil success:^(NSURLSessionDataTask *task, id responseObject)");
    _builder.newLineIfNotEmpty();
    _builder.append("\t");
    _builder.append("{");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("NSArray *elementsFromJSON = responseObject;");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("NSMutableArray *result = [[NSMutableArray alloc] initWithCapacity:[elementsFromJSON count]];");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("for (NSDictionary *attributes in elementsFromJSON) {");
    _builder.newLine();
    _builder.append("\t\t\t");
    Entity _resourceType_2 = this._entityDataAccessExtensions.resourceType(it);
    String _typeName = this._typeExtensions.typeName(_resourceType_2);
    _builder.append(_typeName, "			");
    _builder.append(" *mappedElement = [[");
    Entity _resourceType_3 = this._entityDataAccessExtensions.resourceType(it);
    String _typeName_1 = this._typeExtensions.typeName(_resourceType_3);
    _builder.append(_typeName_1, "			");
    _builder.append(" alloc] initWithAttributes:attributes];");
    _builder.newLineIfNotEmpty();
    _builder.append("\t\t\t");
    _builder.append("[result addObject:mappedElement];");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("}");
    _builder.newLine();
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("if (block) {");
    _builder.newLine();
    _builder.append("\t\t\t");
    _builder.append("block([result copy], nil);");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("}");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("} failure:^(NSURLSessionDataTask *task, NSError *error)");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("{");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("if (block) {");
    _builder.newLine();
    _builder.append("\t\t\t");
    _builder.append("block(@[], error);");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("}");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("}];");
    _builder.newLine();
    _builder.append("}");
    _builder.newLine();
    return _builder;
}
Also used : Entity(org.applause.lang.applauseDsl.Entity) RESTSpecification(org.applause.lang.applauseDsl.RESTSpecification) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) RESTURL(org.applause.lang.applauseDsl.RESTURL)

Example 3 with RESTSpecification

use of org.applause.lang.applauseDsl.RESTSpecification in project applause by applause.

the class EntityDataAccessModuleFileCompiler method compileDELETEMethod.

public CharSequence compileDELETEMethod(final DataSourceAccessMethod it) {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("static NSString *const ");
    String _urlConstantForRESTMethod = this.urlConstantForRESTMethod(it);
    _builder.append(_urlConstantForRESTMethod, "");
    _builder.append(" = @\"");
    RESTSpecification _restSpecification = it.getRestSpecification();
    RESTURL _path = _restSpecification.getPath();
    String _value = this._rESTURLExtensions.value(_path);
    _builder.append(_value, "");
    _builder.append("\";");
    _builder.newLineIfNotEmpty();
    _builder.newLine();
    _builder.append("- (void)");
    String _name = it.getName();
    _builder.append(_name, "");
    _builder.append(":(void (^)(");
    String _parameterList = this._entityDataAccessExtensions.parameterList(it);
    _builder.append(_parameterList, "");
    _builder.append(", NSError *error))block");
    _builder.newLineIfNotEmpty();
    _builder.append("{");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("NSString *urlString = [NSString stringWithFormat:");
    String _urlConstantForRESTMethod_1 = this.urlConstantForRESTMethod(it);
    _builder.append(_urlConstantForRESTMethod_1, "	");
    _builder.append(", self.id];");
    _builder.newLineIfNotEmpty();
    _builder.append("\t");
    _builder.append("[[");
    Entity _resourceType = this._entityDataAccessExtensions.resourceType(it);
    String _apiClientClassName = this._aPIClientClassExtensions.apiClientClassName(_resourceType);
    _builder.append(_apiClientClassName, "	");
    _builder.append(" sharedClient] DELETE:urlString parameters:nil success:^(NSURLSessionDataTask *task, id responseObject)");
    _builder.newLineIfNotEmpty();
    _builder.append("\t");
    _builder.append("{");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("if(block) {");
    _builder.newLine();
    _builder.append("\t\t\t");
    _builder.append("block(self, nil);");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("}");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("} failure:^(NSURLSessionDataTask *task, NSError *error)");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("{");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("if(block) {");
    _builder.newLine();
    _builder.append("\t\t\t");
    _builder.append("block(nil, error);");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("}");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("}];");
    _builder.newLine();
    _builder.append("}");
    _builder.newLine();
    return _builder;
}
Also used : Entity(org.applause.lang.applauseDsl.Entity) RESTSpecification(org.applause.lang.applauseDsl.RESTSpecification) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) RESTURL(org.applause.lang.applauseDsl.RESTURL)

Example 4 with RESTSpecification

use of org.applause.lang.applauseDsl.RESTSpecification in project applause by applause.

the class EntityDataAccessModuleFileCompiler method compilePOSTMethod.

public CharSequence compilePOSTMethod(final DataSourceAccessMethod it) {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("static NSString *const ");
    String _urlConstantForRESTMethod = this.urlConstantForRESTMethod(it);
    _builder.append(_urlConstantForRESTMethod, "");
    _builder.append(" = @\"");
    RESTSpecification _restSpecification = it.getRestSpecification();
    RESTURL _path = _restSpecification.getPath();
    String _value = this._rESTURLExtensions.value(_path);
    _builder.append(_value, "");
    _builder.append("\";");
    _builder.newLineIfNotEmpty();
    _builder.newLine();
    _builder.append("- (void)");
    String _name = it.getName();
    _builder.append(_name, "");
    _builder.append(":(void (^)(");
    String _parameterList = this._entityDataAccessExtensions.parameterList(it);
    _builder.append(_parameterList, "");
    _builder.append(", NSError *error))block");
    _builder.newLineIfNotEmpty();
    _builder.append("{");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("NSDictionary *elementDictionary = [self attributes];");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("[[");
    Entity _resourceType = this._entityDataAccessExtensions.resourceType(it);
    String _apiClientClassName = this._aPIClientClassExtensions.apiClientClassName(_resourceType);
    _builder.append(_apiClientClassName, "	");
    _builder.append(" sharedClient] POST:");
    String _urlConstantForRESTMethod_1 = this.urlConstantForRESTMethod(it);
    _builder.append(_urlConstantForRESTMethod_1, "	");
    _builder.append(" parameters:elementDictionary success:^(NSURLSessionDataTask *task, id responseObject)");
    _builder.newLineIfNotEmpty();
    _builder.append("\t");
    _builder.append("{");
    _builder.newLine();
    _builder.append("\t\t");
    Entity _resourceType_1 = this._entityDataAccessExtensions.resourceType(it);
    String _typeName = this._typeExtensions.typeName(_resourceType_1);
    _builder.append(_typeName, "		");
    _builder.append(" *postedElement = responseObject;");
    _builder.newLineIfNotEmpty();
    _builder.append("\t\t");
    _builder.append("if(block) {");
    _builder.newLine();
    _builder.append("\t\t\t");
    _builder.append("block(postedElement, nil);");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("}");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("} failure:^(NSURLSessionDataTask *task, NSError *error)");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("{");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("if(block) {");
    _builder.newLine();
    _builder.append("\t\t\t");
    _builder.append("block(nil, error);");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("}");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("}];");
    _builder.newLine();
    _builder.append("}");
    _builder.newLine();
    return _builder;
}
Also used : Entity(org.applause.lang.applauseDsl.Entity) RESTSpecification(org.applause.lang.applauseDsl.RESTSpecification) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) RESTURL(org.applause.lang.applauseDsl.RESTURL)

Example 5 with RESTSpecification

use of org.applause.lang.applauseDsl.RESTSpecification in project applause by applause.

the class DefaultDetailsScreenModuleFileCompiler method dataAccessMethodNameForCreate.

public String dataAccessMethodNameForCreate(final Screen it) {
    DataSourceCall _datasource = it.getDatasource();
    DataSource _datasource_1 = _datasource.getDatasource();
    EList<DataSourceAccessMethod> _methods = _datasource_1.getMethods();
    final Function1<DataSourceAccessMethod, Boolean> _function = new Function1<DataSourceAccessMethod, Boolean>() {

        public Boolean apply(final DataSourceAccessMethod it) {
            RESTSpecification _restSpecification = it.getRestSpecification();
            RESTVerb _verb = _restSpecification.getVerb();
            boolean _equals = Objects.equal(_verb, RESTVerb.POST);
            return Boolean.valueOf(_equals);
        }
    };
    DataSourceAccessMethod _findFirst = IterableExtensions.<DataSourceAccessMethod>findFirst(_methods, _function);
    String _name = _findFirst.getName();
    return _name;
}
Also used : DataSourceCall(org.applause.lang.applauseDsl.DataSourceCall) DataSourceAccessMethod(org.applause.lang.applauseDsl.DataSourceAccessMethod) RESTSpecification(org.applause.lang.applauseDsl.RESTSpecification) Function1(org.eclipse.xtext.xbase.lib.Functions.Function1) RESTVerb(org.applause.lang.applauseDsl.RESTVerb) DataSource(org.applause.lang.applauseDsl.DataSource)

Aggregations

RESTSpecification (org.applause.lang.applauseDsl.RESTSpecification)11 RESTURL (org.applause.lang.applauseDsl.RESTURL)5 RESTVerb (org.applause.lang.applauseDsl.RESTVerb)5 DataSource (org.applause.lang.applauseDsl.DataSource)4 DataSourceAccessMethod (org.applause.lang.applauseDsl.DataSourceAccessMethod)4 Entity (org.applause.lang.applauseDsl.Entity)4 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)4 DataSourceCall (org.applause.lang.applauseDsl.DataSourceCall)3 Function1 (org.eclipse.xtext.xbase.lib.Functions.Function1)3 Model (org.applause.lang.applauseDsl.Model)1 NamedElement (org.applause.lang.applauseDsl.NamedElement)1 ENotificationImpl (org.eclipse.emf.ecore.impl.ENotificationImpl)1