Commit 86fa3d9e authored by Alexander Philipp Nowosad's avatar Alexander Philipp Nowosad
Browse files

Add element service interface

parent 3f7bf720
......@@ -48,16 +48,16 @@ export class AppComponent {
}
async printDevelopmentMethods() {
const methods = (
await this.developmentMethodService.getDevelopmentMethodList()
).docs.map((method) => new DevelopmentMethod(method));
const methods = (await this.developmentMethodService.getList()).docs.map(
(method) => new DevelopmentMethod(method)
);
const out = methods.map((method) => method.toPouchDb());
out.forEach((method) => delete method._rev);
console.log(out);
}
async printBmProcesses() {
const processes = (await this.bmProcessService.getBmProcessList()).docs.map(
const processes = (await this.bmProcessService.getList()).docs.map(
(process) => new BmProcess(process)
);
const out = processes.map((process) => process.toPouchDb());
......@@ -66,9 +66,9 @@ export class AppComponent {
}
async printRunningProcesses() {
const processes = (
await this.runningProcessService.getRunningProcessesList()
).docs.map((process) => new RunningProcess(process));
const processes = (await this.runningProcessService.getList()).docs.map(
(process) => new RunningProcess(process)
);
const out = processes.map((process) => process.toPouchDb());
out.forEach((process) => delete process._rev);
console.log(out);
......
......@@ -71,7 +71,7 @@ export class ProcessApiService implements OnDestroy {
private async loadProcessInfo() {
try {
this.runningProcess = await this.runningProcessService.getRunningProcess(
this.runningProcess = await this.runningProcessService.get(
this.stepInfo.runningProcessId
);
} catch (error) {
......
......@@ -62,7 +62,7 @@ export class CompanyModelSelectExpertKnowledgeComponent
}
async loadBmProcess(bmProcessId: string) {
this.bmProcess = await this.bmProcessService.getBmProcess(bmProcessId);
this.bmProcess = await this.bmProcessService.get(bmProcessId);
}
mergeExpertModel(expertModelId: string): void {
......
import { PouchdbModel } from './pouchdb-model';
import { Observable } from 'rxjs';
export interface ElementService<T extends PouchdbModel> {
/**
* Get a list of all elements of this type in the database
*/
getList(): Promise<PouchDB.Find.FindResponse<T>>;
/**
* Add an element to the database
*
* @param element the element to add
*/
add(element: Partial<T>): Promise<any>;
/**
* Update an element in the database
*
* @param id the id of the element
* @param element the new data of the element
*/
update?(id: string, element: Partial<T>): Promise<any>;
/**
* Get an element from the database
*
* @param id the id of the element to get
* @return the element from the database
*/
get(id: string): Promise<T>;
/**
* Get the changes of an element
*
* @param id the id of the element
* @return the changes feed
*/
getChangesFeed(id: string): Observable<any>;
/**
* Remove an element from the database
*
* @param id the id of the element
*/
delete(id: string): Promise<any>;
}
......@@ -7,11 +7,12 @@ import { SituationalFactor } from '../method-elements/situational-factor/situati
import { ModuleService } from '../module-api/module.service';
import { Decision } from './decision';
import { Observable } from 'rxjs';
import { ElementService } from '../../database/element-service';
@Injectable({
providedIn: DevelopmentProcessRegistryModule,
})
export class BmProcessService {
export class BmProcessService implements ElementService<BmProcess> {
constructor(
private moduleService: ModuleService,
private pouchdbService: PouchdbService
......@@ -20,7 +21,7 @@ export class BmProcessService {
/**
* Get the list of the bm processes.
*/
getBmProcessList() {
getList() {
return this.pouchdbService.find<BmProcess>(BmProcess.typeName, {
selector: {},
});
......@@ -29,10 +30,10 @@ export class BmProcessService {
/**
* Add new bm process.
*
* @param name name of the bm process
* @param element the bm process
*/
addBmProcess(name: string) {
return this.pouchdbService.post(new BmProcess({ name }));
add(element: Partial<BmProcess>) {
return this.pouchdbService.post(new BmProcess(element));
}
/**
......@@ -41,8 +42,8 @@ export class BmProcessService {
* @param id id of the bm process
* @param bmProcess the new values of the object (values will be copied)
*/
updateBmProcess(id: string, bmProcess: Partial<BmProcess>) {
return this.getBmProcess(id).then((process) => {
update(id: string, bmProcess: Partial<BmProcess>) {
return this.get(id).then((process) => {
process.update(bmProcess);
return this.saveBmProcess(process);
});
......@@ -53,7 +54,7 @@ export class BmProcessService {
*
* @param id id of the bm process
*/
getBmProcess(id: string): Promise<BmProcess> {
get(id: string): Promise<BmProcess> {
return this.pouchdbService.get<BmProcess>(id).then((e) => new BmProcess(e));
}
......@@ -72,7 +73,7 @@ export class BmProcessService {
*
* @param id id of the bm process
*/
deleteBmProcess(id: string) {
delete(id: string) {
return this.pouchdbService.get(id).then((result) => {
return this.pouchdbService.remove(result);
});
......
......@@ -5,17 +5,20 @@ import { DevelopmentMethod } from './development-method';
import { DevelopmentProcessRegistryModule } from '../development-process-registry.module';
import { Type } from '../method-elements/type/type';
import { Observable } from 'rxjs';
import { ElementService } from '../../database/element-service';
@Injectable({
providedIn: DevelopmentProcessRegistryModule,
})
export class DevelopmentMethodService {
export class DevelopmentMethodService
implements ElementService<DevelopmentMethod>
{
constructor(private pouchdbService: PouchdbService) {}
/**
* Get the list of the development methods.
*/
getDevelopmentMethodList() {
getList() {
return this.pouchdbService.find<DevelopmentMethod>(
DevelopmentMethod.typeName,
{
......@@ -49,10 +52,10 @@ export class DevelopmentMethodService {
/**
* Add new development method.
*
* @param name name of the development method
* @param element the development method
*/
addDevelopmentMethod(name: string) {
return this.pouchdbService.post(new DevelopmentMethod({ name }));
add(element: Partial<DevelopmentMethod>) {
return this.pouchdbService.post(new DevelopmentMethod(element));
}
/**
......@@ -61,11 +64,8 @@ export class DevelopmentMethodService {
* @param id id of the development method
* @param developmentMethod the new values of the object (values will be copied)
*/
updateDevelopmentMethod(
id: string,
developmentMethod: Partial<DevelopmentMethod>
) {
return this.getDevelopmentMethod(id).then((method) => {
update(id: string, developmentMethod: Partial<DevelopmentMethod>) {
return this.get(id).then((method) => {
method.update(developmentMethod);
return this.saveDevelopmentMethod(method);
});
......@@ -76,7 +76,7 @@ export class DevelopmentMethodService {
*
* @param id id of the development method
*/
getDevelopmentMethod(id: string): Promise<DevelopmentMethod> {
get(id: string): Promise<DevelopmentMethod> {
return this.pouchdbService
.get<DevelopmentMethod>(id)
.then((e) => new DevelopmentMethod(e));
......@@ -114,7 +114,7 @@ export class DevelopmentMethodService {
*
* @param id id of the development method
*/
deleteDevelopmentMethod(id: string) {
delete(id: string) {
return this.pouchdbService.get(id).then((result) => {
return this.pouchdbService.remove(result);
});
......
......@@ -3,9 +3,12 @@ import { PouchdbService } from '../../database/pouchdb.service';
import { MethodElement } from './method-element';
import PouchDB from 'pouchdb-browser';
import { Observable } from 'rxjs';
import { ElementService } from '../../database/element-service';
@Injectable()
export abstract class MethodElementService<T extends MethodElement> {
export abstract class MethodElementService<T extends MethodElement>
implements ElementService<T>
{
constructor(protected pouchdbService: PouchdbService) {}
/**
......@@ -20,7 +23,7 @@ export abstract class MethodElementService<T extends MethodElement> {
/**
* Get all method elements
*/
getAll() {
getList() {
return this.pouchdbService.find<T>(this.getTypeName(), { selector: {} });
}
......@@ -28,7 +31,7 @@ export abstract class MethodElementService<T extends MethodElement> {
* Get all method elements in their lists
*/
getLists(): Promise<{ listName: string; elements: T[] }[]> {
return this.getAll().then((list) => {
return this.getList().then((list) => {
const elementListMap: { [listName: string]: MethodElement[] } = {};
list.docs.forEach((element) => {
if (element.list in elementListMap) {
......@@ -70,12 +73,12 @@ export abstract class MethodElementService<T extends MethodElement> {
* Update a method element
*
* @param id the id of the method element to update
* @param updateMethod this method is called to update the element
* @param element the new data of the element
*/
update(id: string, updateMethod: (currentElement: T) => T) {
return this.get(id).then((currentElement) =>
this.save(updateMethod(currentElement))
);
async update(id: string, element: Partial<T>) {
const currentElement = await this.get(id);
currentElement.update(element);
return this.save(currentElement);
}
/**
......
import { PouchdbModel } from '../../database/pouchdb-model';
export class MethodElement extends PouchdbModel {
export abstract class MethodElement extends PouchdbModel {
list: string;
name: string;
description: string;
abstract update(element: Partial<this>);
toPouchDb(): any {
return {
...super.toPouchDb(),
......
......@@ -5,17 +5,18 @@ import PouchDB from 'pouchdb-browser';
import { Type } from '../method-elements/type/type';
import { DevelopmentProcessRegistryModule } from '../development-process-registry.module';
import { Observable } from 'rxjs';
import { ElementService } from '../../database/element-service';
@Injectable({
providedIn: DevelopmentProcessRegistryModule,
})
export class ProcessPatternService {
export class ProcessPatternService implements ElementService<ProcessPattern> {
constructor(private pouchdbService: PouchdbService) {}
/**
* Get the list of the process patterns.
*/
getProcessPatternList() {
getList() {
return this.pouchdbService.find<ProcessPattern>(ProcessPattern.typeName, {
selector: {},
});
......@@ -46,10 +47,10 @@ export class ProcessPatternService {
/**
* Add new process pattern.
*
* @param name name of the process pattern
* @param element the process pattern
*/
addProcessPattern(name: string) {
return this.pouchdbService.post(new ProcessPattern({ name }));
add(element: Partial<ProcessPattern>) {
return this.pouchdbService.post(new ProcessPattern(element));
}
/**
......@@ -58,8 +59,8 @@ export class ProcessPatternService {
* @param id id of the process pattern
* @param processPattern the new values of the object (values will be copied)
*/
updateProcessPattern(id: string, processPattern: Partial<ProcessPattern>) {
return this.getProcessPattern(id).then((pattern) => {
update(id: string, processPattern: Partial<ProcessPattern>) {
return this.get(id).then((pattern) => {
pattern.update(processPattern);
return this.saveProcessPattern(pattern);
});
......@@ -70,7 +71,7 @@ export class ProcessPatternService {
*
* @param id id of the process pattern
*/
getProcessPattern(id: string): Promise<ProcessPattern> {
get(id: string): Promise<ProcessPattern> {
return this.pouchdbService
.get<ProcessPattern>(id)
.then((e) => new ProcessPattern(e));
......@@ -108,7 +109,7 @@ export class ProcessPatternService {
*
* @param id id of the process pattern
*/
deleteProcessPattern(id: string) {
delete(id: string) {
return this.pouchdbService.get(id).then((result) => {
return this.pouchdbService.remove(result);
});
......
......@@ -3,7 +3,6 @@ import { PouchdbService } from '../../database/pouchdb.service';
import PouchDB from 'pouchdb-browser';
import { RunningProcess } from './running-process';
import { DevelopmentProcessRegistryModule } from '../development-process-registry.module';
import { BmProcess } from '../bm-process/bm-process';
import { ArtifactData, ArtifactDataType } from './artifact-data';
import { ProcessExecutionService } from './process-execution.service';
import { MethodExecutionService } from './method-execution.service';
......@@ -14,11 +13,12 @@ import { Comment } from './comment';
import { Observable } from 'rxjs';
import { ArtifactDataService } from './artifact-data.service';
import { RunningArtifact } from './running-artifact';
import { ElementService } from '../../database/element-service';
@Injectable({
providedIn: DevelopmentProcessRegistryModule,
})
export class RunningProcessService {
export class RunningProcessService implements ElementService<RunningProcess> {
constructor(
private artifactDataService: ArtifactDataService,
private methodExecutionService: MethodExecutionService,
......@@ -29,7 +29,7 @@ export class RunningProcessService {
/**
* Get the list of the running processes.
*/
getRunningProcessesList() {
getList() {
return this.pouchdbService.find<RunningProcess>(RunningProcess.typeName, {
selector: {},
});
......@@ -38,14 +38,10 @@ export class RunningProcessService {
/**
* Add new running process from a process.
*
* @param process the process from which to derive the running process
* @param name the name of the running process
* @param element the running process
*/
async addRunningProcess(process: BmProcess, name: string) {
const runningProcess = new RunningProcess({
name,
process,
});
async add(element: Partial<RunningProcess>) {
const runningProcess = new RunningProcess(element);
await this.processExecutionService.initRunningProcess(runningProcess);
await this.processExecutionService.jumpToNextMethod(runningProcess);
return this.saveRunningProcess(runningProcess);
......@@ -56,7 +52,7 @@ export class RunningProcessService {
*
* @param id id of the running process
*/
async getRunningProcess(id: string): Promise<RunningProcess> {
async get(id: string): Promise<RunningProcess> {
const e = await this.pouchdbService.get<RunningProcess>(id);
return new RunningProcess(e);
}
......@@ -83,7 +79,7 @@ export class RunningProcessService {
nodeId: string = null,
flowId: string = null
) {
const databaseProcess = await this.getRunningProcess(runningProcess._id);
const databaseProcess = await this.get(runningProcess._id);
if (databaseProcess._rev !== runningProcess._rev) {
throw new Error(
'Reload needed, process in database does not fit current process'
......@@ -103,7 +99,7 @@ export class RunningProcessService {
* @param runningProcess the running process
*/
async jumpSteps(runningProcess: RunningProcess) {
const databaseProcess = await this.getRunningProcess(runningProcess._id);
const databaseProcess = await this.get(runningProcess._id);
if (databaseProcess._rev !== runningProcess._rev) {
throw new Error(
'Reload needed, process in database does not fit current process'
......@@ -120,7 +116,7 @@ export class RunningProcessService {
* @param nodeId the id of the node to execute
*/
async startMethodExecution(runningProcess: RunningProcess, nodeId: string) {
const databaseProcess = await this.getRunningProcess(runningProcess._id);
const databaseProcess = await this.get(runningProcess._id);
if (databaseProcess._rev !== runningProcess._rev) {
throw new Error(
'Reload needed, process in database does not fit current process'
......@@ -148,7 +144,7 @@ export class RunningProcessService {
runningProcess: RunningProcess,
executionId: string
) {
const databaseProcess = await this.getRunningProcess(runningProcess._id);
const databaseProcess = await this.get(runningProcess._id);
if (databaseProcess._rev !== runningProcess._rev) {
throw new Error(
'Reload needed, process in database does not fit current process'
......@@ -168,7 +164,7 @@ export class RunningProcessService {
* @param executionId the id of the executed method
*/
async executeMethodStep(runningProcess: RunningProcess, executionId: string) {
const databaseProcess = await this.getRunningProcess(runningProcess._id);
const databaseProcess = await this.get(runningProcess._id);
if (databaseProcess._rev !== runningProcess._rev) {
throw new Error(
'Reload needed, process in database does not fit current process'
......@@ -185,7 +181,7 @@ export class RunningProcessService {
executionId
);
await this.saveRunningProcess(runningProcess);
runningProcess = await this.getRunningProcess(runningProcess._id);
runningProcess = await this.get(runningProcess._id);
}
await this.methodExecutionService.executeStep(runningProcess, executionId);
return this.saveRunningProcess(runningProcess);
......@@ -198,9 +194,7 @@ export class RunningProcessService {
* @param output the output of the method of the module
*/
async finishExecuteStep(stepInfo: StepInfo, output: MethodExecutionOutput) {
const databaseProcess = await this.getRunningProcess(
stepInfo.runningProcessId
);
const databaseProcess = await this.get(stepInfo.runningProcessId);
this.methodExecutionService.finishExecuteStep(
databaseProcess,
stepInfo.executionId,
......@@ -220,7 +214,7 @@ export class RunningProcessService {
runningProcess: RunningProcess,
executionId: string
) {
const databaseProcess = await this.getRunningProcess(runningProcess._id);
const databaseProcess = await this.get(runningProcess._id);
if (databaseProcess._rev !== runningProcess._rev) {
throw new Error(
'Reload needed, process in database does not fit current process'
......@@ -250,7 +244,7 @@ export class RunningProcessService {
runningProcess: RunningProcess,
executionId: string
) {
const databaseProcess = await this.getRunningProcess(runningProcess._id);
const databaseProcess = await this.get(runningProcess._id);
if (databaseProcess._rev !== runningProcess._rev) {
throw new Error(
'Reload needed, process in database does not fit current process'
......@@ -303,7 +297,7 @@ export class RunningProcessService {
executionId: string,
inputArtifactMapping: { artifact: number; version: number }[]
) {
const databaseProcess = await this.getRunningProcess(runningProcess._id);
const databaseProcess = await this.get(runningProcess._id);
if (databaseProcess._rev !== runningProcess._rev) {
throw new Error(
'Reload needed, process in database does not fit current process'
......@@ -327,7 +321,7 @@ export class RunningProcessService {
data: ArtifactData;
}[]
) {
const databaseProcess = await this.getRunningProcess(runningProcess._id);
const databaseProcess = await this.get(runningProcess._id);
if (databaseProcess._rev !== runningProcess._rev) {
throw new Error(
'Reload needed, process in database does not fit current process'
......@@ -348,7 +342,7 @@ export class RunningProcessService {
* @param artifact the artifact to import into the running process
*/
async importArtifact(runningProcessId: string, artifact: RunningArtifact) {
const runningProcess = await this.getRunningProcess(runningProcessId);
const runningProcess = await this.get(runningProcessId);
runningProcess.importArtifact(artifact);
return this.saveRunningProcess(runningProcess);
}
......@@ -360,7 +354,7 @@ export class RunningProcessService {
* @param decision the method decisions
*/
async addMethod(runningProcess: RunningProcess, decision: Decision) {
const databaseProcess = await this.getRunningProcess(runningProcess._id);
const databaseProcess = await this.get(runningProcess._id);
if (databaseProcess._rev !== runningProcess._rev) {
throw new Error(
'Reload needed, process in database does not fit current process'
......@@ -377,7 +371,7 @@ export class RunningProcessService {
* @param executionId the id of the method to remove
*/
async removeMethod(runningProcess: RunningProcess, executionId: string) {
const databaseProcess = await this.getRunningProcess(runningProcess._id);
const databaseProcess = await this.get(runningProcess._id);
if (databaseProcess._rev !== runningProcess._rev) {
throw new Error(
'Reload needed, process in database does not fit current process'
......@@ -392,7 +386,7 @@ export class RunningProcessService {
*
* @param id id of the running process
*/
async deleteRunningProcess(id: string) {
async delete(id: string) {
const result = await this.pouchdbService.get<RunningProcess>(id);
const runningProcess = new RunningProcess(result);
// abort all running methods
......@@ -421,7 +415,7 @@ export class RunningProcessService {
* @param comment the comment to add
*/
async addComment(id: string, executionId: string, comment: Comment) {
const process = await this.getRunningProcess(id);
const process = await this.get(id);
const method = process.getRunningMethod(executionId);
method.addComment(comment);
return this.saveRunningProcess(process);
......@@ -435,7 +429,7 @@ export class RunningProcessService {
* @param comment the comment to add
*/
async updateComment(id: string, executionId: string, comment: Comment) {
const process = await this.getRunningProcess(id);
const process = await this.get(id);
const method = process.getRunningMethod(executionId);
const dbComment = method.getComment(comment.id);
dbComment.update(comment);
......@@ -450,7 +444,7 @@ export class RunningProcessService {
* @param commentId the id of the comment to remove
*/
async removeComment(id: string, executionId: string, commentId: string) {
const process = await this.getRunningProcess(id);
const process = await this.get(id);
const method = process.getRunningMethod(executionId);
method.removeComment(commentId);
return this.saveRunningProcess(process);
......@@ -468,7 +462,7 @@ export class RunningProcessService {
runningArtifact: RunningArtifact,
identifier: string
) {