| /** |
| * Copyright (c) 2011, 2016 - Loetz GmbH&Co.KG (69115 Heidelberg, Germany) |
| * |
| * All rights reserved. This program and the accompanying materials |
| * are made available under the terms of the Eclipse Public License v1.0 |
| * which accompanies this distribution, and is available at |
| * http://www.eclipse.org/legal/epl-v10.html |
| * |
| * Contributors: |
| * Christophe Loetz (Loetz GmbH&Co.KG) - initial implementation |
| * |
| * |
| * This copyright notice shows up in the generated Java code |
| */ |
| package org.eclipse.osbp.xtext.blip.common; |
| |
| import com.google.common.base.Objects; |
| import java.util.ArrayList; |
| import java.util.Iterator; |
| import java.util.LinkedList; |
| import java.util.List; |
| import org.apache.commons.lang3.StringUtils; |
| import org.apache.commons.lang3.text.WordUtils; |
| import org.eclipse.bpmn2.CallActivity; |
| import org.eclipse.bpmn2.Event; |
| import org.eclipse.bpmn2.Gateway; |
| import org.eclipse.bpmn2.ScriptTask; |
| import org.eclipse.bpmn2.SequenceFlow; |
| import org.eclipse.bpmn2.ServiceTask; |
| import org.eclipse.bpmn2.Task; |
| import org.eclipse.emf.common.util.EList; |
| import org.eclipse.emf.ecore.EObject; |
| import org.eclipse.osbp.dsl.semantic.common.types.LMultiplicity; |
| import org.eclipse.osbp.dsl.semantic.common.types.LReference; |
| import org.eclipse.osbp.dsl.semantic.common.types.LType; |
| import org.eclipse.osbp.dsl.semantic.dto.LAutoInheritDto; |
| import org.eclipse.osbp.dsl.semantic.dto.LDto; |
| import org.eclipse.osbp.dsl.semantic.dto.LDtoAbstractReference; |
| import org.eclipse.osbp.dsl.semantic.dto.LDtoFeature; |
| import org.eclipse.osbp.dsl.semantic.dto.impl.LDtoInheritedReferenceImpl; |
| import org.eclipse.osbp.dsl.semantic.dto.impl.LDtoReferenceImpl; |
| import org.eclipse.osbp.dsl.semantic.entity.LEntity; |
| import org.eclipse.osbp.xtext.blip.Blip; |
| import org.eclipse.osbp.xtext.blip.BlipCallActivity; |
| import org.eclipse.osbp.xtext.blip.BlipDto; |
| import org.eclipse.osbp.xtext.blip.BlipDtoPath; |
| import org.eclipse.osbp.xtext.blip.BlipEvent; |
| import org.eclipse.osbp.xtext.blip.BlipItem; |
| import org.eclipse.osbp.xtext.blip.BlipOutGoing; |
| import org.eclipse.osbp.xtext.blip.BlipScript; |
| import org.eclipse.osbp.xtext.blip.BlipServiceTask; |
| import org.eclipse.osbp.xtext.blip.BlipSplitGateway; |
| import org.eclipse.osbp.xtext.blip.BlipUserTask; |
| import org.eclipse.osbp.xtext.blip.BlipWorkload; |
| import org.eclipse.xtend2.lib.StringConcatenation; |
| import org.eclipse.xtext.xbase.lib.CollectionLiterals; |
| import org.eclipse.xtext.xbase.lib.Conversions; |
| |
| @SuppressWarnings("all") |
| public class BlipHelper { |
| public static String getBpmItemRecommendedName(final String name) { |
| String recommended = name; |
| String _replace = recommended.replace("_", " "); |
| recommended = _replace; |
| String _replace_1 = recommended.replace(" ", " "); |
| recommended = _replace_1; |
| String _stripAccents = StringUtils.stripAccents(recommended); |
| recommended = _stripAccents; |
| String _capitalize = WordUtils.capitalize(recommended); |
| recommended = _capitalize; |
| String _replace_2 = recommended.replace(" ", ""); |
| recommended = _replace_2; |
| return recommended; |
| } |
| |
| public static String getBpmItemRecommendedName(final BlipItem blipItem) { |
| String bpmItemName = ""; |
| if ((blipItem instanceof BlipEvent)) { |
| Event _event = ((BlipEvent)blipItem).getEvent(); |
| String _name = _event.getName(); |
| bpmItemName = _name; |
| } else { |
| if ((blipItem instanceof BlipSplitGateway)) { |
| Gateway _gateway = ((BlipSplitGateway)blipItem).getGateway(); |
| String _name_1 = _gateway.getName(); |
| bpmItemName = _name_1; |
| } else { |
| if ((blipItem instanceof BlipUserTask)) { |
| Task _task = ((BlipUserTask)blipItem).getTask(); |
| String _name_2 = _task.getName(); |
| bpmItemName = _name_2; |
| } else { |
| if ((blipItem instanceof BlipCallActivity)) { |
| CallActivity _callActivity = ((BlipCallActivity)blipItem).getCallActivity(); |
| String _name_3 = _callActivity.getName(); |
| bpmItemName = _name_3; |
| } else { |
| if ((blipItem instanceof BlipScript)) { |
| ScriptTask _task_1 = ((BlipScript)blipItem).getTask(); |
| String _name_4 = _task_1.getName(); |
| bpmItemName = _name_4; |
| } else { |
| if ((blipItem instanceof BlipServiceTask)) { |
| ServiceTask _task_2 = ((BlipServiceTask)blipItem).getTask(); |
| String _name_5 = _task_2.getName(); |
| bpmItemName = _name_5; |
| } else { |
| if ((blipItem instanceof BlipOutGoing)) { |
| SequenceFlow _sequenceFlow = ((BlipOutGoing)blipItem).getSequenceFlow(); |
| String _name_6 = _sequenceFlow.getName(); |
| bpmItemName = _name_6; |
| } |
| } |
| } |
| } |
| } |
| } |
| } |
| return BlipHelper.getBpmItemRecommendedName(bpmItemName); |
| } |
| |
| public static boolean isOperativeDtoDefined(final BlipItem blipItem) { |
| boolean _and = false; |
| BlipDtoPath _dtoPath = null; |
| if (blipItem!=null) { |
| _dtoPath=blipItem.getDtoPath(); |
| } |
| boolean _notEquals = (!Objects.equal(_dtoPath, null)); |
| if (!_notEquals) { |
| _and = false; |
| } else { |
| BlipDtoPath _dtoPath_1 = null; |
| if (blipItem!=null) { |
| _dtoPath_1=blipItem.getDtoPath(); |
| } |
| String _dtoPath_2 = _dtoPath_1.getDtoPath(); |
| boolean _isEmpty = _dtoPath_2.isEmpty(); |
| boolean _not = (!_isEmpty); |
| _and = _not; |
| } |
| return _and; |
| } |
| |
| public static LDtoAbstractReference getDtoFeature(final LDto operativeDto, final String dtoChildName) { |
| boolean _notEquals = (!Objects.equal(operativeDto, null)); |
| if (_notEquals) { |
| EList<LDtoFeature> _features = operativeDto.getFeatures(); |
| for (final LDtoFeature feature : _features) { |
| { |
| String attributeName = ((String) null); |
| if ((feature instanceof LDtoReferenceImpl)) { |
| String _name = ((LDtoReferenceImpl)feature).getName(); |
| attributeName = _name; |
| } |
| if ((feature instanceof LDtoInheritedReferenceImpl)) { |
| LReference _inheritedFeature = ((LDtoInheritedReferenceImpl)feature).getInheritedFeature(); |
| String _name_1 = _inheritedFeature.getName(); |
| attributeName = _name_1; |
| } |
| boolean _notEquals_1 = (!Objects.equal(attributeName, null)); |
| if (_notEquals_1) { |
| boolean _and = false; |
| boolean _equals = attributeName.equals(dtoChildName); |
| if (!_equals) { |
| _and = false; |
| } else { |
| _and = (feature instanceof LDtoAbstractReference); |
| } |
| if (_and) { |
| return ((LDtoAbstractReference) feature); |
| } |
| } |
| } |
| } |
| } |
| return null; |
| } |
| |
| public static LDto getPureOperativeLDto(final BlipItem blipItem) { |
| boolean _isOperativeDtoDefined = BlipHelper.isOperativeDtoDefined(blipItem); |
| if (_isOperativeDtoDefined) { |
| EObject _eContainer = null; |
| if (blipItem!=null) { |
| _eContainer=blipItem.eContainer(); |
| } |
| BlipWorkload _workload = null; |
| if (((Blip) _eContainer)!=null) { |
| _workload=((Blip) _eContainer).getWorkload(); |
| } |
| BlipDto _source = null; |
| if (_workload!=null) { |
| _source=_workload.getSource(); |
| } |
| LDto _dtoRef = null; |
| if (_source!=null) { |
| _dtoRef=_source.getDtoRef(); |
| } |
| LDto operativeDto = _dtoRef; |
| boolean _and = false; |
| boolean _and_1 = false; |
| boolean _notEquals = (!Objects.equal(operativeDto, null)); |
| if (!_notEquals) { |
| _and_1 = false; |
| } else { |
| String _name = operativeDto.getName(); |
| boolean _notEquals_1 = (!Objects.equal(_name, null)); |
| _and_1 = _notEquals_1; |
| } |
| if (!_and_1) { |
| _and = false; |
| } else { |
| String _name_1 = operativeDto.getName(); |
| BlipDtoPath _dtoPath = null; |
| if (blipItem!=null) { |
| _dtoPath=blipItem.getDtoPath(); |
| } |
| boolean _equals = _name_1.equals(_dtoPath); |
| boolean _not = (!_equals); |
| _and = _not; |
| } |
| if (_and) { |
| BlipDtoPath _dtoPath_1 = null; |
| if (blipItem!=null) { |
| _dtoPath_1=blipItem.getDtoPath(); |
| } |
| String dtoPath = _dtoPath_1.getDtoPath(); |
| String _name_2 = operativeDto.getName(); |
| String _plus = (_name_2 + "."); |
| boolean _startsWith = dtoPath.startsWith(_plus); |
| boolean _not_1 = (!_startsWith); |
| if (_not_1) { |
| return null; |
| } else { |
| String _name_3 = operativeDto.getName(); |
| String _plus_1 = (_name_3 + "."); |
| int _length = _plus_1.length(); |
| String _substring = dtoPath.substring(_length); |
| dtoPath = _substring; |
| final String[] dtoChildNames = dtoPath.split("\\."); |
| for (final String dtoChildName : dtoChildNames) { |
| LDto _referencedLDto = BlipHelper.getReferencedLDto(operativeDto, dtoChildName); |
| operativeDto = _referencedLDto; |
| } |
| } |
| } |
| return operativeDto; |
| } |
| return null; |
| } |
| |
| public static LDtoAbstractReference getDtoFeature(final BlipItem blipItem) { |
| LDtoAbstractReference dtoFeature = ((LDtoAbstractReference) null); |
| LDto operativeDto = ((LDto) null); |
| boolean _isOperativeDtoDefined = BlipHelper.isOperativeDtoDefined(blipItem); |
| if (_isOperativeDtoDefined) { |
| EObject _eContainer = null; |
| if (blipItem!=null) { |
| _eContainer=blipItem.eContainer(); |
| } |
| BlipWorkload _workload = null; |
| if (((Blip) _eContainer)!=null) { |
| _workload=((Blip) _eContainer).getWorkload(); |
| } |
| BlipDto _source = null; |
| if (_workload!=null) { |
| _source=_workload.getSource(); |
| } |
| LDto _dtoRef = null; |
| if (_source!=null) { |
| _dtoRef=_source.getDtoRef(); |
| } |
| operativeDto = _dtoRef; |
| boolean _and = false; |
| boolean _and_1 = false; |
| boolean _notEquals = (!Objects.equal(operativeDto, null)); |
| if (!_notEquals) { |
| _and_1 = false; |
| } else { |
| String _name = operativeDto.getName(); |
| boolean _notEquals_1 = (!Objects.equal(_name, null)); |
| _and_1 = _notEquals_1; |
| } |
| if (!_and_1) { |
| _and = false; |
| } else { |
| String _name_1 = operativeDto.getName(); |
| BlipDtoPath _dtoPath = null; |
| if (blipItem!=null) { |
| _dtoPath=blipItem.getDtoPath(); |
| } |
| boolean _equals = _name_1.equals(_dtoPath); |
| boolean _not = (!_equals); |
| _and = _not; |
| } |
| if (_and) { |
| BlipDtoPath _dtoPath_1 = null; |
| if (blipItem!=null) { |
| _dtoPath_1=blipItem.getDtoPath(); |
| } |
| String _dtoPath_2 = _dtoPath_1.getDtoPath(); |
| String _name_2 = operativeDto.getName(); |
| String _plus = (_name_2 + "."); |
| String _replace = _dtoPath_2.replace(_plus, ""); |
| final String[] dtoChildNames = _replace.split("\\."); |
| for (final String dtoChildName : dtoChildNames) { |
| { |
| LDtoAbstractReference _dtoFeature = BlipHelper.getDtoFeature(operativeDto, dtoChildName); |
| dtoFeature = _dtoFeature; |
| LDto _referencedLDto = BlipHelper.getReferencedLDto(operativeDto, dtoChildName); |
| operativeDto = _referencedLDto; |
| } |
| } |
| } |
| } |
| return dtoFeature; |
| } |
| |
| public static LEntity getOperativeEntity(final BlipItem blipItem) { |
| LDto dto = blipItem.getOperativeLDto(); |
| if ((dto instanceof LAutoInheritDto)) { |
| LType _wrappedType = ((LAutoInheritDto)dto).getWrappedType(); |
| if ((_wrappedType instanceof LEntity)) { |
| LType _wrappedType_1 = ((LAutoInheritDto)dto).getWrappedType(); |
| return ((LEntity) _wrappedType_1); |
| } |
| } |
| return null; |
| } |
| |
| public static LDto getOperativeLDto(final BlipItem blipItem) { |
| final LDto operativeDto = BlipHelper.getPureOperativeLDto(blipItem); |
| boolean _equals = Objects.equal(operativeDto, null); |
| if (_equals) { |
| EObject _eContainer = null; |
| if (blipItem!=null) { |
| _eContainer=blipItem.eContainer(); |
| } |
| BlipWorkload _workload = null; |
| if (((Blip) _eContainer)!=null) { |
| _workload=((Blip) _eContainer).getWorkload(); |
| } |
| BlipDto _source = null; |
| if (_workload!=null) { |
| _source=_workload.getSource(); |
| } |
| LDto _dtoRef = null; |
| if (_source!=null) { |
| _dtoRef=_source.getDtoRef(); |
| } |
| return _dtoRef; |
| } else { |
| return operativeDto; |
| } |
| } |
| |
| public static LDto getReferencedLDto(final LDto operativeDto, final String dtoChildName) { |
| LDtoAbstractReference dtoFeature = BlipHelper.getDtoFeature(operativeDto, dtoChildName); |
| boolean _notEquals = (!Objects.equal(dtoFeature, null)); |
| if (_notEquals) { |
| return dtoFeature.getType(); |
| } |
| return null; |
| } |
| |
| public static List<String> getAvailableDtoPaths(final BlipItem blipItem) { |
| EObject _eContainer = blipItem.eContainer(); |
| return BlipHelper.getAvailableDtoPaths(((Blip) _eContainer)); |
| } |
| |
| public static List<String> getAvailableDtoPaths(final Blip blip) { |
| ArrayList<String> results = CollectionLiterals.<String>newArrayList(); |
| BlipWorkload _workload = null; |
| if (blip!=null) { |
| _workload=blip.getWorkload(); |
| } |
| BlipDto _source = null; |
| if (_workload!=null) { |
| _source=_workload.getSource(); |
| } |
| LDto _dtoRef = null; |
| if (_source!=null) { |
| _dtoRef=_source.getDtoRef(); |
| } |
| final LDto baseDto = _dtoRef; |
| boolean _notEquals = (!Objects.equal(baseDto, null)); |
| if (_notEquals) { |
| final LinkedList<LDto> dtoStack = CollectionLiterals.<LDto>newLinkedList(baseDto); |
| String _name = baseDto.getName(); |
| BlipHelper.recursiveCompleteBlipItem_DtoPath(results, _name, dtoStack); |
| } |
| return results; |
| } |
| |
| /** |
| * TODO: find a more meaningful solution to find unnecessary recursive dto paths |
| */ |
| private static void recursiveCompleteBlipItem_DtoPath(final List<String> results, final String parentName, final LinkedList<LDto> dtoStack) { |
| final String proposal = parentName; |
| results.add(proposal); |
| final LDto actualDto = dtoStack.getLast(); |
| LDto previousDto = ((LDto) null); |
| int _size = dtoStack.size(); |
| boolean _greaterThan = (_size > 1); |
| if (_greaterThan) { |
| int _size_1 = dtoStack.size(); |
| int _minus = (_size_1 - 2); |
| LDto _get = dtoStack.get(_minus); |
| previousDto = _get; |
| } |
| EList<LDtoFeature> _features = actualDto.getFeatures(); |
| for (final LDtoFeature feature : _features) { |
| { |
| LDto referencedDto = ((LDto) null); |
| LMultiplicity multiplicity = ((LMultiplicity) null); |
| String attributeName = ""; |
| if ((feature instanceof LDtoReferenceImpl)) { |
| LDto _type = ((LDtoReferenceImpl)feature).getType(); |
| referencedDto = _type; |
| String _name = ((LDtoReferenceImpl)feature).getName(); |
| attributeName = _name; |
| LMultiplicity _multiplicity = ((LDtoReferenceImpl)feature).getMultiplicity(); |
| multiplicity = _multiplicity; |
| } |
| if ((feature instanceof LDtoInheritedReferenceImpl)) { |
| LDto _type_1 = ((LDtoInheritedReferenceImpl)feature).getType(); |
| referencedDto = _type_1; |
| LReference _inheritedFeature = ((LDtoInheritedReferenceImpl)feature).getInheritedFeature(); |
| String _name_1 = _inheritedFeature.getName(); |
| attributeName = _name_1; |
| LReference _inheritedFeature_1 = ((LDtoInheritedReferenceImpl)feature).getInheritedFeature(); |
| LMultiplicity _multiplicity_1 = _inheritedFeature_1.getMultiplicity(); |
| multiplicity = _multiplicity_1; |
| } |
| boolean _notEquals = (!Objects.equal(referencedDto, null)); |
| if (_notEquals) { |
| StringConcatenation _builder = new StringConcatenation(); |
| String _name_2 = actualDto.getName(); |
| _builder.append(_name_2, ""); |
| _builder.append("."); |
| String _name_3 = referencedDto.getName(); |
| _builder.append(_name_3, ""); |
| String lastDtoNames = _builder.toString(); |
| String[] parentNames = parentName.split("\\."); |
| StringConcatenation _builder_1 = new StringConcatenation(); |
| final String[] _converted_parentNames = (String[])parentNames; |
| int _size_2 = ((List<String>)Conversions.doWrapArray(_converted_parentNames)).size(); |
| int _minus_1 = (_size_2 - 1); |
| String _get_1 = parentNames[_minus_1]; |
| _builder_1.append(_get_1, ""); |
| _builder_1.append("."); |
| _builder_1.append(attributeName, ""); |
| String lastAttributeNames = _builder_1.toString(); |
| boolean _or = false; |
| boolean _equals = Objects.equal(previousDto, null); |
| if (_equals) { |
| _or = true; |
| } else { |
| String _name_4 = previousDto.getName(); |
| String _name_5 = referencedDto.getName(); |
| boolean _equals_1 = _name_4.equals(_name_5); |
| boolean _not = (!_equals_1); |
| _or = _not; |
| } |
| if (_or) { |
| boolean _and = false; |
| boolean _and_1 = false; |
| boolean _notEquals_1 = (!Objects.equal(multiplicity, null)); |
| if (!_notEquals_1) { |
| _and_1 = false; |
| } else { |
| boolean _contains = parentName.contains(lastAttributeNames); |
| boolean _not_1 = (!_contains); |
| _and_1 = _not_1; |
| } |
| if (!_and_1) { |
| _and = false; |
| } else { |
| String _dtoStackNames = BlipHelper.dtoStackNames(dtoStack); |
| boolean _contains_1 = _dtoStackNames.contains(lastDtoNames); |
| boolean _not_2 = (!_contains_1); |
| _and = _not_2; |
| } |
| if (_and) { |
| dtoStack.addLast(referencedDto); |
| int _size_3 = dtoStack.size(); |
| boolean _lessThan = (_size_3 < 32); |
| if (_lessThan) { |
| StringConcatenation _builder_2 = new StringConcatenation(); |
| _builder_2.append(parentName, ""); |
| _builder_2.append("."); |
| _builder_2.append(attributeName, ""); |
| BlipHelper.recursiveCompleteBlipItem_DtoPath(results, _builder_2.toString(), dtoStack); |
| } else { |
| System.err.println("BREAKING recursive inspection of dto references due to meaningful depth!"); |
| } |
| dtoStack.removeLast(); |
| } |
| } |
| } |
| } |
| } |
| } |
| |
| private static String dtoStackNames(final LinkedList<LDto> dtoStack) { |
| String names = ""; |
| final Iterator<LDto> iterator = dtoStack.iterator(); |
| while (iterator.hasNext()) { |
| StringConcatenation _builder = new StringConcatenation(); |
| _builder.append(names, ""); |
| _builder.append("."); |
| LDto _next = iterator.next(); |
| String _name = _next.getName(); |
| _builder.append(_name, ""); |
| names = _builder.toString(); |
| } |
| return names; |
| } |
| } |