diff options
author | donald.g.dunne | 2015-09-29 23:05:22 +0000 |
---|---|---|
committer | Ryan D. Brooks | 2015-09-29 23:05:22 +0000 |
commit | df21349e9006f29c3899442136f11585447967ee (patch) | |
tree | 903d0d4505daf6d6ccf16656c61f4d35e7cb58b9 | |
parent | 5cf5ade0214d5da64c01e5fcf7914d650df848e7 (diff) | |
download | org.eclipse.osee-df21349e9006f29c3899442136f11585447967ee.tar.gz org.eclipse.osee-df21349e9006f29c3899442136f11585447967ee.tar.xz org.eclipse.osee-df21349e9006f29c3899442136f11585447967ee.zip |
bug[ats_ATS244360]: Fix AtsClientImpl.getAtsId
Change-Id: I7d0f0ac88d43100a2f796391e4b9423b99ef7f78
13 files changed, 164 insertions, 80 deletions
diff --git a/plugins/org.eclipse.osee.ats.api/src/org/eclipse/osee/ats/api/IAtsServices.java b/plugins/org.eclipse.osee.ats.api/src/org/eclipse/osee/ats/api/IAtsServices.java index 021a0eea0f7..30fe616db84 100644 --- a/plugins/org.eclipse.osee.ats.api/src/org/eclipse/osee/ats/api/IAtsServices.java +++ b/plugins/org.eclipse.osee.ats.api/src/org/eclipse/osee/ats/api/IAtsServices.java @@ -64,7 +64,9 @@ public interface IAtsServices { ChangeType getChangeType(IAtsAction fromAction); - String getAtsId(IAtsAction action); + String getAtsId(ArtifactId artifact); + + String getAtsId(IAtsObject atsObject); Collection<IArtifactType> getArtifactTypes(); diff --git a/plugins/org.eclipse.osee.ats.core.client/src/org/eclipse/osee/ats/core/client/internal/AtsClientImpl.java b/plugins/org.eclipse.osee.ats.core.client/src/org/eclipse/osee/ats/core/client/internal/AtsClientImpl.java index 7808adbef72..31e77279161 100644 --- a/plugins/org.eclipse.osee.ats.core.client/src/org/eclipse/osee/ats/core/client/internal/AtsClientImpl.java +++ b/plugins/org.eclipse.osee.ats.core.client/src/org/eclipse/osee/ats/core/client/internal/AtsClientImpl.java @@ -105,6 +105,7 @@ import org.eclipse.osee.ats.core.config.IAtsConfig; import org.eclipse.osee.ats.core.config.ITeamDefinitionFactory; import org.eclipse.osee.ats.core.util.ActionFactory; import org.eclipse.osee.ats.core.util.AtsCoreFactory; +import org.eclipse.osee.ats.core.util.AtsCoreServiceImpl; import org.eclipse.osee.ats.core.util.AtsUtilCore; import org.eclipse.osee.ats.core.util.CacheProvider; import org.eclipse.osee.ats.core.util.IAtsActionFactory; @@ -136,7 +137,7 @@ import org.eclipse.osee.logger.Log; /** * @author Donald G. Dunne */ -public class AtsClientImpl implements IAtsClient { +public class AtsClientImpl extends AtsCoreServiceImpl implements IAtsClient { private IAtsStateFactory stateFactory; private IAtsWorkDefinitionService workDefService; @@ -262,6 +263,10 @@ public class AtsClientImpl implements IAtsClient { } + public void setAttributeResolverService(IAttributeResolver attributeResolverService) { + this.attributeResolverService = attributeResolverService; + } + @Override public IVersionFactory getVersionFactory() { return versionFactory; @@ -651,11 +656,6 @@ public class AtsClientImpl implements IAtsClient { } @Override - public String getAtsId(IAtsAction action) { - return getAtsId(action); - } - - @Override public Collection<IArtifactType> getArtifactTypes() { List<IArtifactType> types = new ArrayList<>(); types.addAll(ArtifactTypeManager.getAllTypes()); diff --git a/plugins/org.eclipse.osee.ats.core.test/src/org/eclipse/osee/ats/core/util/AtsCoreServiceImplTest.java b/plugins/org.eclipse.osee.ats.core.test/src/org/eclipse/osee/ats/core/util/AtsCoreServiceImplTest.java new file mode 100644 index 00000000000..a4dded8b1bc --- /dev/null +++ b/plugins/org.eclipse.osee.ats.core.test/src/org/eclipse/osee/ats/core/util/AtsCoreServiceImplTest.java @@ -0,0 +1,62 @@ +/******************************************************************************* + * Copyright (c) 2015 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.core.util; + +import static org.junit.Assert.assertEquals; +import static org.mockito.Mockito.when; +import org.eclipse.osee.ats.api.IAtsObject; +import org.eclipse.osee.ats.api.data.AtsAttributeTypes; +import org.eclipse.osee.ats.api.workdef.IAttributeResolver; +import org.eclipse.osee.framework.core.data.ArtifactId; +import org.junit.Before; +import org.junit.Test; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; + +/** + * Test Case for {@link AtsCoreServiceImpl} + * + * @author Donald G. Dunne + */ +public class AtsCoreServiceImplTest { + + // @formatter:off + @Mock private ArtifactId artifact; + @Mock private IAtsObject atsObject; + @Mock private IAttributeResolver attrResolver; + // @formatter:on + + @Before + public void setup() { + MockitoAnnotations.initMocks(this); + } + + @Test + public void testGetAtsId() { + when(attrResolver.getSoleAttributeValue(artifact, AtsAttributeTypes.AtsId, null)).thenReturn(null); + when(artifact.getGuid()).thenReturn("guid"); + String result = AtsCoreServiceImpl.getAtsId(attrResolver, artifact); + assertEquals(result, "guid"); + + when(attrResolver.getSoleAttributeValue(atsObject, AtsAttributeTypes.AtsId, null)).thenReturn(null); + when(atsObject.getStoreObject()).thenReturn(artifact); + result = AtsCoreServiceImpl.getAtsId(attrResolver, atsObject); + assertEquals(result, "guid"); + + when(attrResolver.getSoleAttributeValue(artifact, AtsAttributeTypes.AtsId, null)).thenReturn("ATS23"); + result = AtsCoreServiceImpl.getAtsId(attrResolver, artifact); + assertEquals(result, "ATS23"); + + when(attrResolver.getSoleAttributeValue(atsObject, AtsAttributeTypes.AtsId, null)).thenReturn("ATS23"); + assertEquals(result, "ATS23"); + } + +} diff --git a/plugins/org.eclipse.osee.ats.core/src/org/eclipse/osee/ats/core/util/AtsCoreServiceImpl.java b/plugins/org.eclipse.osee.ats.core/src/org/eclipse/osee/ats/core/util/AtsCoreServiceImpl.java new file mode 100644 index 00000000000..41fe9766f11 --- /dev/null +++ b/plugins/org.eclipse.osee.ats.core/src/org/eclipse/osee/ats/core/util/AtsCoreServiceImpl.java @@ -0,0 +1,49 @@ +/******************************************************************************* + * Copyright (c) 2015 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.core.util; + +import org.eclipse.osee.ats.api.IAtsObject; +import org.eclipse.osee.ats.api.IAtsServices; +import org.eclipse.osee.ats.api.data.AtsAttributeTypes; +import org.eclipse.osee.ats.api.workdef.IAttributeResolver; +import org.eclipse.osee.framework.core.data.ArtifactId; +import org.eclipse.osee.framework.jdk.core.util.Conditions; + +/** + * @author Donald G. Dunne + */ +public abstract class AtsCoreServiceImpl implements IAtsServices { + + @Override + public String getAtsId(ArtifactId artifact) { + return getAtsId(getAttributeResolver(), artifact); + } + + @Override + public String getAtsId(IAtsObject atsObject) { + return getAtsId(getAttributeResolver(), atsObject.getStoreObject()); + } + + protected static String getAtsId(IAttributeResolver attrResolver, IAtsObject atsObject) { + return getAtsId(attrResolver, atsObject.getStoreObject()); + } + + protected static String getAtsId(IAttributeResolver attrResolver, ArtifactId artifact) { + ArtifactId art = artifact.getStoreObject(); + Conditions.checkNotNull(art, "artifact"); + String toReturn = attrResolver.getSoleAttributeValue(art, AtsAttributeTypes.AtsId, null); + if (toReturn == null) { + toReturn = art.getGuid(); + } + return toReturn; + } + +} diff --git a/plugins/org.eclipse.osee.ats.impl.test/src/org/eclipse/osee/ats/impl/AllAtsImplTestSuite.java b/plugins/org.eclipse.osee.ats.impl.test/src/org/eclipse/osee/ats/impl/AllAtsImplTestSuite.java index e6abf4446bf..4e2bea2cf7f 100644 --- a/plugins/org.eclipse.osee.ats.impl.test/src/org/eclipse/osee/ats/impl/AllAtsImplTestSuite.java +++ b/plugins/org.eclipse.osee.ats.impl.test/src/org/eclipse/osee/ats/impl/AllAtsImplTestSuite.java @@ -10,7 +10,6 @@ *******************************************************************************/ package org.eclipse.osee.ats.impl; -import org.eclipse.osee.ats.impl.internal.AtsServerImplTest; import org.eclipse.osee.ats.impl.internal.notify.AtsImpl_Notify_Suite; import org.eclipse.osee.ats.impl.util.AtsImpl_Util_Suite; import org.junit.runner.RunWith; @@ -20,7 +19,7 @@ import org.junit.runners.Suite; * @author Donald G. Dunne */ @RunWith(Suite.class) -@Suite.SuiteClasses({AtsServerImplTest.class, AtsImpl_Notify_Suite.class, AtsImpl_Util_Suite.class}) +@Suite.SuiteClasses({AtsImpl_Notify_Suite.class, AtsImpl_Util_Suite.class}) public class AllAtsImplTestSuite { // Test Suite } diff --git a/plugins/org.eclipse.osee.ats.impl.test/src/org/eclipse/osee/ats/impl/internal/AtsServerImplTest.java b/plugins/org.eclipse.osee.ats.impl.test/src/org/eclipse/osee/ats/impl/internal/AtsServerImplTest.java deleted file mode 100644 index 8fbe6183f13..00000000000 --- a/plugins/org.eclipse.osee.ats.impl.test/src/org/eclipse/osee/ats/impl/internal/AtsServerImplTest.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Created on Aug 12, 2014 - * - * PLACE_YOUR_DISTRIBUTION_STATEMENT_RIGHT_HERE - */ -package org.eclipse.osee.ats.impl.internal; - -import static org.mockito.Mockito.when; -import org.eclipse.osee.ats.api.data.AtsAttributeTypes; -import org.eclipse.osee.ats.api.workflow.IAtsTeamWorkflow; -import org.eclipse.osee.ats.core.util.AtsUtilCore; -import org.eclipse.osee.orcs.data.ArtifactReadable; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; -import org.mockito.Mock; -import org.mockito.MockitoAnnotations; - -/** - * @author Donald G. Dunne - */ -public class AtsServerImplTest { - - // @formatter:off - @Mock private IAtsTeamWorkflow teamWf; - @Mock private ArtifactReadable teamArt; - // @formatter:on - - @Before - public void setup() { - MockitoAnnotations.initMocks(this); - } - - @Test - public void testGetAtsId() { - when(teamWf.getStoreObject()).thenReturn(teamArt); - when(teamArt.getSoleAttributeAsString(AtsAttributeTypes.AtsId, AtsUtilCore.DEFAULT_ATS_ID_VALUE)).thenReturn( - "ATS123"); - - AtsServerImpl serverImpl = new AtsServerImpl(); - Assert.assertEquals("ATS123", serverImpl.getAtsId(teamWf)); - } -} diff --git a/plugins/org.eclipse.osee.ats.impl/src/org/eclipse/osee/ats/impl/IAtsServer.java b/plugins/org.eclipse.osee.ats.impl/src/org/eclipse/osee/ats/impl/IAtsServer.java index e162adab701..4514e8eb49b 100644 --- a/plugins/org.eclipse.osee.ats.impl/src/org/eclipse/osee/ats/impl/IAtsServer.java +++ b/plugins/org.eclipse.osee.ats.impl/src/org/eclipse/osee/ats/impl/IAtsServer.java @@ -91,8 +91,6 @@ public interface IAtsServer extends IAtsServices, IAtsNotifier, IAtsConfigItemFa List<IAtsWorkItem> getWorkItemListByIds(String id); - String getAtsId(Object obj); - void setEmailEnabled(boolean emailEnabled); IAtsProgramService getProgramService(); diff --git a/plugins/org.eclipse.osee.ats.impl/src/org/eclipse/osee/ats/impl/internal/AtsServerImpl.java b/plugins/org.eclipse.osee.ats.impl/src/org/eclipse/osee/ats/impl/internal/AtsServerImpl.java index 116590641a0..5af2a2860c1 100644 --- a/plugins/org.eclipse.osee.ats.impl/src/org/eclipse/osee/ats/impl/internal/AtsServerImpl.java +++ b/plugins/org.eclipse.osee.ats.impl/src/org/eclipse/osee/ats/impl/internal/AtsServerImpl.java @@ -59,6 +59,7 @@ import org.eclipse.osee.ats.core.ai.ActionableItemManager; import org.eclipse.osee.ats.core.config.IAtsConfig; import org.eclipse.osee.ats.core.util.ActionFactory; import org.eclipse.osee.ats.core.util.AtsCoreFactory; +import org.eclipse.osee.ats.core.util.AtsCoreServiceImpl; import org.eclipse.osee.ats.core.util.AtsUtilCore; import org.eclipse.osee.ats.core.util.IAtsActionFactory; import org.eclipse.osee.ats.core.workdef.AtsWorkDefinitionAdminImpl; @@ -96,7 +97,6 @@ import org.eclipse.osee.framework.core.enums.CoreBranches; import org.eclipse.osee.framework.jdk.core.type.ItemDoesNotExist; import org.eclipse.osee.framework.jdk.core.type.OseeCoreException; import org.eclipse.osee.framework.jdk.core.type.OseeStateException; -import org.eclipse.osee.framework.jdk.core.util.Conditions; import org.eclipse.osee.framework.jdk.core.util.GUID; import org.eclipse.osee.jdbc.JdbcClient; import org.eclipse.osee.jdbc.JdbcService; @@ -108,7 +108,7 @@ import org.eclipse.osee.orcs.search.QueryBuilder; /** * @author Donald G Dunne */ -public class AtsServerImpl implements IAtsServer { +public class AtsServerImpl extends AtsCoreServiceImpl implements IAtsServer { public static String PLUGIN_ID = "org.eclipse.osee.ats.rest"; private OrcsApi orcsApi; @@ -508,22 +508,6 @@ public class AtsServerImpl implements IAtsServer { } @Override - public String getAtsId(Object obj) { - ArtifactReadable art = null; - if (obj instanceof ArtifactReadable) { - art = (ArtifactReadable) obj; - } else if (obj instanceof IAtsObject) { - art = (ArtifactReadable) ((IAtsObject) obj).getStoreObject(); - } - Conditions.checkNotNull(art, "artifact"); - String toReturn = art.getSoleAttributeAsString(AtsAttributeTypes.AtsId, AtsUtilCore.DEFAULT_ATS_ID_VALUE); - if (AtsUtilCore.DEFAULT_ATS_ID_VALUE.equals(toReturn)) { - toReturn = art.getGuid(); - } - return toReturn; - } - - @Override public void setChangeType(IAtsObject atsObject, ChangeType changeType, IAtsChangeSet changes) { ChangeTypeUtil.setChangeType(atsObject, changeType, changes); } @@ -534,11 +518,6 @@ public class AtsServerImpl implements IAtsServer { } @Override - public String getAtsId(IAtsAction action) { - return getAtsId(action); - } - - @Override public Collection<IArtifactType> getArtifactTypes() { List<IArtifactType> types = new ArrayList<>(); types.addAll(orcsApi.getOrcsTypes().getArtifactTypes().getAll()); diff --git a/plugins/org.eclipse.osee.framework.core/src/org/eclipse/osee/framework/core/data/ArtifactId.java b/plugins/org.eclipse.osee.framework.core/src/org/eclipse/osee/framework/core/data/ArtifactId.java index 0e52dbb1645..f80145b7f17 100644 --- a/plugins/org.eclipse.osee.framework.core/src/org/eclipse/osee/framework/core/data/ArtifactId.java +++ b/plugins/org.eclipse.osee.framework.core/src/org/eclipse/osee/framework/core/data/ArtifactId.java @@ -16,5 +16,9 @@ import org.eclipse.osee.framework.jdk.core.type.Identifiable; * @author Megumi Telles */ public interface ArtifactId extends Identifiable<String>, HasUuid { - // + + String toStringWithId(); + + ArtifactId getStoreObject(); + } diff --git a/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/artifact/Artifact.java b/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/artifact/Artifact.java index 0c3df05f4d0..2b57417e7af 100644 --- a/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/artifact/Artifact.java +++ b/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/artifact/Artifact.java @@ -260,6 +260,7 @@ public class Artifact extends FullyNamedIdentity<String>implements IArtifact, IA /* * Provide easy way to display/report [name][uuid] */ + @Override public final String toStringWithId() { return String.format("[%s][%s]", getSafeName(), getUuid()); } @@ -1748,4 +1749,9 @@ public class Artifact extends FullyNamedIdentity<String>implements IArtifact, IA return artifact; } + @Override + public ArtifactId getStoreObject() { + return this; + } + } diff --git a/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/internal/artifact/ArtifactImpl.java b/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/internal/artifact/ArtifactImpl.java index edcd8f7610e..77e3e418336 100644 --- a/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/internal/artifact/ArtifactImpl.java +++ b/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/internal/artifact/ArtifactImpl.java @@ -11,6 +11,7 @@ package org.eclipse.osee.orcs.core.internal.artifact; import java.util.Collection; +import org.eclipse.osee.framework.core.data.ArtifactId; import org.eclipse.osee.framework.core.data.IArtifactType; import org.eclipse.osee.framework.core.data.IAttributeType; import org.eclipse.osee.framework.core.data.IOseeBranch; @@ -167,7 +168,8 @@ public class ArtifactImpl extends AttributeManagerImpl implements Artifact { @Override public String getExceptionString() { try { - return String.format("artifact type[%s] guid[%s] on branch[%s]", getArtifactType(), getGuid(), getBranchUuid()); + return String.format("artifact type[%s] guid[%s] on branch[%s]", getArtifactType(), getGuid(), + getBranchUuid()); } catch (OseeCoreException ex) { return Lib.exceptionToString(ex); } @@ -231,4 +233,14 @@ public class ArtifactImpl extends AttributeManagerImpl implements Artifact { return getLocalId(); } + @Override + public String toStringWithId() { + return String.format("[%s][%s]", getName(), getUuid()); + } + + @Override + public ArtifactId getStoreObject() { + return this; + } + } diff --git a/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/internal/proxy/impl/ArtifactReadOnlyImpl.java b/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/internal/proxy/impl/ArtifactReadOnlyImpl.java index 685ed6d62dd..1dd5258bd50 100644 --- a/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/internal/proxy/impl/ArtifactReadOnlyImpl.java +++ b/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/internal/proxy/impl/ArtifactReadOnlyImpl.java @@ -15,6 +15,7 @@ import java.util.ArrayList; import java.util.Collection; import java.util.LinkedList; import java.util.List; +import org.eclipse.osee.framework.core.data.ArtifactId; import org.eclipse.osee.framework.core.data.AttributeId; import org.eclipse.osee.framework.core.data.IArtifactType; import org.eclipse.osee.framework.core.data.IAttributeType; @@ -298,4 +299,9 @@ public class ArtifactReadOnlyImpl extends AbstractProxied<Artifact>implements Ar return String.format("[%s][%s]", getName(), getUuid()); } + @Override + public ArtifactId getStoreObject() { + return this; + } + } diff --git a/plugins/org.eclipse.osee.orcs/src/org/eclipse/osee/orcs/utility/OrcsUtil.java b/plugins/org.eclipse.osee.orcs/src/org/eclipse/osee/orcs/utility/OrcsUtil.java index bff581bdf60..463564a4135 100644 --- a/plugins/org.eclipse.osee.orcs/src/org/eclipse/osee/orcs/utility/OrcsUtil.java +++ b/plugins/org.eclipse.osee.orcs/src/org/eclipse/osee/orcs/utility/OrcsUtil.java @@ -26,7 +26,7 @@ public final class OrcsUtil { return new ArtifactToken(uuid, guid, name); } - private static class ArtifactToken extends NamedIdentity<String> implements ArtifactId { + private static class ArtifactToken extends NamedIdentity<String>implements ArtifactId { private final long uuid; public ArtifactToken(long uuid, String guid, String name) { @@ -38,6 +38,16 @@ public final class OrcsUtil { public long getUuid() { return uuid; } + + @Override + public String toStringWithId() { + return String.format("[%s][%s]", getName(), getUuid()); + } + + @Override + public ArtifactId getStoreObject() { + return this; + } } } |