blob: 53dec3473499fd3fbd632dbabfba774e4472d2b0 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
|
/*******************************************************************************
* Copyright (c) 2010 Boeing.
* 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:
* Boeing - initial API and implementation
*******************************************************************************/
package org.eclipse.osee.ats.util.validate;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.osee.framework.core.data.IArtifactType;
import org.eclipse.osee.framework.core.data.IRelationTypeSide;
import org.eclipse.osee.framework.core.model.type.ArtifactType;
import org.eclipse.osee.framework.jdk.core.type.OseeCoreException;
import org.eclipse.osee.framework.skynet.core.artifact.Artifact;
/**
* @author Donald G. Dunne
*/
public final class RelationSetRule extends AbstractValidationRule {
private final IArtifactType artifactType;
private final Integer minimumRelations;
private final IRelationTypeSide relationEnum;
private final Collection<IArtifactType> ignoreArtifactTypes;
public RelationSetRule(IArtifactType artifactType, IRelationTypeSide relationEnum, Integer minimumRelations, IArtifactType... ignoreArtifactTypes) {
this.artifactType = artifactType;
this.relationEnum = relationEnum;
this.minimumRelations = minimumRelations;
this.ignoreArtifactTypes =
(ignoreArtifactTypes.length == 0 ? new ArrayList<IArtifactType>() : Arrays.asList(ignoreArtifactTypes));
}
public Integer getMinimumRelations() {
return minimumRelations;
}
public boolean hasArtifactType(ArtifactType artType) {
return artType.inheritsFrom(artifactType);
}
public IRelationTypeSide getRelationEnum() {
return relationEnum;
}
@Override
protected ValidationResult validate(Artifact artToValidate, IProgressMonitor monitor) throws OseeCoreException {
Collection<String> errorMessages = new ArrayList<String>();
boolean validationPassed = true;
ArtifactType type = artToValidate.getArtifactType();
if (!isIgnoreType(type) && hasArtifactType(type)) {
Collection<Artifact> arts = artToValidate.getRelatedArtifacts(relationEnum);
if (arts.size() < minimumRelations) {
errorMessages.add(ValidationReportOperation.getRequirementHyperlink(artToValidate) + " (" + artToValidate.getGammaId() + ") has less than minimum " + minimumRelations + " relation for type \"" + relationEnum.getName() + "\"");
validationPassed = false;
}
}
return new ValidationResult(errorMessages, validationPassed);
}
@Override
public String getRuleDescription() {
return "<b>Relations Check: </b>" + "For \"" + artifactType + "\", ensure at least " + minimumRelations + " relations(s) of type \"" + relationEnum + "\" exists";
}
@Override
public String getRuleTitle() {
return "Relations Check:";
}
private Collection<IArtifactType> getIgnoreArtifactTypes() {
return ignoreArtifactTypes;
}
private boolean isIgnoreType(IArtifactType type) {
return getIgnoreArtifactTypes().contains(type);
}
}
|