@@ -0,0 +1,3725 @@
+package org.apache.taverna.mobile.data.local;%0A%0A%0Aimport com.raizlabs.android.dbflow.sql.language.SQLite;%0A%0Aimport org.apache.taverna.mobile.data.model.Workflow;%0Aimport org.apache.taverna.mobile.data.model.Workflow_Table;%0Aimport org.apache.taverna.mobile.data.model.Workflows;%0A%0Aimport android.support.annotation.Nullable;%0A%0Aimport rx.Observable;%0Aimport rx.Subscriber;%0A%0A%0Apublic class DBHelper %7B%0A%0A%0A    public DBHelper() %7B%0A%0A    %7D%0A%0A    @Nullable%0A    public Observable%3CWorkflows%3E syncWorkflows(final Workflows workflows) %7B%0A        return Observable.create(new Observable.OnSubscribe%3CWorkflows%3E() %7B%0A            @Override%0A            public void call(Subscriber%3C? super Workflows%3E subscriber) %7B%0A                if (subscriber.isUnsubscribed()) return;%0A                for (Workflow workflow : workflows.getWorkflowList()) %7B%0A                    if (!workflow.exists()) %7B%0A                        workflow.save();%0A                    %7D else %7B%0A                        updateWorkflow(workflow).save();%0A                    %7D%0A%0A                %7D%0A                subscriber.onNext(workflows);%0A                subscriber.onCompleted();%0A            %7D%0A        %7D);%0A    %7D%0A%0A    private Workflow updateWorkflow(Workflow workflow) %7B%0A        Workflow workflow1 = SQLite.select()%0A                .from(Workflow.class)%0A                .where(Workflow_Table.id.eq(workflow.getId()))%0A                .querySingle();%0A        if (workflow1 != null) %7B%0A            if (workflow.getDescription() == null %7C%7C !workflow.getDescription().equals(workflow1.getDescription())) %7B%0A%0A                workflow1.setDescription(workflow.getDescription());%0A            %7D%0A            if (workflow.getUpdatedAt() == null %7C%7C !workflow.getUpdatedAt().equals(workflow1.getUpdatedAt())) %7B%0A%0A                workflow1.setUpdatedAt(workflow.getUpdatedAt());%0A            %7D%0A            if (workflow.getSvgUri() == null %7C%7C !workflow.getSvgUri().equals(workflow1.getSvgUri())) %7B%0A%0A                workflow1.setSvgUri(workflow.getSvgUri());%0A            %7D%0A            if (workflow.getLicenseType() == null %7C%7C !workflow.getLicenseType().equals(workflow1.getLicenseType())) %7B%0A%0A                workflow1.setLicenseType(workflow.getLicenseType());%0A            %7D%0A            if (workflow.getContentUri() == null %7C%7C !workflow.getContentUri().equals(workflow1.getContentUri())) %7B%0A%0A                workflow1.setContentUri(workflow.getContentUri());%0A            %7D%0A            if (workflow.getContentType() == null %7C%7C !workflow.getContentType().equals(workflow1.getContentType())) %7B%0A%0A                workflow1.setContentUri(workflow.getContentType());%0A            %7D%0A%0A            workflow1.setTitle(workflow.getTitle());%0A            workflow1.setType(workflow.getType());%0A            workflow1.setUploader(workflow.getUploader());%0A            workflow1.setPreviewUri(workflow.getPreviewUri());%0A            workflow1.setCreatedAt(workflow.getCreatedAt());%0A            workflow1.setResource(workflow.getResource());%0A            workflow1.setUri(workflow.getUri());%0A            workflow1.setId(workflow.getId());%0A            workflow1.setVersion(workflow.getVersion());%0A%0A        %7D%0A        return workflow;%0A    %7D%0A%0A%0A    public Observable%3CWorkflow%3E syncWorkflow(final Workflow workflow) %7B%0A        return Observable.create(new Observable.OnSubscribe%3CWorkflow%3E() %7B%0A            @Override%0A            public void call(Subscriber%3C? super Workflow%3E subscriber) %7B%0A                if (subscriber.isUnsubscribed()) return;%0A                workflow.getType().save();%0A                workflow.getUploader().save();%0A                workflow.getLicenseType().save();%0A                workflow.save();%0A                subscriber.onNext(workflow);%0A                subscriber.onCompleted();%0A            %7D%0A        %7D);%0A    %7D%0A%0A%0A%7D%0A%0A

add DB helper layer