{% for method in swagger_data.crud %}
{% if 'param' in swagger_data.attr_classes_crud[method] %}
{% if 'response' in swagger_data.attr_classes_crud[method] %}
    public boolean {{method}}{{swagger_data.name|class_name_syntax}}({{(swagger_data.attr_classes_crud[method])["param"]|class_name_syntax}}Attr attr, final {{swagger_data.name|class_name_syntax}}Listener listener) throws OcException {
        OcRepresentation rep = attr.pack();
        if({{swagger_data.name|java_instance_variable_syntax}} == null) return false;
        {{swagger_data.name|java_instance_variable_syntax}}.{{method}}(rep, new HashMap<>(), new OnPostListener() {
               @Override
               public void onPostCompleted(List<OcHeaderOption> headerOptionList,
                   OcRepresentation ocRepresentation) {
{% if isForIoTSys[0] %}
                   mExecutor.execute(() -> {
{% else %}
                   mExecutor.execute(() -> {
{% endif %}
                       if(listener != null) {
                        try {
                          {{(swagger_data.attr_classes_crud[method])["response"]|class_name_syntax}}Attr outAttribute = new {{(swagger_data.attr_classes_crud[method])["response"]|class_name_syntax}}Attr();
                          outAttribute.unpack(ocRepresentation);
                          listener.On{{(swagger_data.attr_classes_crud[method])["response"]|class_name_syntax}}Completed(outAttribute, true);
                        } catch(OcException | NullPointerException e) {
                          listener.On{{(swagger_data.attr_classes_crud[method])["response"]|class_name_syntax}}Completed(null, false);
                          e.printStackTrace();
                        }
                      }
                   });
               }

               @Override
               public void onPostFailed(Throwable ex) {
                    ex.printStackTrace();
{% if isForIoTSys[0] %}
                   mExecutor.execute(() ->
{% else %}
                   mExecutor.execute(() ->
{% endif %}
                        listener.On{{(swagger_data.attr_classes_crud[method])["response"]|class_name_syntax}}Completed(null, false)
                    );
               }

             }, DEFAULT_QoS);
        return true;
    }

{% else %}
    public boolean {{method}}{{swagger_data.name|class_name_syntax}}({{(swagger_data.attr_classes_crud[method])["param"]|class_name_syntax}}Attr attr, final {{swagger_data.name|class_name_syntax}}Listener listener) throws OcException {
        OcRepresentation rep = attr.pack();
        if({{swagger_data.name|java_instance_variable_syntax}} == null) return false;
        {{swagger_data.name|java_instance_variable_syntax}}.{{method}}(rep, new HashMap<>(), new OnPostListener() {
               @Override
               public void onPostCompleted(List<OcHeaderOption> headerOptionList,
                   OcRepresentation ocRepresentation) {
{% if isForIoTSys[0] %}
                   mExecutor.execute(() -> {
{% else %}
                   mExecutor.execute(() -> {
{% endif %}
                       if(listener != null) {
                         listener.On{{(swagger_data.attr_classes_crud[method])["param"]|class_name_syntax}}Completed(true);
                       }
                   });
               }

               @Override
               public void onPostFailed(Throwable ex) {
                   ex.printStackTrace();
{% if isForIoTSys[0] %}
                   mExecutor.execute(() ->
{% else %}
                   mExecutor.execute(() ->
{% endif %}
                    listener.On{{(swagger_data.attr_classes_crud[method])["param"]|class_name_syntax}}Completed(false)
                   );
               }

             }, DEFAULT_QoS);
        return true;
    }

{% endif %}
{% else %}
{% if 'response' in swagger_data.attr_classes_crud[method] %}
    public boolean {{method}}{{swagger_data.name|class_name_syntax}}WithCompletion(final {{swagger_data.name|class_name_syntax}}Listener listener) throws OcException {
{% if 'get' in method %}
        if({{swagger_data.name|java_instance_variable_syntax}} == null) return false;
        {{swagger_data.name|java_instance_variable_syntax}}.get(new HashMap<>(), new OnGetListener() {
              @Override
              public void onGetCompleted(List<OcHeaderOption> headerOptionList,
                  OcRepresentation ocRepresentation) {

{% if isForIoTSys[0] %}
                   mExecutor.execute(() -> {
{% else %}
                   mExecutor.execute(() -> {
{% endif %}
                      boolean isAvailable;
                      try{
                          {{(swagger_data.attr_classes_crud[method])["response"]|class_name_syntax}}Attr outAttribute = new {{(swagger_data.attr_classes_crud[method])["response"]|class_name_syntax}}Attr();
                          outAttribute.unpack(ocRepresentation);
                          listener.On{{method|variable_syntax(True,True)}}{{swagger_data.name|class_name_syntax}}Completed(outAttribute,true);
                          isAvailable = true;
                      } catch(OcException | NullPointerException e ) {
                          e.printStackTrace();
                          isAvailable = false;
                          listener.On{{method|variable_syntax(True,True)}}{{swagger_data.name|class_name_syntax}}Completed(null,false);
                      }
{% if swagger_data.prop != 0 %}
                      {{swagger_data.name|java_instance_variable_syntax}}.setResourceAvailable(isAvailable);
{% endif %}
                  });
              }

              @Override
              public void onGetFailed(Throwable ex) {
                  ex.printStackTrace();
{% if isForIoTSys[0] %}
                   mExecutor.execute(() -> {
{% else %}
                   mExecutor.execute(() -> {
{% endif %}
{% if swagger_data.prop != 0 %}
                   {{swagger_data.name|java_instance_variable_syntax}}.setResourceAvailable(false);
{% endif %}

                    listener.On{{method|variable_syntax(True,True)}}{{swagger_data.name|class_name_syntax}}Completed(null,false);
                  });
              }
        } , DEFAULT_QoS);
        return true;
{% else %}
        if({{swagger_data.name|java_instance_variable_syntax}} == null) return false;
        {{swagger_data.name|java_instance_variable_syntax}}.post(new HashMap<>(), new OnPostListener() {
              @Override
              public void onPostCompleted(List<OcHeaderOption> headerOptionList,
                  OcRepresentation ocRepresentation) {
{% if isForIoTSys[0] %}
                   mExecutor.execute(() -> {
{% else %}
                   mExecutor.execute(() -> {
{% endif %}
                      try{
                          {{(swagger_data.attr_classes_crud[method])["response"]|class_name_syntax}}Attr outAttribute = new {{(swagger_data.attr_classes_crud[method])["response"]|class_name_syntax}}Attr();
                          outAttribute.unpack(ocRepresentation);
                          listener.On{{(swagger_data.attr_classes_crud[method])["response"]|class_name_syntax}}Completed(outAttribute,true);
                      } catch(OcException | NullPointerException e) {
                          listener.On{{(swagger_data.attr_classes_crud[method])["response"]|class_name_syntax}}Completed(null,false);
                      }
                  });
              }

              @Override
              public void onPostFailed(Throwable ex) {
                ex.printStackTrace();
{% if isForIoTSys[0] %}
                   mExecutor.execute(() ->
{% else %}
                   mExecutor.execute(() ->
{% endif %}
                    listener.On{{(swagger_data.attr_classes_crud[method])["response"]|class_name_syntax}}Completed(null, false)
                );
              }

              }
        } , DEFAULT_QoS);
        return true;
{% endif %}

    }

{% else %}
    public boolean {{method}}{{swagger_data.name|class_name_syntax}}WithCompletion(final {{swagger_data.name|class_name_syntax}}Listener listener) throws OcException {

       if({{swagger_data.name|java_instance_variable_syntax}} == null) return false;
       {{swagger_data.name|java_instance_variable_syntax}}.post(new OcRepresentation(), new HashMap<>(), new OnPostListener() {
              @Override
              public void onPostCompleted(List<OcHeaderOption> headerOptionList,
                  OcRepresentation ocRepresentation) {
{% if isForIoTSys[0] %}
                   mExecutor.execute(() ->
{% else %}
                   mExecutor.execute(() ->
{% endif %}
                    listener.On{{method|variable_syntax(True,True)}}{{swagger_data.name|class_name_syntax}}Completed(true)
                  );

              }

              @Override
              public void onPostFailed(Throwable ex) {
                ex.printStackTrace();
{% if isForIoTSys[0] %}
                   mExecutor.execute(() ->
{% else %}
                   mExecutor.execute(() ->
{% endif %}
                    listener.On{{method|variable_syntax(True,True)}}{{swagger_data.name|class_name_syntax}}Completed(false)
                );
              }
        } , DEFAULT_QoS);
        return true;
    }

{% endif %}
{% endif %}
{% endfor %}