2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 import emptyModel from './emptyModel.json';
23 function mergeLifelines(oldLifelines, newLifelines) {
24 let oldLifelinesMap = new Map(oldLifelines.map(lifeline => [lifeline.id, lifeline]));
25 let newLifelinesMap = new Map(newLifelines.map(lifeline => [lifeline.id, lifeline]));
27 let updatedLifelines = oldLifelines.map(lifeline => {
28 let newLifeline = newLifelinesMap.get(lifeline.id);
31 name: newLifeline ? newLifeline.name : lifeline.name
35 let addedLifelines = newLifelines.filter(lifeline => !oldLifelinesMap.has(lifeline.id));
44 const SequenceDiagramModelHelper = Object.freeze({
46 createModel(options) {
47 return SequenceDiagramModelHelper.updateModel(emptyModel, options);
50 updateModel(model, options) {
51 const diagram = model.diagram;
52 const metadata = diagram.metadata || model.metadata;
53 const id = options.id || metadata.id;
54 const name = options.name || metadata.name;
55 const lifelines = options.lifelines ? mergeLifelines(diagram.lifelines, options.lifelines) : diagram.lifelines;
71 export default SequenceDiagramModelHelper;