diff options
author | donald.g.dunne | 2017-01-04 17:02:52 +0000 |
---|---|---|
committer | donald.g.dunne | 2017-01-04 17:52:47 +0000 |
commit | d519d0245c36ecf0b1465a2500e41b7eb4ddbe05 (patch) | |
tree | 359eb2887e75badb0b8c9ee08a61c46ccd4690c3 | |
parent | 04117bfc4f64778cb004f79f29c5df5bf77ea6f1 (diff) | |
download | org.eclipse.osee-d519d0245c36ecf0b1465a2500e41b7eb4ddbe05.tar.gz org.eclipse.osee-d519d0245c36ecf0b1465a2500e41b7eb4ddbe05.tar.xz org.eclipse.osee-d519d0245c36ecf0b1465a2500e41b7eb4ddbe05.zip |
bug[ats_ATS329812]: Fix AtsChangeSet.setRelations to unrelate first0.24.3.v201701042113-NR
Change-Id: I1356269c182a5651f9fce0546acaaacadb18717c
11 files changed, 92 insertions, 39 deletions
diff --git a/plugins/org.eclipse.osee.ats.api/src/org/eclipse/osee/ats/api/user/IAtsUserService.java b/plugins/org.eclipse.osee.ats.api/src/org/eclipse/osee/ats/api/user/IAtsUserService.java index e3f5fcf54c6..8f25d7ec8ff 100644 --- a/plugins/org.eclipse.osee.ats.api/src/org/eclipse/osee/ats/api/user/IAtsUserService.java +++ b/plugins/org.eclipse.osee.ats.api/src/org/eclipse/osee/ats/api/user/IAtsUserService.java @@ -48,4 +48,6 @@ public interface IAtsUserService { List<? extends IAtsUser> getUsers(); + IAtsUser getUserByAccountId(Long accountId); + } diff --git a/plugins/org.eclipse.osee.ats.core.client/src/org/eclipse/osee/ats/core/client/internal/user/AtsUserServiceClientImpl.java b/plugins/org.eclipse.osee.ats.core.client/src/org/eclipse/osee/ats/core/client/internal/user/AtsUserServiceClientImpl.java index 8f05b815845..35a7c14855d 100644 --- a/plugins/org.eclipse.osee.ats.core.client/src/org/eclipse/osee/ats/core/client/internal/user/AtsUserServiceClientImpl.java +++ b/plugins/org.eclipse.osee.ats.core.client/src/org/eclipse/osee/ats/core/client/internal/user/AtsUserServiceClientImpl.java @@ -23,6 +23,7 @@ import org.eclipse.osee.ats.api.user.JaxAtsUser; import org.eclipse.osee.ats.core.client.IAtsUserServiceClient; import org.eclipse.osee.ats.core.users.AbstractAtsUserService; import org.eclipse.osee.ats.core.util.AtsUtilCore; +import org.eclipse.osee.framework.core.data.ArtifactId; import org.eclipse.osee.framework.core.enums.Active; import org.eclipse.osee.framework.core.enums.CoreArtifactTypes; import org.eclipse.osee.framework.core.enums.CoreAttributeTypes; @@ -176,4 +177,14 @@ public class AtsUserServiceClientImpl extends AbstractAtsUserService implements return createFromArtifact(userArt); } + @Override + protected IAtsUser loadUserByAccountId(Long accountId) { + IAtsUser user = null; + ArtifactId userArt = ArtifactQuery.getArtifactFromId(accountId.intValue(), AtsUtilCore.getAtsBranch()); + if (userArt != null) { + user = createFromArtifact((Artifact) userArt); + } + return user; + } + } diff --git a/plugins/org.eclipse.osee.ats.core/src/org/eclipse/osee/ats/core/program/AtsProgramService.java b/plugins/org.eclipse.osee.ats.core/src/org/eclipse/osee/ats/core/program/AtsProgramService.java index a42d25611bf..904086fe832 100644 --- a/plugins/org.eclipse.osee.ats.core/src/org/eclipse/osee/ats/core/program/AtsProgramService.java +++ b/plugins/org.eclipse.osee.ats.core/src/org/eclipse/osee/ats/core/program/AtsProgramService.java @@ -10,12 +10,16 @@ *******************************************************************************/ package org.eclipse.osee.ats.core.program; +import com.google.common.cache.CacheBuilder; +import com.google.common.cache.CacheLoader; +import com.google.common.cache.LoadingCache; import java.util.ArrayList; import java.util.Collection; import java.util.HashSet; import java.util.LinkedList; import java.util.List; import java.util.Set; +import java.util.concurrent.TimeUnit; import org.eclipse.osee.ats.api.IAtsObject; import org.eclipse.osee.ats.api.IAtsServices; import org.eclipse.osee.ats.api.IAtsWorkItem; @@ -53,10 +57,21 @@ import org.eclipse.osee.framework.jdk.core.util.Strings; */ public class AtsProgramService implements IAtsProgramService { - private final IAtsServices services; + static private IAtsServices services; + static CacheLoader<IAtsTeamDefinition, IAtsProgram> teamDefToAtsProgramCacheLoader = + new CacheLoader<IAtsTeamDefinition, IAtsProgram>() { + @Override + public IAtsProgram load(IAtsTeamDefinition teamDef) { + return loadProgram(teamDef); + } + }; + static private final LoadingCache<IAtsTeamDefinition, IAtsProgram> teamDefToAtsProgramCache = + CacheBuilder.newBuilder() // + .expireAfterWrite(15, TimeUnit.MINUTES) // + .build(teamDefToAtsProgramCacheLoader); public AtsProgramService(IAtsServices services) { - this.services = services; + AtsProgramService.services = services; } @Override @@ -196,6 +211,15 @@ public class AtsProgramService implements IAtsProgramService { @Override public IAtsProgram getProgram(IAtsTeamDefinition teamDef) { + try { + return teamDefToAtsProgramCache.get(teamDef); + } catch (Exception ex) { + // do nothing + } + return null; + } + + private static IAtsProgram loadProgram(IAtsTeamDefinition teamDef) { IAtsProgram program = null; Object object = services.getAttributeResolver().getSoleAttributeValue(teamDef, AtsAttributeTypes.ProgramUuid, null); @@ -207,7 +231,7 @@ public class AtsProgramService implements IAtsProgramService { if (program == null) { IAtsTeamDefinition topTeamDef = teamDef.getTeamDefinitionHoldingVersions(); if (topTeamDef != null && !teamDef.equals(topTeamDef)) { - program = getProgram(teamDef.getParentTeamDef()); + program = loadProgram(teamDef.getParentTeamDef()); } } if (program == null) { diff --git a/plugins/org.eclipse.osee.ats.core/src/org/eclipse/osee/ats/core/users/AbstractAtsUserService.java b/plugins/org.eclipse.osee.ats.core/src/org/eclipse/osee/ats/core/users/AbstractAtsUserService.java index f32be96f433..cf4889a5ab8 100644 --- a/plugins/org.eclipse.osee.ats.core/src/org/eclipse/osee/ats/core/users/AbstractAtsUserService.java +++ b/plugins/org.eclipse.osee.ats.core/src/org/eclipse/osee/ats/core/users/AbstractAtsUserService.java @@ -30,6 +30,7 @@ import org.eclipse.osee.framework.jdk.core.util.Strings; */ public abstract class AbstractAtsUserService implements IAtsUserService { + protected final Map<Long, IAtsUser> accountIdToAtsUser = new ConcurrentHashMap<>(300); protected final Map<String, IAtsUser> userIdToAtsUser = new ConcurrentHashMap<>(300); protected final Map<String, IAtsUser> nameToAtsUser = new ConcurrentHashMap<>(300); protected IAtsUser currentUser = null; @@ -80,6 +81,20 @@ public abstract class AbstractAtsUserService implements IAtsUserService { return atsUser; } + @Override + public IAtsUser getUserByAccountId(Long accountId) throws OseeCoreException { + IAtsUser atsUser = accountIdToAtsUser.get(accountId); + if (atsUser == null) { + atsUser = loadUserByAccountId(accountId); + if (atsUser != null) { + accountIdToAtsUser.put(accountId, atsUser); + } + } + return atsUser; + } + + protected abstract IAtsUser loadUserByAccountId(Long accountId); + protected abstract IAtsUser loadUserFromDbByUserId(String userId); @Override diff --git a/plugins/org.eclipse.osee.ats.core/src/org/eclipse/osee/ats/core/util/AtsUtilCore.java b/plugins/org.eclipse.osee.ats.core/src/org/eclipse/osee/ats/core/util/AtsUtilCore.java index c22ceb62cbd..2ca7633509e 100644 --- a/plugins/org.eclipse.osee.ats.core/src/org/eclipse/osee/ats/core/util/AtsUtilCore.java +++ b/plugins/org.eclipse.osee.ats.core/src/org/eclipse/osee/ats/core/util/AtsUtilCore.java @@ -20,11 +20,8 @@ import java.util.Map; import java.util.logging.Level; import org.eclipse.osee.ats.api.IAtsObject; import org.eclipse.osee.ats.api.IAtsServices; -import org.eclipse.osee.ats.api.user.IAtsUser; -import org.eclipse.osee.framework.core.data.ArtifactId; import org.eclipse.osee.framework.core.data.BranchId; import org.eclipse.osee.framework.core.data.TokenFactory; -import org.eclipse.osee.framework.core.enums.CoreAttributeTypes; import org.eclipse.osee.framework.core.enums.CoreBranches; import org.eclipse.osee.framework.jdk.core.type.Identifiable; import org.eclipse.osee.framework.jdk.core.util.Conditions; @@ -164,30 +161,6 @@ public class AtsUtilCore { return table; } - /** - * @return User by artId which is also accountId - */ - public static IAtsUser getUserByAccountId(String accountId, IAtsServices services) { - IAtsUser user = null; - if (Strings.isNumeric(accountId)) { - user = getUserByAccountId(Long.valueOf(accountId), services); - } - return user; - } - - public static IAtsUser getUserByAccountId(Long accountId, IAtsServices services) { - IAtsUser user = null; - ArtifactId userArt = services.getArtifact(accountId); - if (userArt != null) { - String userId = - services.getAttributeResolver().getSoleAttributeValue(userArt, CoreAttributeTypes.UserId, null); - if (Strings.isValid(userId)) { - user = services.getUserService().getUserById(userId); - } - } - return user; - } - public static String getActionUrl(String atsIdOrUuid, IAtsServices services) { return getActionUrl(atsIdOrUuid, ATS_DEFAULT_ACTION_URL, services); } diff --git a/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/config/AtsUserServiceServerImpl.java b/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/config/AtsUserServiceServerImpl.java index 58aedd426b1..c10b1e0c4dd 100644 --- a/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/config/AtsUserServiceServerImpl.java +++ b/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/config/AtsUserServiceServerImpl.java @@ -112,7 +112,17 @@ public class AtsUserServiceServerImpl extends AbstractAtsUserService { return createFromArtifact(userArt); } return null; + } + @Override + protected IAtsUser loadUserByAccountId(Long accountId) { + IAtsUser user = null; + ArtifactId userArt = orcsApi.getQueryFactory().fromBranch(AtsUtilCore.getAtsBranch()).andUuid( + accountId).getResults().getAtMostOneOrNull(); + if (userArt != null) { + user = createFromArtifact((ArtifactReadable) userArt); + } + return user; } } diff --git a/plugins/org.eclipse.osee.orcs.core.test/src/org/eclipse/osee/orcs/core/internal/relation/impl/RelationManagerImplTest.java b/plugins/org.eclipse.osee.orcs.core.test/src/org/eclipse/osee/orcs/core/internal/relation/impl/RelationManagerImplTest.java index 539a404012f..522227cbe83 100644 --- a/plugins/org.eclipse.osee.orcs.core.test/src/org/eclipse/osee/orcs/core/internal/relation/impl/RelationManagerImplTest.java +++ b/plugins/org.eclipse.osee.orcs.core.test/src/org/eclipse/osee/orcs/core/internal/relation/impl/RelationManagerImplTest.java @@ -74,6 +74,7 @@ import org.junit.Test; import org.junit.rules.ExpectedException; import org.mockito.ArgumentCaptor; import org.mockito.Captor; +import org.mockito.Matchers; import org.mockito.Mock; import org.mockito.MockitoAnnotations; import org.mockito.invocation.InvocationOnMock; @@ -520,7 +521,8 @@ public class RelationManagerImplTest { when(container1.getRelation(node1, TYPE_1, node2, INCLUDE_DELETED)).thenReturn(null); when(container2.getRelation(node1, TYPE_1, node2, INCLUDE_DELETED)).thenReturn(null); - when(relationFactory.createRelation(node1, TYPE_1, node2)).thenReturn(relation1); + when(relationFactory.createRelation(eq(node1), eq(TYPE_1), eq(node2), Matchers.anyString())).thenReturn( + relation1); when(orderFactory.createOrderManager(node1)).thenReturn(orderManager1); when(node1.getArtifactType()).thenReturn(artifactType1); @@ -534,7 +536,6 @@ public class RelationManagerImplTest { verify(container1).getRelation(node1, TYPE_1, node2, INCLUDE_DELETED); verify(container2).getRelation(node1, TYPE_1, node2, INCLUDE_DELETED); - verify(relationFactory).createRelation(node1, TYPE_1, node2); verify(orderManager1).setOrder(eq(typeSide), eq(LEXICOGRAPHICAL_ASC), sortedListCaptor.capture()); verify(container1).add(TYPE_1.getGuid(), relation1); verify(container2).add(TYPE_1.getGuid(), relation1); @@ -545,7 +546,8 @@ public class RelationManagerImplTest { when(container1.getRelation(node1, TYPE_1, node2, INCLUDE_DELETED)).thenReturn(null); when(container2.getRelation(node1, TYPE_1, node2, INCLUDE_DELETED)).thenReturn(null); - when(relationFactory.createRelation(node1, TYPE_1, node2)).thenReturn(relation1); + when(relationFactory.createRelation(eq(node1), eq(TYPE_1), eq(node2), Matchers.anyString())).thenReturn( + relation1); when(orderFactory.createOrderManager(node1)).thenReturn(orderManager1); @@ -561,7 +563,6 @@ public class RelationManagerImplTest { verify(container1).getRelation(node1, TYPE_1, node2, INCLUDE_DELETED); verify(container2).getRelation(node1, TYPE_1, node2, INCLUDE_DELETED); - verify(relationFactory).createRelation(node1, TYPE_1, node2); verify(orderManager1).getSorterId(typeSide); verify(orderManager1).setOrder(eq(typeSide), eq(UNORDERED), sortedListCaptor.capture()); verify(container1).add(TYPE_1.getGuid(), relation1); @@ -573,7 +574,8 @@ public class RelationManagerImplTest { when(container1.getRelation(node1, TYPE_1, node2, INCLUDE_DELETED)).thenReturn(null); when(container2.getRelation(node1, TYPE_1, node2, INCLUDE_DELETED)).thenReturn(null); - when(relationFactory.createRelation(node1, TYPE_1, node2)).thenReturn(relation1); + when(relationFactory.createRelation(eq(node1), eq(TYPE_1), eq(node2), Matchers.anyString())).thenReturn( + relation1); when(orderFactory.createOrderManager(node1)).thenReturn(orderManager1); List<Relation> toOrder = Arrays.asList(relation3, relation4); @@ -613,7 +615,9 @@ public class RelationManagerImplTest { when(container1.getRelation(node1, DEFAULT_HIERARCHY, node2, INCLUDE_DELETED)).thenReturn(null); when(container2.getRelation(node1, DEFAULT_HIERARCHY, node2, INCLUDE_DELETED)).thenReturn(null); - when(relationFactory.createRelation(node1, DEFAULT_HIERARCHY, node2)).thenReturn(relation1); + when( + relationFactory.createRelation(eq(node1), eq(DEFAULT_HIERARCHY), eq(node2), Matchers.anyString())).thenReturn( + relation1); when(orderFactory.createOrderManager(node1)).thenReturn(orderManager1); when(orderFactory.createOrderManager(node1)).thenReturn(orderManager1); @@ -639,7 +643,9 @@ public class RelationManagerImplTest { when(container1.getRelation(node1, TYPE_1, node2, INCLUDE_DELETED)).thenReturn(null); when(container2.getRelation(node1, TYPE_1, node2, INCLUDE_DELETED)).thenReturn(null); - when(relationFactory.createRelation(node1, DEFAULT_HIERARCHY, node2)).thenReturn(relation1); + when( + relationFactory.createRelation(eq(node1), eq(DEFAULT_HIERARCHY), eq(node2), Matchers.anyString())).thenReturn( + relation1); when(orderFactory.createOrderManager(node1)).thenReturn(orderManager1); when(orderManager1.getSorterId(Default_Hierarchical__Child)).thenReturn(UNORDERED); diff --git a/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/internal/relation/RelationFactory.java b/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/internal/relation/RelationFactory.java index ed524ce589e..8d7cd28515f 100644 --- a/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/internal/relation/RelationFactory.java +++ b/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/internal/relation/RelationFactory.java @@ -40,9 +40,13 @@ public class RelationFactory { } public Relation createRelation(RelationNode aNode, IRelationType type, RelationNode bNode) throws OseeCoreException { + return createRelation(aNode, type, bNode, ""); + } + + public Relation createRelation(RelationNode aNode, IRelationType type, RelationNode bNode, String rationale) throws OseeCoreException { OrcsConditions.checkBranch(aNode, bNode); OrcsConditions.checkRelateSelf(aNode, bNode); - RelationData data = relationDataFactory.createRelationData(type, aNode.getBranchId(), aNode, bNode, ""); + RelationData data = relationDataFactory.createRelationData(type, aNode.getBranchId(), aNode, bNode, rationale); return createRelation(data); } diff --git a/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/internal/relation/impl/RelationManagerImpl.java b/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/internal/relation/impl/RelationManagerImpl.java index cbe77db4d0f..beb2b4e5400 100644 --- a/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/internal/relation/impl/RelationManagerImpl.java +++ b/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/internal/relation/impl/RelationManagerImpl.java @@ -237,7 +237,7 @@ public class RelationManagerImpl implements RelationManager { Relation relation = getRelation(session, aNode, type, bNode, INCLUDE_DELETED).getOneOrNull(); boolean updated = false; if (relation == null) { - relation = relationFactory.createRelation(aNode, type, bNode); + relation = relationFactory.createRelation(aNode, type, bNode, rationale); graph.<RelationNodeAdjacencies> getAdjacencies(aNode).add(type.getGuid(), relation); graph.<RelationNodeAdjacencies> getAdjacencies(bNode).add(type.getGuid(), relation); updated = true; diff --git a/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/loader/data/OrcsObjectFactoryImpl.java b/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/loader/data/OrcsObjectFactoryImpl.java index 28dc549acf4..267bc0807aa 100644 --- a/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/loader/data/OrcsObjectFactoryImpl.java +++ b/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/loader/data/OrcsObjectFactoryImpl.java @@ -24,6 +24,7 @@ import org.eclipse.osee.framework.core.enums.BranchType; import org.eclipse.osee.framework.core.enums.ModificationType; import org.eclipse.osee.framework.core.enums.TransactionDetailsType; import org.eclipse.osee.framework.jdk.core.type.OseeCoreException; +import org.eclipse.osee.framework.jdk.core.util.Conditions; import org.eclipse.osee.framework.jdk.core.util.Lib; import org.eclipse.osee.orcs.core.ds.ArtifactData; import org.eclipse.osee.orcs.core.ds.AttributeData; @@ -176,6 +177,9 @@ public class OrcsObjectFactoryImpl implements OrcsObjectFactory { data.setBaseModType(baseModType); data.setArtIdA(aArtId); data.setArtIdB(bArtId); + Conditions.assertNotNull(rationale, + "rationale can't be null for RelationData localId [%s], localTypeId [%s], aArtId [%s], bArtId", localId, + localTypeID, aArtId, bArtId); data.setRationale(rationale); data.setApplicabilityId(applicId); return data; diff --git a/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/loader/processor/RelationLoadProcessor.java b/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/loader/processor/RelationLoadProcessor.java index 78c4dd97a0a..d7af054b8fe 100644 --- a/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/loader/processor/RelationLoadProcessor.java +++ b/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/loader/processor/RelationLoadProcessor.java @@ -62,6 +62,10 @@ public class RelationLoadProcessor extends LoadProcessor<RelationData, RelationO ModificationType modType = ModificationType.getMod(chStmt.getInt("mod_type")); String rationale = chStmt.getString("rationale"); + // Oracle returns nulls as null. HSQLDB returns as "". Rationale can not be null. + if (rationale == null) { + rationale = ""; + } toReturn = factory.createRelationData(version, localId, typeId, modType, aArtId, bArtId, rationale, applicId); |