|
| 1 | +/* |
| 2 | + * Copyright 2021 The Context Mapper Project Team |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | +package org.contextmapper.archunit.conditions; |
| 17 | + |
| 18 | +import com.tngtech.archunit.core.domain.JavaClass; |
| 19 | +import com.tngtech.archunit.lang.ArchCondition; |
| 20 | +import com.tngtech.archunit.lang.ConditionEvents; |
| 21 | +import com.tngtech.archunit.lang.SimpleConditionEvent; |
| 22 | +import org.contextmapper.dsl.contextMappingDSL.BoundedContext; |
| 23 | +import org.contextmapper.tactic.dsl.tacticdsl.ValueObject; |
| 24 | +import org.eclipse.xtext.EcoreUtil2; |
| 25 | + |
| 26 | +import java.util.List; |
| 27 | + |
| 28 | +public class ModeledAsValueObjectInContext extends ArchCondition<JavaClass> { |
| 29 | + |
| 30 | + private final BoundedContext cmlContext; |
| 31 | + |
| 32 | + private ModeledAsValueObjectInContext(String description, BoundedContext cmlContext) { |
| 33 | + super(description, new Object[0]); |
| 34 | + this.cmlContext = cmlContext; |
| 35 | + } |
| 36 | + |
| 37 | + @Override |
| 38 | + public void check(JavaClass javaClass, ConditionEvents events) { |
| 39 | + List<ValueObject> valueObjects = EcoreUtil2.eAllOfType(cmlContext, ValueObject.class); |
| 40 | + events.add(new SimpleConditionEvent(javaClass, valueObjects.stream() |
| 41 | + .anyMatch(vo -> vo.getName().equals(javaClass.getSimpleName())), |
| 42 | + String.format("The value object '%s' is not modeled in CML.", javaClass.getSimpleName()))); |
| 43 | + } |
| 44 | + |
| 45 | + public static ModeledAsValueObjectInContext beModeledAsValueObjectInCML(BoundedContext cmlContext) { |
| 46 | + return new ModeledAsValueObjectInContext("be modeled as value object in CML.", cmlContext); |
| 47 | + } |
| 48 | + |
| 49 | +} |
0 commit comments