Skip to main content
summaryrefslogtreecommitdiffstats
blob: ffce5ca7207504da8ced3f7ecf5fa30ea0a326b0 (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
/*******************************************************************************
 * Copyright (c) 2004, 2007 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.framework.core.model.type;

import org.eclipse.osee.framework.core.data.IArtifactType;
import org.eclipse.osee.framework.core.enums.RelationTypeMultiplicity;
import org.eclipse.osee.framework.core.enums.StorageState;
import org.eclipse.osee.framework.core.exception.OseeCoreException;
import org.eclipse.osee.framework.core.model.cache.IOseeCache;
import org.eclipse.osee.framework.core.model.cache.IOseeTypeFactory;
import org.eclipse.osee.framework.core.model.cache.RelationTypeCache;
import org.eclipse.osee.framework.core.util.Conditions;

/**
 * @author Roberto E. Escobar
 */
public class RelationTypeFactory implements IOseeTypeFactory {

   public RelationType create(String guid, String name, String sideAName, String sideBName, IArtifactType artifactTypeSideA, IArtifactType artifactTypeSideB, RelationTypeMultiplicity multiplicity, String defaultOrderTypeGuid) throws OseeCoreException {
      Conditions.checkNotNullOrEmpty(name, "relation type name");
      Conditions.checkNotNullOrEmpty(sideAName, "side A name");
      Conditions.checkNotNullOrEmpty(sideBName, "side B name");
      Conditions.checkNotNull(artifactTypeSideA, "artifact type A");
      Conditions.checkNotNull(artifactTypeSideB, "relation type B");
      Conditions.checkNotNull(multiplicity, "multiplicity");
      String checkedGuid = Conditions.checkGuidCreateIfNeeded(guid);
      return new RelationType(checkedGuid, name, sideAName, sideBName, artifactTypeSideA, artifactTypeSideB,
         multiplicity, defaultOrderTypeGuid);
   }

   public RelationType createOrUpdate(RelationTypeCache cache, String guid, String typeName, String sideAName, String sideBName, IArtifactType artifactTypeSideA, IArtifactType artifactTypeSideB, RelationTypeMultiplicity multiplicity, String defaultOrderTypeGuid) throws OseeCoreException {
      RelationType relationType = cache.getByGuid(guid);
      if (relationType == null) {
         relationType =
            create(guid, typeName, sideAName, sideBName, artifactTypeSideA, artifactTypeSideB, multiplicity,
               defaultOrderTypeGuid);
      } else {
         cache.decache(relationType);
         relationType.setFields(typeName, sideAName, sideBName, artifactTypeSideA, artifactTypeSideB, multiplicity,
            defaultOrderTypeGuid);
      }
      cache.cache(relationType);
      return relationType;
   }

   public RelationType createOrUpdate(IOseeCache<String, RelationType> cache, int typeId, StorageState storageState, String guid, String typeName, String sideAName, String sideBName, IArtifactType artifactTypeSideA, IArtifactType artifactTypeSideB, RelationTypeMultiplicity multiplicity, String defaultOrderTypeGuid) throws OseeCoreException {
      RelationType relationType = cache.getById(typeId);
      if (relationType == null) {
         relationType =
            create(guid, typeName, sideAName, sideBName, artifactTypeSideA, artifactTypeSideB, multiplicity,
               defaultOrderTypeGuid);
         relationType.setId(typeId);
         relationType.setStorageState(storageState);
      } else {
         cache.decache(relationType);
         relationType.setFields(typeName, sideAName, sideBName, artifactTypeSideA, artifactTypeSideB, multiplicity,
            defaultOrderTypeGuid);
      }
      cache.cache(relationType);
      return relationType;
   }
}

Back to the top