Commit fe2cdab5 authored by Sebastian Gottschalk's avatar Sebastian Gottschalk
Browse files

Added adaptation function to business model canvas

parent b08442ff
......@@ -38,17 +38,24 @@ export class BusinessModelViewComponent implements OnInit {
/**
* Create a new instance of the BusinessModelViewComponent.
* @param route ActivatedRoute
* @param router Router
* @param pouchDBServer PouchdbService
* @param modalService NgbModal
* @param fb FormBuilder
*/
constructor(
private route: ActivatedRoute,
private router: Router,
private pouchDBServer: PouchdbService,
private modalService: NgbModal,
private fb: FormBuilder
) { }
) {
this.router.routeReuseStrategy.shouldReuseRoute = function () {
return false;
};
}
/**
* Initialize the component.
......@@ -185,6 +192,32 @@ export class BusinessModelViewComponent implements OnInit {
});
}
/**
* Create adaptation of the business model.
*/
createAdaptation() {
var nameSplit = this.businessModelName.split(" - Adaptation#")
var adaptationName;
console.log(nameSplit.length)
if(nameSplit.length > 1 && parseInt(nameSplit[nameSplit.length -1]) != NaN) {
adaptationName = nameSplit[0]+" - Adaptation#"+(parseInt(nameSplit[nameSplit.length -1]) + 1);
} else {
adaptationName = nameSplit[0]+" - Adaptation#1"
}
this.pouchDBServer.adaptBusinessModel(this.featureModelId, this.businessModelId, adaptationName).then(result => {
this.pouchDBServer.getFeatureModel(this.featureModelId).then(result => {
var businessModelKeys = Object.keys(result['businessModelMap']);
this.router.navigateByUrl('/businessmodelview/'+this.featureModelId+'/'+businessModelKeys[businessModelKeys.length - 1]);
}, error => {
console.log("CreateAdaptation (inner): ");
});
}, error => {
console.log("CreateAdaptation: ")
})
}
/**
* Uncheck the conformance.
*/
......@@ -347,6 +380,8 @@ export class BusinessModelViewComponent implements OnInit {
getUnselectedFeatures(feature: any): any[] {
var returnFeatures = []
console.log(JSON.stringify(feature))
for (var i = 0; i < feature.features.length; i++) {
if (!feature.features[i]['businessModelIds'].includes(parseInt(this.businessModelId))) {
returnFeatures.push(feature.features[i])
......
......@@ -24,23 +24,15 @@ export class PouchdbService {
// Create a PouchDB connection
PouchDB.plugin(PouchDBFind)
// Change to this.db = new PouchDB('http://server:port/yourdatabase'); to connect to a couchdb database
this.db = new PouchDB(this.databaseName);
// Check database connection
this.db.info().then(function (info) {
console.log("Database connection: " + info);
})
this.getFeatureModelList().then(result => {
console.log("Res: "+JSON.stringify(result));
}, error => {
console.log("Err: "+error);
console.log("Database connection: " + JSON.stringify(info));
})
}
/**
* Get the information about the database.
*/
getDatabaseInfo() {
return this.db.info();
}
......@@ -223,6 +215,54 @@ export class PouchdbService {
});
}
/**
* Adapt an existing business model.
* @param featureModelId id of the current feature model
* @param businessModelId id of the business model
* @param adaptationName name of the adapted business model
*/
adaptBusinessModel(featureModelId: string, businessModelId: string, adaptationName: string){
return this.db.get(featureModelId).then(result => {
var result = result;
var newBusinessModelId = result['businessModelIdCounter'];
// Create new business model
for (var i = 0; i < result['features'].length; i++) {
result['features'][i]['businessModelIds'].push(result['businessModelIdCounter']);
}
result['businessModelMap'][result['businessModelIdCounter']] = adaptationName;
result['businessModelIdCounter'] = result['businessModelIdCounter'] + 1;
// Traverse features
var featureStack: any[] = []
for (var i = 0; i < result['features'].length; i++) {
var model = result['features'][result['features'].length - 1 - i];
featureStack.push(model);
}
// Select single feature from the stack
while (featureStack.length > 0) {
var f = featureStack.pop();
if(f['businessModelIds'].includes(parseInt(businessModelId)) && !f['businessModelIds'].includes(parseInt(newBusinessModelId))) {
f['businessModelIds'].push(newBusinessModelId)
}
// Add new features to the stack
if (f.features) {
for (var i = 0; i < f.features.length; i++) {
var model = f.features[f.features.length - 1 - i];
featureStack.push(model);
}
}
}
//console.log(JSON.stringify(result));
//return result;
return this.db.put(result);
});
}
/**
* Delete a specific business model of the current feature model.
* @param featureModelId id of the current feature model
......@@ -692,10 +732,12 @@ export class PouchdbService {
}
/**
* Destroy the old database and generate a new one with default data.
* Add default data to the database.
*/
public addDefaultData() {
console.log("Inner default db")
return this.db.destroy().then(result => {
console.log("Result: "+JSON.stringify(result))
this.db = new PouchDB(this.databaseName);
return this.db.post({
......@@ -1255,10 +1297,7 @@ export class PouchdbService {
});
}, error => {
// error occurred
console.log("Add Default Data")
});
console.log("Add Default Data")
return error;
});
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment