diff options
author | donald.g.dunne | 2016-08-10 16:31:09 +0000 |
---|---|---|
committer | Ryan D. Brooks | 2016-08-31 16:18:33 +0000 |
commit | d7738a1ce81e2ca20e90f63c610d32a461a0ac17 (patch) | |
tree | ee2ad2e3108cde4de77a18b24273b51103105833 | |
parent | fd2836e03129da126b7449004131016676a9a644 (diff) | |
download | org.eclipse.osee-d7738a1ce81e2ca20e90f63c610d32a461a0ac17.tar.gz org.eclipse.osee-d7738a1ce81e2ca20e90f63c610d32a461a0ac17.tar.xz org.eclipse.osee-d7738a1ce81e2ca20e90f63c610d32a461a0ac17.zip |
bug[ats_ATS307497]: Consolidate AtsUserServiceImpl
Change-Id: Id43047620cc36e133e96cb5e36f4818e9a524229
43 files changed, 675 insertions, 753 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 cf880bfba61..2edb2a3c7f1 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 @@ -14,6 +14,7 @@ import java.util.Collection; import org.eclipse.osee.ats.api.column.IAtsColumnService; import org.eclipse.osee.ats.api.config.AtsConfigurations; import org.eclipse.osee.ats.api.config.IAtsCache; +import org.eclipse.osee.ats.api.config.IAtsConfigurationProvider; import org.eclipse.osee.ats.api.ev.IAtsEarnedValueService; import org.eclipse.osee.ats.api.ev.IAtsEarnedValueServiceProvider; import org.eclipse.osee.ats.api.program.IAtsProgramService; @@ -49,7 +50,7 @@ import org.eclipse.osee.logger.Log; /** * @author Donald G. Dunne */ -public interface IAtsServices { +public interface IAtsServices extends IAtsConfigurationProvider { IRelationResolver getRelationResolver(); @@ -113,6 +114,7 @@ public interface IAtsServices { IAtsEarnedValueService getEarnedValueService(); + @Override AtsConfigurations getConfigurations(); IAtsEarnedValueServiceProvider getEarnedValueServiceProvider(); diff --git a/plugins/org.eclipse.osee.ats.api/src/org/eclipse/osee/ats/api/agile/AgileItem.java b/plugins/org.eclipse.osee.ats.api/src/org/eclipse/osee/ats/api/agile/AgileItem.java index 74c2629caf4..4ca0bba9db7 100644 --- a/plugins/org.eclipse.osee.ats.api/src/org/eclipse/osee/ats/api/agile/AgileItem.java +++ b/plugins/org.eclipse.osee.ats.api/src/org/eclipse/osee/ats/api/agile/AgileItem.java @@ -74,12 +74,12 @@ public class AgileItem extends JaxAtsObject { } @Override - public long getUuid() { + public Long getUuid() { return uuid; } @Override - public void setUuid(long uuid) { + public void setUuid(Long uuid) { this.uuid = uuid; } diff --git a/plugins/org.eclipse.osee.ats.api/src/org/eclipse/osee/ats/api/config/AtsConfigurations.java b/plugins/org.eclipse.osee.ats.api/src/org/eclipse/osee/ats/api/config/AtsConfigurations.java index a7b8b82f7f4..fb51505580c 100644 --- a/plugins/org.eclipse.osee.ats.api/src/org/eclipse/osee/ats/api/config/AtsConfigurations.java +++ b/plugins/org.eclipse.osee.ats.api/src/org/eclipse/osee/ats/api/config/AtsConfigurations.java @@ -13,6 +13,7 @@ package org.eclipse.osee.ats.api.config; import java.util.ArrayList; import java.util.List; import javax.xml.bind.annotation.XmlRootElement; +import org.eclipse.osee.ats.api.user.JaxAtsUser; import org.eclipse.osee.ats.api.util.ColorColumns; /** @@ -24,6 +25,9 @@ public class AtsConfigurations { private final List<AtsConfiguration> configs = new ArrayList<>(); private AtsViews views = new AtsViews(); private ColorColumns colorColumns = new ColorColumns(); + List<JaxAtsUser> users = new ArrayList<>(); + List<JaxAtsUser> atsAdmins = new ArrayList<>(); + List<Integer> atsActiveConfigIds = new ArrayList<>(); public List<AtsConfiguration> getConfigs() { return configs; @@ -45,4 +49,24 @@ public class AtsConfigurations { this.colorColumns = colorColumns; } + public List<JaxAtsUser> getUsers() { + return users; + } + + public void setUsers(List<JaxAtsUser> users) { + this.users = users; + } + + public List<JaxAtsUser> getAtsAdmins() { + return atsAdmins; + } + + public List<Integer> getAtsActiveConfigIds() { + return atsActiveConfigIds; + } + + public void setAtsActiveConfigIds(List<Integer> atsActiveConfigIds) { + this.atsActiveConfigIds = atsActiveConfigIds; + } + } diff --git a/plugins/org.eclipse.osee.ats.api/src/org/eclipse/osee/ats/api/config/IAtsConfigurationProvider.java b/plugins/org.eclipse.osee.ats.api/src/org/eclipse/osee/ats/api/config/IAtsConfigurationProvider.java new file mode 100644 index 00000000000..f365cc788c5 --- /dev/null +++ b/plugins/org.eclipse.osee.ats.api/src/org/eclipse/osee/ats/api/config/IAtsConfigurationProvider.java @@ -0,0 +1,22 @@ +/******************************************************************************* + * Copyright (c) 2016 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.api.config; + +/** + * @author Donald G. Dunne + */ +public interface IAtsConfigurationProvider { + + AtsConfigurations getConfigurations(); + + void clearConfigurationsCaches(); + +} diff --git a/plugins/org.eclipse.osee.ats.api/src/org/eclipse/osee/ats/api/config/JaxAtsObject.java b/plugins/org.eclipse.osee.ats.api/src/org/eclipse/osee/ats/api/config/JaxAtsObject.java index f055579e079..d9bcb39232a 100644 --- a/plugins/org.eclipse.osee.ats.api/src/org/eclipse/osee/ats/api/config/JaxAtsObject.java +++ b/plugins/org.eclipse.osee.ats.api/src/org/eclipse/osee/ats/api/config/JaxAtsObject.java @@ -14,6 +14,7 @@ import javax.xml.bind.annotation.XmlRootElement; import org.codehaus.jackson.map.annotate.JsonSerialize; import org.codehaus.jackson.map.ser.std.ToStringSerializer; import org.eclipse.osee.ats.api.IAtsObject; +import org.eclipse.osee.framework.core.data.ArtifactId; import org.eclipse.osee.framework.jdk.core.type.UuidIdentity; /** @@ -24,7 +25,7 @@ public class JaxAtsObject { private String name; @JsonSerialize(using = ToStringSerializer.class) - private long uuid; + private Long uuid; private boolean active; private String description; @@ -36,14 +37,14 @@ public class JaxAtsObject { this.name = name; } - public long getUuid() { + public Long getUuid() { return uuid; } /** * Provided for deserialization. Setting will not apply to new artifact. */ - public void setUuid(long uuid) { + public void setUuid(Long uuid) { this.uuid = uuid; } @@ -106,6 +107,12 @@ public class JaxAtsObject { return true; } } + if (obj instanceof ArtifactId) { + ArtifactId other = (ArtifactId) obj; + if (other.getUuid().equals(uuid)) { + return true; + } + } return false; } diff --git a/plugins/org.eclipse.osee.ats.api/src/org/eclipse/osee/ats/api/task/NewTaskData.java b/plugins/org.eclipse.osee.ats.api/src/org/eclipse/osee/ats/api/task/NewTaskData.java index a29b792ba39..990e5e23c81 100644 --- a/plugins/org.eclipse.osee.ats.api/src/org/eclipse/osee/ats/api/task/NewTaskData.java +++ b/plugins/org.eclipse.osee.ats.api/src/org/eclipse/osee/ats/api/task/NewTaskData.java @@ -13,6 +13,8 @@ package org.eclipse.osee.ats.api.task; import java.util.ArrayList; import java.util.List; import javax.xml.bind.annotation.XmlRootElement; +import org.codehaus.jackson.map.annotate.JsonSerialize; +import org.codehaus.jackson.map.ser.std.ToStringSerializer; /** * @author Donald G. Dunne @@ -20,6 +22,7 @@ import javax.xml.bind.annotation.XmlRootElement; @XmlRootElement public class NewTaskData { + @JsonSerialize(using = ToStringSerializer.class) Long teamWfUuid; List<JaxAtsTask> newTasks; String asUserId; 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 2d71e0526f7..e3f5fcf54c6 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 @@ -12,7 +12,6 @@ package org.eclipse.osee.ats.api.user; import java.util.Collection; import java.util.List; -import org.eclipse.osee.ats.api.IAtsWorkItem; import org.eclipse.osee.framework.core.enums.Active; import org.eclipse.osee.framework.jdk.core.type.OseeCoreException; @@ -43,12 +42,10 @@ public interface IAtsUserService { List<IAtsUser> getUsersSortedByName(Active active); - void clearCache(); + void reloadCache(); void releaseUser(); - Collection<IAtsUser> getSubscribed(IAtsWorkItem workItem); - - IAtsUser getUserById(long accountId); + List<? extends IAtsUser> getUsers(); } diff --git a/plugins/org.eclipse.osee.ats.api/src/org/eclipse/osee/ats/api/user/IUserArtLoader.java b/plugins/org.eclipse.osee.ats.api/src/org/eclipse/osee/ats/api/user/IUserArtLoader.java new file mode 100644 index 00000000000..b0cae41b3d9 --- /dev/null +++ b/plugins/org.eclipse.osee.ats.api/src/org/eclipse/osee/ats/api/user/IUserArtLoader.java @@ -0,0 +1,22 @@ +/******************************************************************************* + * Copyright (c) 2016 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.api.user; + +import org.eclipse.osee.framework.core.data.ArtifactId; + +/** + * @author Donald G. Dunne + */ +public interface IUserArtLoader { + + public ArtifactId loadUser(IAtsUser user); + +} diff --git a/plugins/org.eclipse.osee.ats.api/src/org/eclipse/osee/ats/api/user/JaxAtsUser.java b/plugins/org.eclipse.osee.ats.api/src/org/eclipse/osee/ats/api/user/JaxAtsUser.java index 216bcb1fa45..eea8d51a059 100644 --- a/plugins/org.eclipse.osee.ats.api/src/org/eclipse/osee/ats/api/user/JaxAtsUser.java +++ b/plugins/org.eclipse.osee.ats.api/src/org/eclipse/osee/ats/api/user/JaxAtsUser.java @@ -19,11 +19,14 @@ import org.eclipse.osee.framework.core.data.ArtifactId; * @author Donald G. Dunne */ @XmlRootElement -public class JaxAtsUser extends JaxAtsObject { +public class JaxAtsUser extends JaxAtsObject implements IAtsUser { private String userId; private String email; + private ArtifactId storeObject; + private IUserArtLoader userArtLoader; + @Override public String getUserId() { return userId; } @@ -32,6 +35,7 @@ public class JaxAtsUser extends JaxAtsObject { this.userId = userId; } + @Override public String getEmail() { return email; } @@ -40,18 +44,33 @@ public class JaxAtsUser extends JaxAtsObject { this.email = email; } + @Override public String toStringWithId() { return String.format("[%s]-[%d]", getName(), getUserId()); } + @Override @JsonIgnore public ArtifactId getStoreObject() { - return null; + if (storeObject == null && userArtLoader != null) { + storeObject = userArtLoader.loadUser(this); + } + return storeObject; } @Override - public long getUuid() { + public Long getUuid() { return super.getUuid(); } + @Override + public void setStoreObject(ArtifactId artifact) { + this.storeObject = artifact; + } + + @JsonIgnore + public void setUserArtLoader(IUserArtLoader userArtLoader) { + this.userArtLoader = userArtLoader; + } + } diff --git a/plugins/org.eclipse.osee.ats.client.integration.tests/src/org/eclipse/osee/ats/client/integration/tests/ats/DemoCountryConfigTest.java b/plugins/org.eclipse.osee.ats.client.integration.tests/src/org/eclipse/osee/ats/client/integration/tests/ats/DemoCountryConfigTest.java index 4fbbadbe2b9..45a9d7ced71 100644 --- a/plugins/org.eclipse.osee.ats.client.integration.tests/src/org/eclipse/osee/ats/client/integration/tests/ats/DemoCountryConfigTest.java +++ b/plugins/org.eclipse.osee.ats.client.integration.tests/src/org/eclipse/osee/ats/client/integration/tests/ats/DemoCountryConfigTest.java @@ -65,7 +65,7 @@ public class DemoCountryConfigTest { List<JaxCountry> countries = AtsClientService.getCountryEp().get(); JaxCountry usgCountry = null; for (JaxCountry country : countries) { - if (country.getUuid() == DemoCountry.usg.getUuid()) { + if (country.getUuid().equals(DemoCountry.usg.getUuid())) { usgCountry = country; break; } @@ -79,7 +79,7 @@ public class DemoCountryConfigTest { JaxProgram sawProgram = null; for (JaxProgram program : programs) { - if (program.getUuid() == DemoProgram.sawProgram.getUuid()) { + if (program.getUuid().equals(DemoProgram.sawProgram.getUuid())) { sawProgram = program; break; } @@ -93,7 +93,7 @@ public class DemoCountryConfigTest { JaxInsertion sawCommInsertion = null; for (JaxInsertion insertion : insertions) { - if (insertion.getUuid() == DemoInsertion.sawComm.getUuid()) { + if (insertion.getUuid().equals(DemoInsertion.sawComm.getUuid())) { sawCommInsertion = insertion; break; } @@ -108,7 +108,7 @@ public class DemoCountryConfigTest { JaxInsertionActivity commPageInsertionActivity = null; for (JaxInsertionActivity activity : insertionActivities) { - if (activity.getUuid() == DemoInsertionActivity.commPage.getUuid()) { + if (activity.getUuid().equals(DemoInsertionActivity.commPage.getUuid())) { commPageInsertionActivity = activity; break; } diff --git a/plugins/org.eclipse.osee.ats.client.integration.tests/src/org/eclipse/osee/ats/client/integration/tests/ats/agile/AgileEndpointTest.java b/plugins/org.eclipse.osee.ats.client.integration.tests/src/org/eclipse/osee/ats/client/integration/tests/ats/agile/AgileEndpointTest.java index 55a774db8ff..f3842291546 100644 --- a/plugins/org.eclipse.osee.ats.client.integration.tests/src/org/eclipse/osee/ats/client/integration/tests/ats/agile/AgileEndpointTest.java +++ b/plugins/org.eclipse.osee.ats.client.integration.tests/src/org/eclipse/osee/ats/client/integration/tests/ats/agile/AgileEndpointTest.java @@ -64,7 +64,7 @@ public class AgileEndpointTest { JaxAgileTeam team = agile.getTeam(teamUuid); Assert.assertNotNull(team); Assert.assertEquals("My Agile Team", team.getName()); - Assert.assertEquals(teamUuid, team.getUuid()); + Assert.assertEquals(teamUuid, team.getUuid().longValue()); Assert.assertEquals("", team.getDescription()); Assert.assertEquals(true, team.isActive()); @@ -112,7 +112,7 @@ public class AgileEndpointTest { JaxAgileSprint sprint = sprints.iterator().next(); Assert.assertEquals("My Sprint", sprint.getName()); Assert.assertEquals(teamUuid, sprint.getTeamUuid()); - Assert.assertEquals(uuid.longValue(), sprint.getUuid()); + Assert.assertEquals(uuid.longValue(), sprint.getUuid().longValue()); // Test Delete agile.deleteSprint(teamUuid, sprint.getUuid()); @@ -142,7 +142,7 @@ public class AgileEndpointTest { JaxAgileFeatureGroup newGroup = groups.iterator().next(); Assert.assertEquals("Communications", newGroup.getName()); Assert.assertEquals(teamUuid, newGroup.getTeamUuid()); - Assert.assertEquals(uuid.longValue(), newGroup.getUuid()); + Assert.assertEquals(uuid.longValue(), newGroup.getUuid().longValue()); // Test Delete agile.deleteFeatureGroup(teamUuid, newGroup.getUuid()); @@ -172,7 +172,7 @@ public class AgileEndpointTest { Assert.assertEquals("My Backlog", newBacklog.getName()); Assert.assertEquals(teamUuid, newBacklog.getTeamUuid()); Assert.assertTrue(newBacklog.isActive()); - Assert.assertEquals(uuid.longValue(), newBacklog.getUuid()); + Assert.assertEquals(uuid.longValue(), newBacklog.getUuid().longValue()); } } diff --git a/plugins/org.eclipse.osee.ats.client.integration.tests/src/org/eclipse/osee/ats/client/integration/tests/ats/core/client/util/AtsUserTest.java b/plugins/org.eclipse.osee.ats.client.integration.tests/src/org/eclipse/osee/ats/client/integration/tests/ats/core/client/util/AtsUserTest.java index dd4c0da492e..f4c49c62a65 100644 --- a/plugins/org.eclipse.osee.ats.client.integration.tests/src/org/eclipse/osee/ats/client/integration/tests/ats/core/client/util/AtsUserTest.java +++ b/plugins/org.eclipse.osee.ats.client.integration.tests/src/org/eclipse/osee/ats/client/integration/tests/ats/core/client/util/AtsUserTest.java @@ -22,7 +22,6 @@ import org.eclipse.osee.framework.skynet.core.User; import org.eclipse.osee.framework.skynet.core.UserManager; import org.junit.Assert; import org.junit.Before; -import org.mockito.Mockito; /** * @author Donald G. Dunne @@ -54,16 +53,6 @@ public class AtsUserTest { } @org.junit.Test - public void testEquals() throws OseeCoreException { - Assert.assertEquals(atsUser, user); - - IAtsUser atsUser2 = Mockito.mock(IAtsUser.class); - Mockito.when(atsUser2.getName()).thenReturn(user.getName()); - Mockito.when(atsUser2.getUserId()).thenReturn(user.getUserId()); - Assert.assertEquals(atsUser, atsUser2); - } - - @org.junit.Test public void testRemove() throws OseeCoreException { Collection<IAtsUser> assignees = new HashSet<>(); assignees.add(AtsClientService.get().getUserServiceClient().getUserFromToken(DemoUsers.Alex_Kay)); diff --git a/plugins/org.eclipse.osee.ats.client.integration.tests/src/org/eclipse/osee/ats/client/integration/tests/ats/resource/UserResourceTest.java b/plugins/org.eclipse.osee.ats.client.integration.tests/src/org/eclipse/osee/ats/client/integration/tests/ats/resource/UserResourceTest.java index e4c5751f92f..0e6ca42e8d3 100644 --- a/plugins/org.eclipse.osee.ats.client.integration.tests/src/org/eclipse/osee/ats/client/integration/tests/ats/resource/UserResourceTest.java +++ b/plugins/org.eclipse.osee.ats.client.integration.tests/src/org/eclipse/osee/ats/client/integration/tests/ats/resource/UserResourceTest.java @@ -17,7 +17,7 @@ import org.junit.Test; /** * Test unit for {@link UserResource} - * + * * @author Donald G. Dunne */ public class UserResourceTest extends AbstractRestTest { @@ -25,7 +25,7 @@ public class UserResourceTest extends AbstractRestTest { @Test public void testGet() throws Exception { JsonArray users = getAndCheckArray("/ats/user"); - Assert.assertEquals(23, users.size()); + Assert.assertTrue(users.size() >= 9); JsonObject obj = getObjectNamed("Joe Smith", users); Assert.assertEquals("3333", obj.get("uuid").getAsString()); } diff --git a/plugins/org.eclipse.osee.ats.client.integration.tests/src/org/eclipse/osee/ats/client/integration/tests/ats/workflow/AtsTaskEndpointImplTest.java b/plugins/org.eclipse.osee.ats.client.integration.tests/src/org/eclipse/osee/ats/client/integration/tests/ats/workflow/AtsTaskEndpointImplTest.java index da4635d0da3..09865ed8a40 100644 --- a/plugins/org.eclipse.osee.ats.client.integration.tests/src/org/eclipse/osee/ats/client/integration/tests/ats/workflow/AtsTaskEndpointImplTest.java +++ b/plugins/org.eclipse.osee.ats.client.integration.tests/src/org/eclipse/osee/ats/client/integration/tests/ats/workflow/AtsTaskEndpointImplTest.java @@ -161,7 +161,7 @@ public class AtsTaskEndpointImplTest { JaxAtsTask task1R = taskEp.get(taskUuid1).readEntity(JaxAtsTask.class); Assert.assertNotNull(task1R); Assert.assertEquals("Task 1", task1R.getName()); - Assert.assertEquals(taskUuid1, task1R.getUuid()); + Assert.assertEquals(taskUuid1, task1R.getUuid().longValue()); Assert.assertEquals(createdByUserId, task1R.getCreatedByUserId()); Assert.assertEquals("description", task1R.getDescription()); Assert.assertEquals(true, task1R.isActive()); @@ -187,7 +187,7 @@ public class AtsTaskEndpointImplTest { JaxAtsTask task2R = taskEp.get(taskUuid2).readEntity(JaxAtsTask.class); Assert.assertNotNull(task2R); Assert.assertEquals("Task 2", task2R.getName()); - Assert.assertEquals(taskUuid2, task2R.getUuid()); + Assert.assertEquals(taskUuid2, task2R.getUuid().longValue()); Assert.assertEquals(createdByUserId, task2R.getCreatedByUserId()); Assert.assertEquals("description", task2R.getDescription()); Assert.assertEquals(true, task2R.isActive()); @@ -206,7 +206,7 @@ public class AtsTaskEndpointImplTest { JaxAtsTask task3R = taskEp.get(taskUuid3).readEntity(JaxAtsTask.class); Assert.assertNotNull(task3R); Assert.assertEquals("Task 3", task3R.getName()); - Assert.assertEquals(taskUuid3, task3R.getUuid()); + Assert.assertEquals(taskUuid3, task3R.getUuid().longValue()); Assert.assertEquals(createdByUserId, task2R.getCreatedByUserId()); Assert.assertEquals("", task3R.getDescription()); Assert.assertEquals(true, task3R.isActive()); diff --git a/plugins/org.eclipse.osee.ats.core.client/OSGI-INF/ats.client.service.xml b/plugins/org.eclipse.osee.ats.core.client/OSGI-INF/ats.client.service.xml index 878614305c1..2f4e8aa7390 100644 --- a/plugins/org.eclipse.osee.ats.core.client/OSGI-INF/ats.client.service.xml +++ b/plugins/org.eclipse.osee.ats.core.client/OSGI-INF/ats.client.service.xml @@ -9,4 +9,5 @@ <reference bind="setJdbcService" cardinality="1..1" interface="org.eclipse.osee.jdbc.JdbcService" name="JdbcService" policy="static" target="(osgi.binding=skynet.jdbc.service)"/> <reference bind="setLogger" cardinality="1..1" interface="org.eclipse.osee.logger.Log" name="Log" policy="static"/> <reference bind="addSearchDataProvider" cardinality="0..n" interface="org.eclipse.osee.ats.api.query.IAtsSearchDataProvider" name="IAtsSearchDataProvider" policy="dynamic" unbind="removeSearchDataProvider"/> + <reference bind="setConfigurationsService" cardinality="1..1" interface="org.eclipse.osee.ats.api.config.IAtsConfigurationProvider" name="IAtsConfigurationProvider" policy="static"/> </scr:component> diff --git a/plugins/org.eclipse.osee.ats.core.client/OSGI-INF/ats.configurations.service.xml b/plugins/org.eclipse.osee.ats.core.client/OSGI-INF/ats.configurations.service.xml new file mode 100644 index 00000000000..9c7778ae8a3 --- /dev/null +++ b/plugins/org.eclipse.osee.ats.core.client/OSGI-INF/ats.configurations.service.xml @@ -0,0 +1,7 @@ +<?xml version="1.0" encoding="UTF-8"?> +<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" immediate="true"> + <implementation class="org.eclipse.osee.ats.core.client.internal.AtsConfigurationsService"/> + <service> + <provide interface="org.eclipse.osee.ats.api.config.IAtsConfigurationProvider"/> + </service> +</scr:component> diff --git a/plugins/org.eclipse.osee.ats.core.client/OSGI-INF/ats.user.service.xml b/plugins/org.eclipse.osee.ats.core.client/OSGI-INF/ats.user.service.xml index b897d9c381e..749053969f2 100644 --- a/plugins/org.eclipse.osee.ats.core.client/OSGI-INF/ats.user.service.xml +++ b/plugins/org.eclipse.osee.ats.core.client/OSGI-INF/ats.user.service.xml @@ -1,8 +1,9 @@ <?xml version="1.0" encoding="UTF-8"?> <scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0"> - <implementation class="org.eclipse.osee.ats.core.client.internal.user.AtsUserServiceImpl"/> + <implementation class="org.eclipse.osee.ats.core.client.internal.user.AtsUserServiceClientImpl"/> <service> <provide interface="org.eclipse.osee.ats.api.user.IAtsUserService"/> <provide interface="org.eclipse.osee.ats.core.client.IAtsUserServiceClient"/> </service> + <reference bind="setConfigurationsService" cardinality="1..1" interface="org.eclipse.osee.ats.api.config.IAtsConfigurationProvider" name="IAtsConfigurationProvider" policy="static"/> </scr:component> diff --git a/plugins/org.eclipse.osee.ats.core.client/src/org/eclipse/osee/ats/core/client/IAtsClient.java b/plugins/org.eclipse.osee.ats.core.client/src/org/eclipse/osee/ats/core/client/IAtsClient.java index 8f6aefb2e4c..d0f86938326 100644 --- a/plugins/org.eclipse.osee.ats.core.client/src/org/eclipse/osee/ats/core/client/IAtsClient.java +++ b/plugins/org.eclipse.osee.ats.core.client/src/org/eclipse/osee/ats/core/client/IAtsClient.java @@ -72,11 +72,11 @@ public interface IAtsClient extends IAtsServices, IAtsNotifier, IAttributeResolv void invalidateCache(); - void reloadWorkDefinitionCache() throws OseeCoreException; + void reloadWorkDefinitionCache(boolean pend) throws OseeCoreException; void invalidateWorkDefinitionCache(); - void reloadAllCaches() throws OseeCoreException; + void reloadAllCaches(boolean pend) throws OseeCoreException; void invalidateAllCaches(); @@ -125,6 +125,8 @@ public interface IAtsClient extends IAtsServices, IAtsNotifier, IAttributeResolv IAtsEventService getEventService(); - void reloadConfigCache(); + void reloadConfigCache(boolean pend); + + void reloadUserCache(boolean pend); } diff --git a/plugins/org.eclipse.osee.ats.core.client/src/org/eclipse/osee/ats/core/client/IAtsUserServiceClient.java b/plugins/org.eclipse.osee.ats.core.client/src/org/eclipse/osee/ats/core/client/IAtsUserServiceClient.java index 20a2dad245a..770981e2d89 100644 --- a/plugins/org.eclipse.osee.ats.core.client/src/org/eclipse/osee/ats/core/client/IAtsUserServiceClient.java +++ b/plugins/org.eclipse.osee.ats.core.client/src/org/eclipse/osee/ats/core/client/IAtsUserServiceClient.java @@ -12,6 +12,7 @@ package org.eclipse.osee.ats.core.client; import java.util.Collection; import java.util.List; +import org.eclipse.osee.ats.api.IAtsWorkItem; import org.eclipse.osee.ats.api.user.IAtsUser; import org.eclipse.osee.framework.core.data.IUserToken; import org.eclipse.osee.framework.core.enums.Active; @@ -42,4 +43,8 @@ public interface IAtsUserServiceClient { List<User> getOseeUsersSorted(Active active); + List<IAtsUser> getSubscribed(IAtsWorkItem workItem) throws OseeCoreException; + + IAtsUser getUserById(long accountId); + }
\ No newline at end of file diff --git a/plugins/org.eclipse.osee.ats.core.client/src/org/eclipse/osee/ats/core/client/config/AtsBulkLoad.java b/plugins/org.eclipse.osee.ats.core.client/src/org/eclipse/osee/ats/core/client/config/AtsBulkLoad.java index d22b34b9d0b..90bdfa0abe2 100644 --- a/plugins/org.eclipse.osee.ats.core.client/src/org/eclipse/osee/ats/core/client/config/AtsBulkLoad.java +++ b/plugins/org.eclipse.osee.ats.core.client/src/org/eclipse/osee/ats/core/client/config/AtsBulkLoad.java @@ -44,7 +44,7 @@ public class AtsBulkLoad { IOperation op = new AbstractOperation("Re-load ATS Config", Activator.PLUGIN_ID) { @Override protected void doWork(IProgressMonitor monitor) throws Exception { - AtsClientService.get().reloadAllCaches(); + AtsClientService.get().reloadAllCaches(false); } }; ops.add(op); @@ -56,7 +56,7 @@ public class AtsBulkLoad { public static void reloadConfig(boolean pend) throws OseeCoreException { if (pend) { - AtsClientService.get().reloadAllCaches(); + AtsClientService.get().reloadAllCaches(pend); } else { AtsClientService.get().invalidateAllCaches(); } 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 148694ecfd3..172a223a3e1 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 @@ -27,6 +27,7 @@ import org.eclipse.osee.ats.api.ai.IAtsActionableItemService; import org.eclipse.osee.ats.api.column.IAtsColumnService; import org.eclipse.osee.ats.api.config.AtsConfigurations; import org.eclipse.osee.ats.api.config.IAtsCache; +import org.eclipse.osee.ats.api.config.IAtsConfigurationProvider; import org.eclipse.osee.ats.api.data.AtsArtifactToken; import org.eclipse.osee.ats.api.data.AtsAttributeTypes; import org.eclipse.osee.ats.api.data.AtsRelationTypes; @@ -72,14 +73,13 @@ import org.eclipse.osee.ats.core.client.artifact.SprintArtifact; import org.eclipse.osee.ats.core.client.branch.internal.AtsBranchServiceImpl; import org.eclipse.osee.ats.core.client.config.IAtsClientVersionService; import org.eclipse.osee.ats.core.client.internal.config.ActionableItemFactory; -import org.eclipse.osee.ats.core.client.internal.config.LoadAtsConfigCacheCallable; import org.eclipse.osee.ats.core.client.internal.config.TeamDefinitionFactory; import org.eclipse.osee.ats.core.client.internal.config.VersionFactory; import org.eclipse.osee.ats.core.client.internal.ev.AtsEarnedValueImpl; import org.eclipse.osee.ats.core.client.internal.query.AtsQueryServiceImpl; import org.eclipse.osee.ats.core.client.internal.review.AtsReviewServiceImpl; import org.eclipse.osee.ats.core.client.internal.store.AtsVersionServiceImpl; -import org.eclipse.osee.ats.core.client.internal.user.AtsUserServiceImpl; +import org.eclipse.osee.ats.core.client.internal.user.AtsUserServiceClientImpl; import org.eclipse.osee.ats.core.client.internal.workdef.ArtifactResolverImpl; import org.eclipse.osee.ats.core.client.internal.workflow.AtsAttributeResolverServiceImpl; import org.eclipse.osee.ats.core.client.internal.workflow.AtsRelationResolverServiceImpl; @@ -172,6 +172,7 @@ public class AtsClientImpl extends AtsCoreServiceImpl implements IAtsClient { List<IAtsSearchDataProvider> searchDataProviders; private IAtsEventService eventService; private IAtsImplementerService implementerService; + private IAtsConfigurationProvider configProvider; public AtsClientImpl() { searchDataProviders = new ArrayList<>(); @@ -189,6 +190,10 @@ public class AtsClientImpl extends AtsCoreServiceImpl implements IAtsClient { this.logger = logger; } + public void setConfigurationsService(IAtsConfigurationProvider configProvider) { + this.configProvider = configProvider; + } + public void addSearchDataProvider(IAtsSearchDataProvider provider) { searchDataProviders.add(provider); } @@ -200,7 +205,7 @@ public class AtsClientImpl extends AtsCoreServiceImpl implements IAtsClient { public void start() throws OseeCoreException { Conditions.checkNotNull(workDefService, "IAtsWorkDefinitionService"); - userService = new AtsUserServiceImpl(); + userService = new AtsUserServiceClientImpl(this); userServiceClient = (IAtsUserServiceClient) userService; atsCache = new AtsCache(this); @@ -292,32 +297,68 @@ public class AtsClientImpl extends AtsCoreServiceImpl implements IAtsClient { } @Override - public void reloadWorkDefinitionCache() throws OseeCoreException { - workDefCache.invalidate(); - workDefCache.getAllWorkDefinitions(); + public void reloadWorkDefinitionCache(boolean pend) throws OseeCoreException { + Runnable reload = new Runnable() { + + @Override + public void run() { + workDefCache.invalidate(); + workDefCache.getAllWorkDefinitions(); + } + }; + if (pend) { + reload.run(); + } else { + new Thread(reload).start(); + } } @Override - public void reloadAllCaches() throws OseeCoreException { - Job job = new Job("Reload ATS Caches") { + public void reloadUserCache(boolean pend) throws OseeCoreException { + Runnable reload = new Runnable() { @Override - protected IStatus run(IProgressMonitor monitor) { - reloadConfigCache(); - reloadWorkDefinitionCache(); - getUserService().clearCache(); - return Status.OK_STATUS; + public void run() { + configProvider.clearConfigurationsCaches(); + getUserService().reloadCache(); } }; - Jobs.startJob(job); + if (pend) { + reload.run(); + } else { + new Thread(reload).start(); + } } @Override - public void reloadConfigCache() { - try { - new LoadAtsConfigCacheCallable(atsCache).run(); - } catch (Exception ex) { - OseeLog.log(Activator.class, Level.SEVERE, ex); + public void reloadAllCaches(boolean pend) throws OseeCoreException { + reloadUserCache(pend); + reloadWorkDefinitionCache(pend); + reloadConfigCache(pend); + } + + @Override + public void reloadConfigCache(boolean pend) { + Runnable reload = new Runnable() { + + @Override + public void run() { + try { + List<Artifact> artifacts = ArtifactQuery.getArtifactListFromIds( + configProvider.getConfigurations().getAtsActiveConfigIds(), AtsUtilCore.getAtsBranch()); + + for (Artifact artifact : artifacts) { + atsCache.cacheArtifact(artifact); + } + } catch (Exception ex) { + OseeLog.log(Activator.class, Level.SEVERE, ex); + } + } + }; + if (pend) { + reload.run(); + } else { + new Thread(reload).start(); } } @@ -738,8 +779,13 @@ public class AtsClientImpl extends AtsCoreServiceImpl implements IAtsClient { } @Override - protected AtsConfigurations loadConfigurations() { - return AtsClientService.getConfigEndpoint().get(); + public AtsConfigurations getConfigurations() { + return configProvider.getConfigurations(); + } + + @Override + public void clearConfigurationsCaches() { + configProvider.clearConfigurationsCaches(); } } diff --git a/plugins/org.eclipse.osee.ats.core.client/src/org/eclipse/osee/ats/core/client/internal/AtsConfigurationsService.java b/plugins/org.eclipse.osee.ats.core.client/src/org/eclipse/osee/ats/core/client/internal/AtsConfigurationsService.java new file mode 100644 index 00000000000..2a2e154dbb8 --- /dev/null +++ b/plugins/org.eclipse.osee.ats.core.client/src/org/eclipse/osee/ats/core/client/internal/AtsConfigurationsService.java @@ -0,0 +1,85 @@ +/******************************************************************************* + * Copyright (c) 2016 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.client.internal; + +import com.google.common.base.Supplier; +import com.google.common.base.Suppliers; +import java.util.concurrent.TimeUnit; +import org.eclipse.osee.ats.api.config.AtsConfigurations; +import org.eclipse.osee.ats.api.config.IAtsConfigurationProvider; +import org.eclipse.osee.ats.api.user.IAtsUser; +import org.eclipse.osee.ats.api.user.IUserArtLoader; +import org.eclipse.osee.ats.api.user.JaxAtsUser; +import org.eclipse.osee.ats.core.util.AtsUtilCore; +import org.eclipse.osee.framework.core.data.ArtifactId; +import org.eclipse.osee.framework.core.exception.ArtifactDoesNotExist; +import org.eclipse.osee.framework.skynet.core.UserManager; +import org.eclipse.osee.framework.skynet.core.artifact.search.ArtifactQuery; + +/** + * @author Donald G. Dunne + */ +public class AtsConfigurationsService implements IAtsConfigurationProvider { + + @Override + public AtsConfigurations getConfigurations() { + return configurationsCache.get(); + } + + @Override + public void clearConfigurationsCaches() { + configurationsCache = Suppliers.memoizeWithExpiration(getConfigurationsSupplier(), 5, TimeUnit.MINUTES); + } + + private Supplier<AtsConfigurations> configurationsCache = + Suppliers.memoizeWithExpiration(getConfigurationsSupplier(), 5, TimeUnit.MINUTES); + + private Supplier<AtsConfigurations> getConfigurationsSupplier() { + return new Supplier<AtsConfigurations>() { + @Override + public AtsConfigurations get() { + return loadConfigurations(); + } + }; + } + + private AtsConfigurations loadConfigurations() { + AtsConfigurations configs = AtsClientService.getConfigEndpoint().get(); + for (IAtsUser user : configs.getUsers()) { + JaxAtsUser jUser = (JaxAtsUser) user; + jUser.setUserArtLoader(userLoader); + } + return configs; + } + + /** + * Lazy Loader for user artifact + */ + private final UserArtLoader userLoader = new UserArtLoader(); + private class UserArtLoader implements IUserArtLoader { + + @Override + public ArtifactId loadUser(IAtsUser user) { + ArtifactId userArt = null; + try { + userArt = UserManager.getUserByArtId(user.getUuid().intValue()); + if (userArt == null) { + userArt = ArtifactQuery.getArtifactFromId(user.getUuid(), AtsUtilCore.getAtsBranch()); + } + } catch (ArtifactDoesNotExist ex) { + // do nothing + } + user.setStoreObject(userArt); + return userArt; + } + } + +} diff --git a/plugins/org.eclipse.osee.ats.core.client/src/org/eclipse/osee/ats/core/client/internal/ConfigItemFactory.java b/plugins/org.eclipse.osee.ats.core.client/src/org/eclipse/osee/ats/core/client/internal/ConfigItemFactory.java index be8f5d03274..5598c99ccd0 100644 --- a/plugins/org.eclipse.osee.ats.core.client/src/org/eclipse/osee/ats/core/client/internal/ConfigItemFactory.java +++ b/plugins/org.eclipse.osee.ats.core.client/src/org/eclipse/osee/ats/core/client/internal/ConfigItemFactory.java @@ -37,6 +37,7 @@ import org.eclipse.osee.ats.core.insertion.Insertion; import org.eclipse.osee.ats.core.insertion.InsertionActivity; import org.eclipse.osee.ats.core.model.WorkPackage; import org.eclipse.osee.framework.core.data.ArtifactId; +import org.eclipse.osee.framework.jdk.core.type.OseeArgumentException; import org.eclipse.osee.framework.jdk.core.type.OseeCoreException; import org.eclipse.osee.framework.skynet.core.artifact.Artifact; import org.eclipse.osee.logger.Log; @@ -81,6 +82,9 @@ public class ConfigItemFactory extends AbstractConfigItemFactory { configObject = getCountry(artifact); } else if (artifact.isOfType(AtsArtifactTypes.WorkPackage)) { configObject = getWorkPackage(artifact); + } else { + throw new OseeArgumentException("Unhandled artifact type %s for %s", ((Artifact) art).getArtifactTypeName(), + art.toStringWithId()); } } return configObject; diff --git a/plugins/org.eclipse.osee.ats.core.client/src/org/eclipse/osee/ats/core/client/internal/config/LoadAtsConfigCacheCallable.java b/plugins/org.eclipse.osee.ats.core.client/src/org/eclipse/osee/ats/core/client/internal/config/LoadAtsConfigCacheCallable.java deleted file mode 100644 index 47aad2af267..00000000000 --- a/plugins/org.eclipse.osee.ats.core.client/src/org/eclipse/osee/ats/core/client/internal/config/LoadAtsConfigCacheCallable.java +++ /dev/null @@ -1,51 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2013 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.client.internal.config; - -import java.util.Arrays; -import java.util.List; -import org.eclipse.osee.ats.api.config.IAtsCache; -import org.eclipse.osee.ats.api.data.AtsArtifactTypes; -import org.eclipse.osee.ats.api.data.AtsAttributeTypes; -import org.eclipse.osee.ats.core.util.AtsUtilCore; -import org.eclipse.osee.framework.core.data.IArtifactType; -import org.eclipse.osee.framework.skynet.core.artifact.Artifact; -import org.eclipse.osee.framework.skynet.core.artifact.search.ArtifactQuery; -import org.eclipse.osee.framework.skynet.core.artifact.search.QueryBuilderArtifact; - -/** - * @author Donald G. Dunne - */ -public class LoadAtsConfigCacheCallable { - - private final IAtsCache cache; - - public LoadAtsConfigCacheCallable(IAtsCache cache) { - this.cache = cache; - } - - public void run() throws Exception { - - List<IArtifactType> typesToLoad = getTypesToLoad(); - QueryBuilderArtifact query = ArtifactQuery.createQueryBuilder(AtsUtilCore.getAtsBranch()); - query.andTypeEquals(typesToLoad).and(AtsAttributeTypes.Active, "true"); - List<Artifact> artifactListFromType = query.getResults().getList(); - - for (Artifact artifact : artifactListFromType) { - cache.cacheArtifact(artifact); - } - } - - private List<IArtifactType> getTypesToLoad() { - return Arrays.asList(AtsArtifactTypes.TeamDefinition, AtsArtifactTypes.ActionableItem, AtsArtifactTypes.Version); - } - -}
\ No newline at end of file diff --git a/plugins/org.eclipse.osee.ats.core.client/src/org/eclipse/osee/ats/core/client/internal/user/AtsUser.java b/plugins/org.eclipse.osee.ats.core.client/src/org/eclipse/osee/ats/core/client/internal/user/AtsUser.java deleted file mode 100644 index 3767c265dd9..00000000000 --- a/plugins/org.eclipse.osee.ats.core.client/src/org/eclipse/osee/ats/core/client/internal/user/AtsUser.java +++ /dev/null @@ -1,136 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2013 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.client.internal.user; - -import org.eclipse.osee.ats.api.user.IAtsUser; -import org.eclipse.osee.framework.core.data.ArtifactId; -import org.eclipse.osee.framework.jdk.core.type.OseeCoreException; -import org.eclipse.osee.framework.jdk.core.type.UuidIdentity; -import org.eclipse.osee.framework.skynet.core.User; - -/** - * @author Donald G. Dunne - */ -public class AtsUser implements IAtsUser { - - private User user; - - public AtsUser(User user) { - this.user = user; - } - - @Override - public String getName() { - return user.getName(); - } - - @Override - public int hashCode() { - final int prime = 31; - int result = 0; - int userIdHashCode = 0; - try { - userIdHashCode = getUserId() == null ? 0 : getUserId().hashCode(); - } catch (OseeCoreException ex) { - // Do nothing; - } - result = prime * result + userIdHashCode; - return result; - } - - @Override - public boolean equals(Object obj) { - if (this == obj) { - return true; - } - if (obj == null) { - return false; - } - try { - String objUserId = null; - if (obj instanceof IAtsUser) { - objUserId = ((IAtsUser) obj).getUserId(); - } else if (obj instanceof User) { - objUserId = ((User) obj).getUserId(); - } else { - return false; - } - String thisUserId = getUserId(); - if (thisUserId == null) { - if (objUserId != null) { - return false; - } - } else if (!thisUserId.equals(objUserId)) { - return false; - } - } catch (OseeCoreException ex) { - return false; - } - return true; - } - - @Override - public boolean matches(UuidIdentity... identities) { - for (UuidIdentity identity : identities) { - if (equals(identity)) { - return true; - } - } - return false; - } - - @Override - public String getUserId() throws OseeCoreException { - return user.getUserId(); - } - - @Override - public String getEmail() throws OseeCoreException { - return user.getEmail(); - } - - @Override - public boolean isActive() throws OseeCoreException { - return user.isActive(); - } - - @Override - public String toString() { - try { - return getName(); - } catch (Exception ex) { - return "Exception: " + ex.getLocalizedMessage(); - } - } - - @Override - public String toStringWithId() { - return String.format("[%s][%d]", getName(), getUuid()); - } - - @Override - public ArtifactId getStoreObject() { - return user; - } - - @Override - public void setStoreObject(ArtifactId artifact) { - if (artifact instanceof User) { - this.user = (User) artifact; - } - } - - @Override - public Long getUuid() { - return Long.valueOf(user.getArtId()); - } - -} diff --git a/plugins/org.eclipse.osee.ats.core.client/src/org/eclipse/osee/ats/core/client/internal/user/AtsUserServiceImpl.java b/plugins/org.eclipse.osee.ats.core.client/src/org/eclipse/osee/ats/core/client/internal/user/AtsUserServiceClientImpl.java index b6979cd2454..846d6acf998 100644 --- a/plugins/org.eclipse.osee.ats.core.client/src/org/eclipse/osee/ats/core/client/internal/user/AtsUserServiceImpl.java +++ b/plugins/org.eclipse.osee.ats.core.client/src/org/eclipse/osee/ats/core/client/internal/user/AtsUserServiceClientImpl.java @@ -16,17 +16,17 @@ import java.util.Collections; import java.util.LinkedList; import java.util.List; import org.eclipse.osee.ats.api.IAtsWorkItem; +import org.eclipse.osee.ats.api.config.IAtsConfigurationProvider; import org.eclipse.osee.ats.api.data.AtsRelationTypes; import org.eclipse.osee.ats.api.user.IAtsUser; +import org.eclipse.osee.ats.api.user.JaxAtsUser; import org.eclipse.osee.ats.core.client.IAtsUserServiceClient; import org.eclipse.osee.ats.core.client.util.AtsGroup; import org.eclipse.osee.ats.core.users.AbstractAtsUserService; import org.eclipse.osee.ats.core.util.AtsUtilCore; -import org.eclipse.osee.framework.core.client.ClientSessionManager; import org.eclipse.osee.framework.core.enums.Active; import org.eclipse.osee.framework.core.enums.CoreArtifactTypes; import org.eclipse.osee.framework.core.enums.CoreAttributeTypes; -import org.eclipse.osee.framework.core.exception.ArtifactDoesNotExist; import org.eclipse.osee.framework.jdk.core.type.OseeCoreException; import org.eclipse.osee.framework.skynet.core.User; import org.eclipse.osee.framework.skynet.core.UserManager; @@ -38,82 +38,27 @@ import org.eclipse.osee.framework.skynet.core.artifact.search.ArtifactQuery; * * @author Donald G Dunne */ -public class AtsUserServiceImpl extends AbstractAtsUserService implements IAtsUserServiceClient { +public class AtsUserServiceClientImpl extends AbstractAtsUserService implements IAtsUserServiceClient { - /************************************************ - ** IAtsUserService implementations - ************************************************/ + private IAtsConfigurationProvider configurationProvider; - @Override - public String getCurrentUserId() throws OseeCoreException { - if (currentUserId == null) { - currentUserId = ClientSessionManager.getCurrentUserToken().getUserId(); - } - return currentUserId; - } - - @Override - protected IAtsUser loadUserByUserNameFromDb(String name) { - IAtsUser atsUser = null; - User user = null; - try { - user = (User) ArtifactQuery.getArtifactFromTypeAndAttribute(CoreArtifactTypes.User, CoreAttributeTypes.Name, - name, AtsUtilCore.getAtsBranch()); - } catch (ArtifactDoesNotExist ex) { - // do nothing - } - if (user != null) { - atsUser = new AtsUser(user); - } - return atsUser; - } - - @Override - protected IAtsUser loadUserByUserIdFromDb(String userId) { - IAtsUser atsUser = null; - User user = (User) ArtifactQuery.getArtifactFromTypeAndAttribute(CoreArtifactTypes.User, - CoreAttributeTypes.UserId, userId, AtsUtilCore.getAtsBranch()); - - if (user != null) { - atsUser = getUserFromOseeUser(user); - } - return atsUser; + public AtsUserServiceClientImpl() { + // For OSGI Instantiation } - @Override - public boolean isAtsAdmin(IAtsUser user) { - ensureLoaded(); - Boolean admin = userIdToAdmin.get(user.getUserId()); - if (admin == null) { - admin = AtsGroup.AtsAdmin.isMember(user); - userIdToAdmin.put(user.getUserId(), admin); - } - return admin; + public AtsUserServiceClientImpl(IAtsConfigurationProvider configurationProvider) { + this.configurationProvider = configurationProvider; } - @Override - public List<IAtsUser> getUsers(Active active) { - ensureLoaded(); - List<IAtsUser> users = new ArrayList<>(); - for (Artifact user : ArtifactQuery.getArtifactListFromType(CoreArtifactTypes.User, AtsUtilCore.getAtsBranch())) { - Boolean activeFlag = user.getSoleAttributeValue(CoreAttributeTypes.Active, true); - if (active == Active.Both || active == Active.Active && activeFlag || active == Active.InActive && !activeFlag) { - users.add(new AtsUser((User) user)); - } - } - return users; + public void setConfigurationsService(IAtsConfigurationProvider configurationProvider) { + this.configurationProvider = configurationProvider; } - /************************************************ - ** IAtsUserServiceClient implementations - ************************************************/ - @Override public IAtsUser getUserFromOseeUser(User user) throws OseeCoreException { - ensureLoaded(); IAtsUser atsUser = userIdToAtsUser.get(user.getUserId()); if (atsUser == null) { - atsUser = new AtsUser(user); + atsUser = createFromArtifact(user); userIdToAtsUser.put(user.getUserId(), atsUser); } return atsUser; @@ -121,7 +66,6 @@ public class AtsUserServiceImpl extends AbstractAtsUserService implements IAtsUs @Override public User getOseeUser(IAtsUser atsUser) throws OseeCoreException { - ensureLoaded(); User oseeUser = null; if (atsUser.getStoreObject() != null) { oseeUser = (User) atsUser.getStoreObject(); @@ -133,14 +77,12 @@ public class AtsUserServiceImpl extends AbstractAtsUserService implements IAtsUs @Override public User getCurrentOseeUser() throws OseeCoreException { - ensureLoaded(); IAtsUser user = getCurrentUser(); return getOseeUser(user); } @Override public Collection<? extends User> toOseeUsers(Collection<? extends IAtsUser> users) throws OseeCoreException { - ensureLoaded(); List<User> results = new LinkedList<>(); for (IAtsUser user : users) { results.add(getOseeUser(user)); @@ -150,7 +92,6 @@ public class AtsUserServiceImpl extends AbstractAtsUserService implements IAtsUs @Override public Collection<IAtsUser> getAtsUsers(Collection<? extends Artifact> artifacts) throws OseeCoreException { - ensureLoaded(); List<IAtsUser> users = new LinkedList<>(); for (Artifact artifact : artifacts) { if (artifact instanceof User) { @@ -164,7 +105,6 @@ public class AtsUserServiceImpl extends AbstractAtsUserService implements IAtsUs @Override public Collection<User> getOseeUsers(Collection<? extends IAtsUser> users) throws OseeCoreException { - ensureLoaded(); List<User> results = new LinkedList<>(); for (IAtsUser user : users) { results.add(getOseeUser(user)); @@ -174,25 +114,10 @@ public class AtsUserServiceImpl extends AbstractAtsUserService implements IAtsUs @Override public User getOseeUserById(String userId) throws OseeCoreException { - ensureLoaded(); return getOseeUser(getUserById(userId)); } @Override - protected synchronized void ensureLoaded() { - if (!loaded) { - for (Artifact art : ArtifactQuery.getArtifactListFromType(CoreArtifactTypes.User, - AtsUtilCore.getAtsBranch())) { - User user = (User) art; - AtsUser atsUser = new AtsUser(user); - userIdToAtsUser.put(user.getUserId(), atsUser); - nameToAtsUser.put(user.getName(), atsUser); - } - loaded = true; - } - } - - @Override public List<User> getOseeUsersSorted(Active active) { List<IAtsUser> activeUsers = getUsers(active); List<User> oseeUsers = new ArrayList<>(); @@ -216,4 +141,49 @@ public class AtsUserServiceImpl extends AbstractAtsUserService implements IAtsUs return getUserFromOseeUser(UserManager.getUserByArtId((int) accountId)); } + @Override + public String getCurrentUserId() { + return UserManager.getUser().getUserId(); + } + + @Override + public boolean isAtsAdmin(IAtsUser user) { + Boolean admin = userIdToAdmin.get(user.getUserId()); + if (admin == null) { + admin = AtsGroup.AtsAdmin.isMember(user); + userIdToAdmin.put(user.getUserId(), admin); + } + return admin; + } + + @Override + public List<? extends IAtsUser> getUsers() { + return configurationProvider.getConfigurations().getUsers(); + } + + @Override + protected IAtsUser loadUserFromDbByUserId(String userId) { + Artifact userArt = ArtifactQuery.getArtifactFromTypeAndAttribute(CoreArtifactTypes.User, + CoreAttributeTypes.UserId, userId, AtsUtilCore.getAtsBranch()); + return createFromArtifact(userArt); + } + + private JaxAtsUser createFromArtifact(Artifact userArt) { + JaxAtsUser atsUser = new JaxAtsUser(); + atsUser.setName(userArt.getName()); + atsUser.setStoreObject(userArt); + atsUser.setUserId(userArt.getSoleAttributeValue(CoreAttributeTypes.UserId, "")); + atsUser.setEmail(userArt.getSoleAttributeValue(CoreAttributeTypes.Email, "")); + atsUser.setActive(userArt.getSoleAttributeValue(CoreAttributeTypes.Active, true)); + atsUser.setUuid(userArt.getUuid()); + return atsUser; + } + + @Override + protected IAtsUser loadUserFromDbByUserName(String name) { + Artifact userArt = ArtifactQuery.getArtifactFromTypeAndAttribute(CoreArtifactTypes.User, CoreAttributeTypes.Name, + name, AtsUtilCore.getAtsBranch()); + return createFromArtifact(userArt); + } + } diff --git a/plugins/org.eclipse.osee.ats.core.client/src/org/eclipse/osee/ats/core/client/task/AtsTaskService.java b/plugins/org.eclipse.osee.ats.core.client/src/org/eclipse/osee/ats/core/client/task/AtsTaskService.java index ed9e24c0feb..4cb48f33f92 100644 --- a/plugins/org.eclipse.osee.ats.core.client/src/org/eclipse/osee/ats/core/client/task/AtsTaskService.java +++ b/plugins/org.eclipse.osee.ats.core.client/src/org/eclipse/osee/ats/core/client/task/AtsTaskService.java @@ -120,7 +120,7 @@ public class AtsTaskService extends AbstractAtsTaskService { private RelationLink getRelation(Artifact teamWf, JaxAtsTask task) { for (RelationLink relation : teamWf.getRelationsAll(DeletionFlag.EXCLUDE_DELETED)) { - if (relation.getBArtifactId() == (int) task.getUuid()) { + if (relation.getBArtifactId() == task.getUuid().intValue()) { return relation; } } diff --git a/plugins/org.eclipse.osee.ats.core/src/org/eclipse/osee/ats/core/config/TeamDefinition.java b/plugins/org.eclipse.osee.ats.core/src/org/eclipse/osee/ats/core/config/TeamDefinition.java index d830f912a2c..c6b447baa29 100644 --- a/plugins/org.eclipse.osee.ats.core/src/org/eclipse/osee/ats/core/config/TeamDefinition.java +++ b/plugins/org.eclipse.osee.ats.core/src/org/eclipse/osee/ats/core/config/TeamDefinition.java @@ -100,17 +100,20 @@ public class TeamDefinition extends AtsConfigObject implements IAtsTeamDefinitio for (IAtsActionableItem aia : actionableItems) { if (this.equals(aia.getTeamDefinitionInherited())) { // If leads are specified for this aia, add them - if (aia.getLeads().size() > 0) { - leads.addAll(aia.getLeads()); + Collection<IAtsUser> leads2 = aia.getLeads(); + if (leads2.size() > 0) { + leads.addAll(leads2); } else { if (aia.getTeamDefinitionInherited() != null) { - leads.addAll(aia.getTeamDefinitionInherited().getLeads()); + Collection<IAtsUser> leads3 = aia.getTeamDefinitionInherited().getLeads(); + leads.addAll(leads3); } } } } if (leads.isEmpty()) { - leads.addAll(getLeads()); + Collection<IAtsUser> leads2 = getLeads(); + leads.addAll(leads2); } return leads; } diff --git a/plugins/org.eclipse.osee.ats.core/src/org/eclipse/osee/ats/core/query/AbstractAtsConfigQueryImpl.java b/plugins/org.eclipse.osee.ats.core/src/org/eclipse/osee/ats/core/query/AbstractAtsConfigQueryImpl.java index 381e99d3f73..34e101464c9 100644 --- a/plugins/org.eclipse.osee.ats.core/src/org/eclipse/osee/ats/core/query/AbstractAtsConfigQueryImpl.java +++ b/plugins/org.eclipse.osee.ats.core/src/org/eclipse/osee/ats/core/query/AbstractAtsConfigQueryImpl.java @@ -179,7 +179,8 @@ public abstract class AbstractAtsConfigQueryImpl implements IAtsConfigQuery { @Override public <T extends ArtifactId> ResultSet<T> getResultArtifacts() { List<T> items = new ArrayList<>(); - for (IAtsConfigObject configObject : getResults()) { + ResultSet<IAtsConfigObject> results = getResults(); + for (IAtsConfigObject configObject : results) { if (configObject == null) { OseeLog.log(AbstractAtsConfigQueryImpl.class, Level.SEVERE, "Null found in results"); } else { 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 54d5b48c2f5..90d94335905 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 @@ -10,12 +10,13 @@ *******************************************************************************/ package org.eclipse.osee.ats.core.users; +import java.util.ArrayList; import java.util.Collection; import java.util.Collections; -import java.util.HashMap; import java.util.LinkedList; import java.util.List; import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; import org.eclipse.osee.ats.api.user.IAtsUser; import org.eclipse.osee.ats.api.user.IAtsUserService; import org.eclipse.osee.ats.api.util.AtsUserNameComparator; @@ -29,27 +30,29 @@ import org.eclipse.osee.framework.jdk.core.util.Strings; */ public abstract class AbstractAtsUserService implements IAtsUserService { - protected final Map<String, IAtsUser> userIdToAtsUser = new HashMap<>(300); - protected final Map<String, Boolean> userIdToAdmin = new HashMap<>(300); - protected final Map<String, IAtsUser> nameToAtsUser = new HashMap<>(300); + protected final Map<String, IAtsUser> userIdToAtsUser = new ConcurrentHashMap<>(300); + protected final Map<String, Boolean> userIdToAdmin = new ConcurrentHashMap<>(300); + protected final Map<String, IAtsUser> nameToAtsUser = new ConcurrentHashMap<>(300); protected IAtsUser currentUser = null; - protected String currentUserId = null; - protected boolean loaded = false; - - protected abstract void ensureLoaded(); @Override public IAtsUser getCurrentUser() throws OseeCoreException { - ensureLoaded(); if (currentUser == null) { - currentUser = getUserById(getCurrentUserId()); + currentUser = userIdToAtsUser.get(getCurrentUserId()); + if (currentUser == null) { + for (IAtsUser user : getUsers(Active.Both)) { + if (user.getUserId().equals(getCurrentUserId())) { + currentUser = user; + break; + } + } + } } return currentUser; } @Override public Collection<IAtsUser> getUsersByUserIds(Collection<String> userIds) throws OseeCoreException { - ensureLoaded(); List<IAtsUser> users = new LinkedList<>(); for (String userId : userIds) { IAtsUser user = getUserById(userId); @@ -62,68 +65,98 @@ public abstract class AbstractAtsUserService implements IAtsUserService { @Override public IAtsUser getUserById(String userId) throws OseeCoreException { - ensureLoaded(); - IAtsUser atsUser = userIdToAtsUser.get(userId); - if (atsUser == null && Strings.isValid(userId)) { - atsUser = AtsCoreUsers.getAtsCoreUserByUserId(userId); - if (atsUser == null) { - atsUser = loadUserByUserIdFromDb(userId); + IAtsUser atsUser = null; + if (Strings.isValid(userId)) { + atsUser = userIdToAtsUser.get(userId); + if (atsUser == null && Strings.isValid(userId)) { + atsUser = AtsCoreUsers.getAtsCoreUserByUserId(userId); + if (atsUser == null) { + atsUser = loadUserFromDbByUserId(userId); + if (atsUser != null) { + userIdToAtsUser.put(userId, atsUser); + } + } } } return atsUser; } - protected abstract IAtsUser loadUserByUserIdFromDb(String userId); + protected abstract IAtsUser loadUserFromDbByUserId(String userId); @Override public IAtsUser getUserByName(String name) throws OseeCoreException { - ensureLoaded(); IAtsUser atsUser = nameToAtsUser.get(name); if (atsUser == null && Strings.isValid(name)) { - atsUser = loadUserByUserNameFromDb(name); + atsUser = loadUserFromDbByUserName(name); + if (atsUser != null) { + nameToAtsUser.put(name, atsUser); + } } return atsUser; } - protected abstract IAtsUser loadUserByUserNameFromDb(String name); + protected abstract IAtsUser loadUserFromDbByUserName(String name); @Override public boolean isUserIdValid(String userId) throws OseeCoreException { - ensureLoaded(); return getUserById(userId) != null; } @Override public boolean isUserNameValid(String name) throws OseeCoreException { - ensureLoaded(); return getUserByName(name) != null; } @Override public List<IAtsUser> getUsersSortedByName(Active active) { - ensureLoaded(); List<IAtsUser> users = getUsers(active); Collections.sort(users, new AtsUserNameComparator(false)); return users; } public IAtsUser getUserFromToken(IUserToken userToken) { - ensureLoaded(); return getUserById(userToken.getUserId()); } - @Override - public void releaseUser() { + public void releaseUser(IAtsUser newUser) { currentUser = null; - currentUserId = null; } @Override - public void clearCache() { + public abstract String getCurrentUserId(); + + @Override + public abstract boolean isAtsAdmin(IAtsUser user); + + @Override + public abstract List<? extends IAtsUser> getUsers(); + + @Override + public List<IAtsUser> getUsers(Active active) { + List<IAtsUser> users = new ArrayList<>(); + for (IAtsUser user : getUsers()) { + if (active == Active.Both || active == Active.Active && user.isActive() || active == Active.InActive && !user.isActive()) { + users.add(user); + } + } + return users; + } + + @Override + public void reloadCache() { userIdToAdmin.clear(); userIdToAtsUser.clear(); nameToAtsUser.clear(); - loaded = false; + currentUser = null; + for (IAtsUser user : getUsers()) { + userIdToAtsUser.put(user.getUserId(), user); + nameToAtsUser.put(user.getName(), user); + } + } + + @Override + public void releaseUser() { + currentUser = null; } } 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 index f6453052421..4e212e92747 100644 --- 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 @@ -10,13 +10,9 @@ *******************************************************************************/ package org.eclipse.osee.ats.core.util; -import com.google.common.base.Supplier; -import com.google.common.base.Suppliers; -import java.util.concurrent.TimeUnit; import org.eclipse.osee.ats.api.IAtsConfigObject; import org.eclipse.osee.ats.api.IAtsObject; import org.eclipse.osee.ats.api.IAtsServices; -import org.eclipse.osee.ats.api.config.AtsConfigurations; import org.eclipse.osee.ats.api.data.AtsAttributeTypes; import org.eclipse.osee.ats.api.workdef.IAtsWorkDefinitionAdmin; import org.eclipse.osee.ats.api.workdef.IAttributeResolver; @@ -59,28 +55,6 @@ public abstract class AtsCoreServiceImpl implements IAtsServices { } @Override - public AtsConfigurations getConfigurations() { - return configurationsCache.get(); - } - - private final Supplier<AtsConfigurations> configurationsCache = - Suppliers.memoizeWithExpiration(getConfigurationsSupplier(), 5, TimeUnit.MINUTES); - - private Supplier<AtsConfigurations> getConfigurationsSupplier() { - return new Supplier<AtsConfigurations>() { - @Override - public AtsConfigurations get() { - return loadConfigurations(); - } - }; - } - - /** - * Provided loader for configurations. Should be called infrequently only by AtsClientImpl or AtsServerImpl - */ - abstract protected AtsConfigurations loadConfigurations(); - - @Override public <T> T getConfigItem(IArtifactToken artifactToken) { return getConfigItem(artifactToken.getUuid()); } diff --git a/plugins/org.eclipse.osee.ats.rest.test/src/org/eclipse/osee/ats/rest/internal/notify/WorkItemNotificationProcessorTest.java b/plugins/org.eclipse.osee.ats.rest.test/src/org/eclipse/osee/ats/rest/internal/notify/WorkItemNotificationProcessorTest.java index d1933a77c7e..e06d5b6e774 100644 --- a/plugins/org.eclipse.osee.ats.rest.test/src/org/eclipse/osee/ats/rest/internal/notify/WorkItemNotificationProcessorTest.java +++ b/plugins/org.eclipse.osee.ats.rest.test/src/org/eclipse/osee/ats/rest/internal/notify/WorkItemNotificationProcessorTest.java @@ -19,6 +19,7 @@ import java.util.List; import java.util.Set; import org.eclipse.osee.ats.api.ai.IAtsActionableItem; import org.eclipse.osee.ats.api.data.AtsAttributeTypes; +import org.eclipse.osee.ats.api.data.AtsRelationTypes; import org.eclipse.osee.ats.api.notify.AtsNotificationCollector; import org.eclipse.osee.ats.api.notify.AtsNotificationEvent; import org.eclipse.osee.ats.api.notify.AtsNotifyType; @@ -30,11 +31,13 @@ import org.eclipse.osee.ats.api.user.IAtsUser; import org.eclipse.osee.ats.api.user.IAtsUserService; import org.eclipse.osee.ats.api.workdef.IAtsStateDefinition; import org.eclipse.osee.ats.api.workdef.IAttributeResolver; +import org.eclipse.osee.ats.api.workdef.IRelationResolver; import org.eclipse.osee.ats.api.workdef.StateType; import org.eclipse.osee.ats.api.workflow.IAtsTeamWorkflow; import org.eclipse.osee.ats.api.workflow.state.IAtsStateManager; import org.eclipse.osee.ats.rest.IAtsServer; -import org.eclipse.osee.ats.rest.internal.notify.WorkItemNotificationProcessor; +import org.eclipse.osee.framework.core.data.ArtifactId; +import org.eclipse.osee.framework.core.enums.CoreAttributeTypes; import org.eclipse.osee.framework.jdk.core.type.OseeCoreException; import org.eclipse.osee.logger.Log; import org.eclipse.osee.orcs.OrcsApi; @@ -45,14 +48,16 @@ import org.mockito.MockitoAnnotations; /** * Test unit for {@link WorkItemNotificationProcessor} - * + * * @author Donald G. Dunne */ public class WorkItemNotificationProcessorTest { // @formatter:off - @Mock IAtsUser joeSmith_CurrentUser, kay_ValidEmail, jason_ValidEmail, alex_NoValidEmail, inactiveSteve; + @Mock IAtsUser joeSmith_CurrentUser, kay_ValidEmail, jason_ValidEmail, alex_NoValidEmail, inactiveSteve; + @Mock ArtifactId kayArtifact; @Mock IAtsTeamWorkflow teamWf; + @Mock ArtifactId teamWfArt; @Mock IAtsPeerToPeerReview peerReview; @Mock IAtsStateManager stateMgr; @Mock Log logger; @@ -61,6 +66,7 @@ public class WorkItemNotificationProcessorTest { @Mock IAtsWorkItemFactory workItemFactory; @Mock IAtsUserService userService; @Mock IAttributeResolver attrResolver; + @Mock IRelationResolver relResolver; @Mock IAtsStateDefinition stateDef; @Mock IAtsTeamDefinition teamDef; @Mock IAtsActionableItem ai; @@ -71,19 +77,16 @@ public class WorkItemNotificationProcessorTest { public void setup() { MockitoAnnotations.initMocks(this); - setupUser(joeSmith_CurrentUser, 61106791L, "Joe Smith", "joe@boeing.com", "3333", true, - false); + setupUser(joeSmith_CurrentUser, 61106791L, "Joe Smith", "joe@boeing.com", "3333", true, false); setupUser(kay_ValidEmail, 5896672L, "Kay Jones", "kay@boeing.com", "4444", true, false); - setupUser(jason_ValidEmail, 277990L, "Jason Michael", "jason@boeing.com", "5555", - true, false); + setupUser(jason_ValidEmail, 277990L, "Jason Michael", "jason@boeing.com", "5555", true, false); setupUser(alex_NoValidEmail, 8006939L, "Alex Kay", "", "6666", true, false); - setupUser(inactiveSteve, 5808093L, "Inactive Steve", "insactiveSteve@boeing.com", "7777", - false, false); + setupUser(inactiveSteve, 5808093L, "Inactive Steve", "insactiveSteve@boeing.com", "7777", false, false); when(teamWf.getName()).thenReturn(WorkItemNotificationProcessorTest.class.getSimpleName() + "-testNotify"); List<IAtsUser> assignees = new ArrayList<>(); - assignees.addAll(Arrays.asList(inactiveSteve, alex_NoValidEmail, jason_ValidEmail, kay_ValidEmail, - joeSmith_CurrentUser)); + assignees.addAll( + Arrays.asList(inactiveSteve, alex_NoValidEmail, jason_ValidEmail, kay_ValidEmail, joeSmith_CurrentUser)); String atsId = "ATS003"; when(teamWf.getAtsId()).thenReturn(atsId); when(workItemFactory.getWorkItemByAtsId(atsId)).thenReturn(teamWf); @@ -165,8 +168,8 @@ public class WorkItemNotificationProcessorTest { Assert.assertEquals(1, notifications.getNotificationEvents().size()); notifyEvent = notifications.getNotificationEvents().get(0); - Assert.assertTrue(org.eclipse.osee.framework.jdk.core.util.Collections.isEqual(expectedUserIds, - notifyEvent.getUserIds())); + Assert.assertTrue( + org.eclipse.osee.framework.jdk.core.util.Collections.isEqual(expectedUserIds, notifyEvent.getUserIds())); Assert.assertEquals( "You have been set as the assignee of [Team Workflow] in state [Analyze] titled [WorkItemNotificationProcessorTest-testNotify]", notifyEvent.getDescription()); @@ -188,8 +191,13 @@ public class WorkItemNotificationProcessorTest { @org.junit.Test public void testNotifySubscribe() throws OseeCoreException { - - when(userService.getSubscribed(teamWf)).thenReturn(Arrays.asList(kay_ValidEmail)); + when(teamWf.getStoreObject()).thenReturn(teamWfArt); + when(atsServer.getRelationResolver()).thenReturn(relResolver); + when(atsServer.getAttributeResolver()).thenReturn(attrResolver); + when(relResolver.getRelated(teamWf.getStoreObject(), AtsRelationTypes.SubscribedUser_User)).thenReturn( + Arrays.asList(kayArtifact)); + when(attrResolver.getSoleAttributeValue(kayArtifact, CoreAttributeTypes.UserId, null)).thenReturn("4444"); + when(userService.getUserById(eq("4444"))).thenReturn(kay_ValidEmail); AtsWorkItemNotificationEvent event = new AtsWorkItemNotificationEvent(); event.setFromUserId(joeSmith_CurrentUser.getUserId()); event.setNotifyType(AtsNotifyType.Subscribed); diff --git a/plugins/org.eclipse.osee.ats.rest/META-INF/MANIFEST.MF b/plugins/org.eclipse.osee.ats.rest/META-INF/MANIFEST.MF index c5101671f46..caf5c08ea73 100644 --- a/plugins/org.eclipse.osee.ats.rest/META-INF/MANIFEST.MF +++ b/plugins/org.eclipse.osee.ats.rest/META-INF/MANIFEST.MF @@ -9,7 +9,8 @@ Service-Component: OSGI-INF/*.xml Osee-JaxRs-Resource: /web/*;path=/ats/cpa/ui, OSEE-INF/web/*;path=/ats Osee-Template: OSEE-INF/templates/*.html -Import-Package: com.google.common.cache, +Import-Package: com.google.common.base, + com.google.common.cache, com.google.gson;version="2.1.0", com.lowagie.text, com.lowagie.text.html, diff --git a/plugins/org.eclipse.osee.ats.rest/OSGI-INF/ats.user.service.xml b/plugins/org.eclipse.osee.ats.rest/OSGI-INF/ats.user.service.xml index fa5f987c084..3a905dd5f98 100644 --- a/plugins/org.eclipse.osee.ats.rest/OSGI-INF/ats.user.service.xml +++ b/plugins/org.eclipse.osee.ats.rest/OSGI-INF/ats.user.service.xml @@ -1,9 +1,8 @@ <?xml version="1.0" encoding="UTF-8"?> -<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" activate="start" deactivate="stop"> - <implementation class="org.eclipse.osee.ats.rest.internal.user.AtsUserServiceImpl"/> +<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0"> + <implementation class="org.eclipse.osee.ats.rest.internal.config.AtsUserServiceServerImpl"/> <service> <provide interface="org.eclipse.osee.ats.api.user.IAtsUserService"/> </service> <reference bind="setOrcsApi" cardinality="1..1" interface="org.eclipse.osee.orcs.OrcsApi" name="OrcsApi" policy="static"/> - <reference bind="setLogger" cardinality="1..1" interface="org.eclipse.osee.logger.Log" name="Log" policy="static"/> </scr:component> diff --git a/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/AtsServerImpl.java b/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/AtsServerImpl.java index 38d3cafaa02..114c5e5df7a 100644 --- a/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/AtsServerImpl.java +++ b/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/AtsServerImpl.java @@ -164,6 +164,7 @@ public class AtsServerImpl extends AtsCoreServiceImpl implements IAtsServer { new ConcurrentHashMap<String, IAtsDatabaseConversion>(); private IArtifactResolver artifactResolver; private IAtsColumnService columnServices; + private AtsConfigEndpointImpl configurationsProvider; public void setLogger(Log logger) { this.logger = logger; @@ -614,8 +615,16 @@ public class AtsServerImpl extends AtsCoreServiceImpl implements IAtsServer { } @Override - protected AtsConfigurations loadConfigurations() { - return new AtsConfigEndpointImpl(this, orcsApi, logger).get(); + public AtsConfigurations getConfigurations() { + if (configurationsProvider == null) { + configurationsProvider = new AtsConfigEndpointImpl(this, orcsApi, logger); + } + return configurationsProvider.get(); + } + + @Override + public void clearConfigurationsCaches() { + // do nothing } @Override diff --git a/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/config/AtsConfigEndpointImpl.java b/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/config/AtsConfigEndpointImpl.java index 01af2ff34e2..9e4fa2979e1 100644 --- a/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/config/AtsConfigEndpointImpl.java +++ b/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/config/AtsConfigEndpointImpl.java @@ -10,7 +10,10 @@ *******************************************************************************/ package org.eclipse.osee.ats.rest.internal.config; +import com.google.common.base.Supplier; +import com.google.common.base.Suppliers; import java.util.concurrent.Callable; +import java.util.concurrent.TimeUnit; import javax.ws.rs.GET; import javax.ws.rs.POST; import javax.ws.rs.PUT; @@ -30,11 +33,13 @@ import org.eclipse.osee.ats.api.data.AtsArtifactToken; import org.eclipse.osee.ats.api.data.AtsArtifactTypes; import org.eclipse.osee.ats.api.data.AtsAttributeTypes; import org.eclipse.osee.ats.api.user.IAtsUser; +import org.eclipse.osee.ats.api.user.JaxAtsUser; import org.eclipse.osee.ats.api.workdef.JaxAtsWorkDef; import org.eclipse.osee.ats.core.users.AtsCoreUsers; import org.eclipse.osee.ats.core.util.AtsUtilCore; import org.eclipse.osee.ats.rest.IAtsServer; import org.eclipse.osee.framework.core.data.ArtifactId; +import org.eclipse.osee.framework.core.data.HasLocalId; import org.eclipse.osee.framework.core.data.IArtifactToken; import org.eclipse.osee.framework.core.data.TokenFactory; import org.eclipse.osee.framework.core.enums.CoreArtifactTokens; @@ -67,26 +72,61 @@ public final class AtsConfigEndpointImpl implements AtsConfigEndpointApi { this.logger = logger; } + private final Supplier<AtsConfigurations> configurationsCache = + Suppliers.memoizeWithExpiration(getConfigurationsSupplier(), 5, TimeUnit.MINUTES); + + private Supplier<AtsConfigurations> getConfigurationsSupplier() { + return new Supplier<AtsConfigurations>() { + @SuppressWarnings("unchecked") + @Override + public AtsConfigurations get() { + ResultSet<ArtifactReadable> artifacts = + orcsApi.getQueryFactory().fromBranch(CoreBranches.COMMON).andTypeEquals( + AtsArtifactTypes.Configuration).getResults(); + AtsConfigurations configs = new AtsConfigurations(); + for (ArtifactReadable art : artifacts) { + AtsConfiguration config = new AtsConfiguration(); + configs.getConfigs().add(config); + config.setName(art.getName()); + config.setUuid(art.getUuid()); + config.setBranchUuid( + Long.valueOf(art.getSoleAttributeValue(AtsAttributeTypes.AtsConfiguredBranch, "0L"))); + config.setIsDefault(art.getSoleAttributeValue(AtsAttributeTypes.Default, false)); + } + UpdateAtsConfiguration update = new UpdateAtsConfiguration(atsServer); + AtsViews views = update.getConfigViews(); + configs.setViews(views); + configs.setColorColumns(update.getColorColumns()); + for (IAtsUser user : atsServer.getUserService().getUsers()) { + configs.getUsers().add((JaxAtsUser) user); + } + ArtifactReadable atsAdminArt = orcsApi.getQueryFactory().fromBranch(AtsUtilCore.getAtsBranch()).andIds( + AtsArtifactToken.AtsAdmin).getResults().getAtMostOneOrNull(); + if (atsAdminArt != null) { + for (ArtifactReadable member : atsAdminArt.getRelated(CoreRelationTypes.User_Grouping__Members)) { + IAtsUser found = configs.getUsers().stream().filter( + user -> user.getUuid().equals(member.getUuid())).findFirst().orElse(null); + if (found != null) { + configs.getAtsAdmins().add((JaxAtsUser) found); + } + } + } + for (HasLocalId<Integer> configArtId : orcsApi.getQueryFactory().fromBranch( + AtsUtilCore.getAtsBranch()).andIsOfType(AtsArtifactTypes.TeamDefinition, AtsArtifactTypes.Version, + AtsArtifactTypes.ActionableItem).getResultsAsLocalIds()) { + configs.getAtsActiveConfigIds().add(configArtId.getLocalId()); + } + return configs; + } + + }; + } + @GET @Produces(MediaType.APPLICATION_JSON) @Override public AtsConfigurations get() { - ResultSet<ArtifactReadable> artifacts = orcsApi.getQueryFactory().fromBranch(CoreBranches.COMMON).andTypeEquals( - AtsArtifactTypes.Configuration).getResults(); - AtsConfigurations configs = new AtsConfigurations(); - for (ArtifactReadable art : artifacts) { - AtsConfiguration config = new AtsConfiguration(); - configs.getConfigs().add(config); - config.setName(art.getName()); - config.setUuid(art.getUuid()); - config.setBranchUuid(Long.valueOf(art.getSoleAttributeValue(AtsAttributeTypes.AtsConfiguredBranch, "0L"))); - config.setIsDefault(art.getSoleAttributeValue(AtsAttributeTypes.Default, false)); - } - UpdateAtsConfiguration update = new UpdateAtsConfiguration(atsServer); - AtsViews views = update.getConfigViews(); - configs.setViews(views); - configs.setColorColumns(update.getColorColumns()); - return configs; + return configurationsCache.get(); } @GET 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 new file mode 100644 index 00000000000..58aedd426b1 --- /dev/null +++ b/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/config/AtsUserServiceServerImpl.java @@ -0,0 +1,118 @@ +/******************************************************************************* + * Copyright (c) 2016 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.rest.internal.config; + +import com.google.common.base.Supplier; +import com.google.common.base.Suppliers; +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.TimeUnit; +import org.eclipse.osee.ats.api.data.AtsArtifactToken; +import org.eclipse.osee.ats.api.user.IAtsUser; +import org.eclipse.osee.ats.api.user.JaxAtsUser; +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.CoreArtifactTypes; +import org.eclipse.osee.framework.core.enums.CoreAttributeTypes; +import org.eclipse.osee.framework.core.enums.CoreRelationTypes; +import org.eclipse.osee.framework.core.enums.SystemUser; +import org.eclipse.osee.orcs.OrcsApi; +import org.eclipse.osee.orcs.data.ArtifactReadable; + +/** + * @author Donald G. Dunne + */ +public class AtsUserServiceServerImpl extends AbstractAtsUserService { + + private OrcsApi orcsApi; + ArtifactReadable atsAdminArt; + + public void setOrcsApi(OrcsApi orcsApi) { + this.orcsApi = orcsApi; + } + + @Override + public String getCurrentUserId() { + return SystemUser.OseeSystem.getUserId(); + } + + @SuppressWarnings("unchecked") + @Override + public boolean isAtsAdmin(IAtsUser user) { + if (atsAdminArt == null) { + atsAdminArt = orcsApi.getQueryFactory().fromBranch(AtsUtilCore.getAtsBranch()).andIds( + AtsArtifactToken.AtsAdmin).getResults().getAtMostOneOrNull(); + } + return atsAdminArt.areRelated(CoreRelationTypes.User_Grouping__Members, (ArtifactReadable) user.getStoreObject()); + } + + private final Supplier<List<IAtsUser>> usersCache = + Suppliers.memoizeWithExpiration(getConfigurationsSupplier(), 5, TimeUnit.MINUTES); + + private Supplier<List<IAtsUser>> getConfigurationsSupplier() { + return new Supplier<List<IAtsUser>>() { + @Override + public List<IAtsUser> get() { + List<IAtsUser> users = new ArrayList<>(); + for (ArtifactId art : orcsApi.getQueryFactory().fromBranch(AtsUtilCore.getAtsBranch()).andIsOfType( + CoreArtifactTypes.User).getResults()) { + ArtifactReadable userArt = (ArtifactReadable) art; + JaxAtsUser atsUser = createFromArtifact(userArt); + userIdToAtsUser.put(atsUser.getUserId(), atsUser); + nameToAtsUser.put(atsUser.getName(), atsUser); + users.add(atsUser); + } + return users; + } + }; + } + + private JaxAtsUser createFromArtifact(ArtifactReadable userArt) { + JaxAtsUser atsUser = new JaxAtsUser(); + atsUser.setName(userArt.getName()); + atsUser.setStoreObject(userArt); + atsUser.setUserId(userArt.getSoleAttributeValue(CoreAttributeTypes.UserId, "")); + atsUser.setEmail(userArt.getSoleAttributeValue(CoreAttributeTypes.Email, "")); + atsUser.setActive(userArt.getSoleAttributeValue(CoreAttributeTypes.Active, true)); + atsUser.setUuid(userArt.getUuid()); + return atsUser; + } + + @Override + public List<IAtsUser> getUsers() { + return usersCache.get(); + } + + @Override + protected IAtsUser loadUserFromDbByUserId(String userId) { + ArtifactReadable userArt = + orcsApi.getQueryFactory().fromBranch(AtsUtilCore.getAtsBranch()).andIsOfType(CoreArtifactTypes.User).and( + CoreAttributeTypes.UserId, userId).getResults().getAtMostOneOrNull(); + if (userArt != null) { + return createFromArtifact(userArt); + } + return null; + } + + @Override + protected IAtsUser loadUserFromDbByUserName(String name) { + ArtifactReadable userArt = + orcsApi.getQueryFactory().fromBranch(AtsUtilCore.getAtsBranch()).andIsOfType(CoreArtifactTypes.User).and( + CoreAttributeTypes.Name, name).getResults().getAtMostOneOrNull(); + if (userArt != null) { + return createFromArtifact(userArt); + } + return null; + + } + +} diff --git a/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/notify/WorkItemNotificationProcessor.java b/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/notify/WorkItemNotificationProcessor.java index 194d8d6ab9c..f156c95d2ff 100644 --- a/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/notify/WorkItemNotificationProcessor.java +++ b/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/notify/WorkItemNotificationProcessor.java @@ -18,6 +18,7 @@ import java.util.List; import org.eclipse.osee.ats.api.IAtsWorkItem; import org.eclipse.osee.ats.api.ai.IAtsActionableItem; import org.eclipse.osee.ats.api.data.AtsAttributeTypes; +import org.eclipse.osee.ats.api.data.AtsRelationTypes; import org.eclipse.osee.ats.api.notify.AtsNotificationCollector; import org.eclipse.osee.ats.api.notify.AtsNotificationEventFactory; import org.eclipse.osee.ats.api.notify.AtsNotifyType; @@ -37,6 +38,8 @@ import org.eclipse.osee.ats.core.review.UserRoleManager; import org.eclipse.osee.ats.core.users.AtsCoreUsers; import org.eclipse.osee.ats.core.users.AtsUsersUtility; import org.eclipse.osee.ats.rest.IAtsServer; +import org.eclipse.osee.framework.core.data.ArtifactId; +import org.eclipse.osee.framework.core.enums.CoreAttributeTypes; import org.eclipse.osee.framework.jdk.core.type.OseeCoreException; import org.eclipse.osee.framework.jdk.core.util.DateUtil; import org.eclipse.osee.framework.jdk.core.util.EmailUtil; @@ -126,7 +129,7 @@ public class WorkItemNotificationProcessor { if (types.contains(AtsNotifyType.Subscribed)) { try { Collection<IAtsUser> subscribed = new HashSet<>(); - subscribed.addAll(userService.getSubscribed(workItem)); + subscribed.addAll(getSubscribed(workItem)); subscribed = AtsUsersUtility.getValidEmailUsers(subscribed); subscribed = AtsUsersUtility.getActiveEmailUsers(subscribed); if (subscribed.size() > 0) { @@ -235,6 +238,16 @@ public class WorkItemNotificationProcessor { } } + public List<IAtsUser> getSubscribed(IAtsWorkItem workItem) throws OseeCoreException { + ArrayList<IAtsUser> arts = new ArrayList<>(); + for (ArtifactId art : atsServer.getRelationResolver().getRelated(workItem.getStoreObject(), + AtsRelationTypes.SubscribedUser_User)) { + arts.add(userService.getUserById( + (String) atsServer.getAttributeResolver().getSoleAttributeValue(art, CoreAttributeTypes.UserId, null))); + } + return arts; + } + private boolean isOriginatorDifferentThanCancelledOrCompletedBy(IAtsWorkItem workItem, IAtsUser fromUser, IAtsUser originator) { boolean different = true; if (fromUser.equals(originator)) { diff --git a/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/user/AtsUser.java b/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/user/AtsUser.java deleted file mode 100644 index bb51c4ce1c8..00000000000 --- a/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/user/AtsUser.java +++ /dev/null @@ -1,139 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2013 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.rest.internal.user; - -import javax.xml.bind.annotation.XmlRootElement; -import org.codehaus.jackson.annotate.JsonIgnore; -import org.eclipse.osee.ats.api.user.IAtsUser; -import org.eclipse.osee.framework.core.data.ArtifactId; -import org.eclipse.osee.framework.core.enums.CoreAttributeTypes; -import org.eclipse.osee.framework.jdk.core.type.OseeCoreException; -import org.eclipse.osee.framework.jdk.core.type.UuidIdentity; -import org.eclipse.osee.orcs.data.ArtifactReadable; - -/** - * @author Donald G. Dunne - */ -@XmlRootElement -public class AtsUser implements IAtsUser { - - private ArtifactReadable user; - - public AtsUser(ArtifactReadable user) { - this.user = user; - } - - @Override - public String getName() { - return user.getName(); - } - - @Override - public int hashCode() { - final int prime = 31; - int result = 0; - int userIdHashCode = 0; - try { - userIdHashCode = getUserId() == null ? 0 : getUserId().hashCode(); - } catch (OseeCoreException ex) { - // Do nothing; - } - result = prime * result + userIdHashCode; - return result; - } - - @Override - public boolean equals(Object obj) { - if (this == obj) { - return true; - } - if (obj == null) { - return false; - } - try { - String objUserId = null; - if (obj instanceof IAtsUser) { - objUserId = ((IAtsUser) obj).getUserId(); - } else { - return false; - } - String thisUserId = getUserId(); - if (thisUserId == null) { - if (objUserId != null) { - return false; - } - } else if (!thisUserId.equals(objUserId)) { - return false; - } - } catch (OseeCoreException ex) { - return false; - } - return true; - } - - @Override - public String getUserId() throws OseeCoreException { - return user.getSoleAttributeAsString(CoreAttributeTypes.UserId); - } - - @Override - public String getEmail() throws OseeCoreException { - return user.getSoleAttributeAsString(CoreAttributeTypes.Email, ""); - } - - @Override - public boolean isActive() throws OseeCoreException { - return user.getSoleAttributeValue(CoreAttributeTypes.Active, false); - } - - @Override - public String toString() { - try { - return String.format("%s (%s)", getName(), getUserId()); - } catch (Exception ex) { - return "Exception: " + ex.getLocalizedMessage(); - } - } - - @Override - public boolean matches(UuidIdentity... identities) { - for (UuidIdentity identity : identities) { - if (equals(identity)) { - return true; - } - } - return false; - } - - @Override - public String toStringWithId() { - return String.format("[%s][%d]", getName(), getUuid()); - } - - @Override - @JsonIgnore - public ArtifactId getStoreObject() { - return user; - } - - @Override - public void setStoreObject(ArtifactId artifact) { - if (artifact instanceof ArtifactReadable) { - this.user = (ArtifactReadable) artifact; - } - } - - @Override - public Long getUuid() { - return this.user.getUuid(); - } - -} diff --git a/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/user/AtsUserServiceImpl.java b/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/user/AtsUserServiceImpl.java deleted file mode 100644 index 5f6b4e0ba24..00000000000 --- a/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/user/AtsUserServiceImpl.java +++ /dev/null @@ -1,168 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2013 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.rest.internal.user; - -import java.util.ArrayList; -import java.util.List; -import org.eclipse.osee.ats.api.IAtsWorkItem; -import org.eclipse.osee.ats.api.data.AtsArtifactToken; -import org.eclipse.osee.ats.api.data.AtsRelationTypes; -import org.eclipse.osee.ats.api.user.IAtsUser; -import org.eclipse.osee.ats.core.users.AbstractAtsUserService; -import org.eclipse.osee.ats.core.util.AtsUtilCore; -import org.eclipse.osee.framework.core.enums.Active; -import org.eclipse.osee.framework.core.enums.CoreArtifactTypes; -import org.eclipse.osee.framework.core.enums.CoreAttributeTypes; -import org.eclipse.osee.framework.core.enums.CoreRelationTypes; -import org.eclipse.osee.framework.core.enums.SystemUser; -import org.eclipse.osee.framework.jdk.core.type.OseeCoreException; -import org.eclipse.osee.framework.jdk.core.type.ResultSet; -import org.eclipse.osee.framework.jdk.core.util.Conditions; -import org.eclipse.osee.logger.Log; -import org.eclipse.osee.orcs.OrcsApi; -import org.eclipse.osee.orcs.data.ArtifactReadable; - -/** - * Non-artifact base user service - * - * @author Donald G Dunne - */ -public class AtsUserServiceImpl extends AbstractAtsUserService { - - private OrcsApi orcsApi; - private Log logger; - - public void setLogger(Log logger) { - this.logger = logger; - } - - public void setOrcsApi(OrcsApi orcsApi) { - this.orcsApi = orcsApi; - } - - public void start() throws OseeCoreException { - Conditions.checkNotNull(orcsApi, "OrcsApi"); - logger.info("AtsUserService started"); - } - - public void stop() { - // - } - - @Override - public String getCurrentUserId() throws OseeCoreException { - if (currentUserId == null) { - currentUserId = SystemUser.OseeSystem.getUserId(); - } - return currentUserId; - } - - // TODO Replace this once server has user account - @Override - public IAtsUser getCurrentUser() throws OseeCoreException { - if (currentUser == null) { - currentUser = getUserById(getCurrentUserId()); - } - return currentUser; - } - - @Override - protected IAtsUser loadUserByUserIdFromDb(String userId) { - IAtsUser atsUser = null; - ResultSet<ArtifactReadable> results = - orcsApi.getQueryFactory().fromBranch(AtsUtilCore.getAtsBranch()).andIsOfType(CoreArtifactTypes.User).and( - CoreAttributeTypes.UserId, userId).getResults(); - if (!results.isEmpty()) { - ArtifactReadable userArt = results.getExactlyOne(); - atsUser = new AtsUser(userArt); - } - return atsUser; - } - - @Override - protected IAtsUser loadUserByUserNameFromDb(String name) { - IAtsUser atsUser = null; - ArtifactReadable userArt = - orcsApi.getQueryFactory().fromBranch(AtsUtilCore.getAtsBranch()).andIsOfType(CoreArtifactTypes.User).and( - CoreAttributeTypes.Name, name).getResults().getExactlyOne(); - if (userArt != null) { - atsUser = new AtsUser(userArt); - } - return atsUser; - } - - @Override - public boolean isAtsAdmin(IAtsUser user) { - ensureLoaded(); - Boolean admin = userIdToAdmin.get(user.getUserId()); - if (admin == null) { - admin = orcsApi.getQueryFactory().fromBranch(AtsUtilCore.getAtsBranch()).andGuid( - AtsArtifactToken.AtsAdmin.getGuid()).andRelatedTo(CoreRelationTypes.Users_User, - getUserArt(user)).getCount() == 1; - userIdToAdmin.put(user.getUserId(), admin); - } - return admin; - } - - private ArtifactReadable getUserArt(IAtsUser user) { - ensureLoaded(); - if (user.getStoreObject() instanceof ArtifactReadable) { - return (ArtifactReadable) user.getStoreObject(); - } - return orcsApi.getQueryFactory().fromBranch(AtsUtilCore.getAtsBranch()).andUuid( - user.getUuid()).getResults().getExactlyOne(); - } - - @Override - public List<IAtsUser> getUsers(Active active) { - ensureLoaded(); - List<IAtsUser> users = new ArrayList<>(); - for (ArtifactReadable userArt : orcsApi.getQueryFactory().fromBranch(AtsUtilCore.getAtsBranch()).andIsOfType( - CoreArtifactTypes.User).getResults()) { - Boolean activeFlag = userArt.getSoleAttributeValue(CoreAttributeTypes.Active, true); - if (active == Active.Both || active == Active.Active && activeFlag || active == Active.InActive && !activeFlag) { - users.add(new AtsUser(userArt)); - } - } - return users; - } - - @Override - protected synchronized void ensureLoaded() { - if (!loaded) { - for (ArtifactReadable art : orcsApi.getQueryFactory().fromBranch(AtsUtilCore.getAtsBranch()).andIsOfType( - CoreArtifactTypes.User).getResults()) { - AtsUser atsUser = new AtsUser(art); - userIdToAtsUser.put(art.getSoleAttributeValue(CoreAttributeTypes.UserId, ""), atsUser); - nameToAtsUser.put(art.getName(), atsUser); - } - loaded = true; - } - } - - @Override - public List<IAtsUser> getSubscribed(IAtsWorkItem workItem) throws OseeCoreException { - ArrayList<IAtsUser> arts = new ArrayList<>(); - for (ArtifactReadable art : ((ArtifactReadable) workItem.getStoreObject()).getRelated( - AtsRelationTypes.SubscribedUser_User)) { - arts.add(getUserById((String) art.getSoleAttributeValue(CoreAttributeTypes.UserId))); - } - return arts; - } - - @Override - public IAtsUser getUserById(long accountId) { - ArtifactReadable userArt = orcsApi.getQueryFactory().fromBranch(AtsUtilCore.getAtsBranch()).andUuid( - accountId).getResults().getAtMostOneOrNull(); - return getUserById(userArt.getSoleAttributeValue(CoreAttributeTypes.UserId, null)); - } - -} diff --git a/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/workitem/CreateTasksOperation.java b/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/workitem/CreateTasksOperation.java index 47158ff8fde..3859e456475 100644 --- a/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/workitem/CreateTasksOperation.java +++ b/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/workitem/CreateTasksOperation.java @@ -109,7 +109,7 @@ public class CreateTasksOperation { for (JaxAtsTask task : newTaskData.getNewTasks()) { Long taskUuid = task.getUuid(); - if (taskUuid > 0L) { + if (taskUuid != null && taskUuid > 0L) { ArtifactReadable taskArt = atsServer.getArtifact(taskUuid); if (taskArt != null) { resultData.errorf("Task with uuid %d already exists for %s", taskUuid, task); @@ -250,7 +250,7 @@ public class CreateTasksOperation { for (JaxAtsTask jaxTask : newTaskData.getNewTasks()) { Long uuid = jaxTask.getUuid(); - if (uuid <= 0L) { + if (uuid == null || uuid <= 0L) { uuid = Lib.generateArtifactIdAsInt(); jaxTask.setUuid(uuid); } diff --git a/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/world/WorldResource.java b/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/world/WorldResource.java index 2d72beb980a..f720e757acd 100644 --- a/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/world/WorldResource.java +++ b/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/world/WorldResource.java @@ -31,6 +31,7 @@ import org.eclipse.osee.ats.api.user.IAtsUser; import org.eclipse.osee.ats.api.workflow.WorkItemType; import org.eclipse.osee.ats.core.column.AtsColumnId; import org.eclipse.osee.ats.rest.IAtsServer; +import org.eclipse.osee.framework.core.enums.CoreAttributeTypes; import org.eclipse.osee.framework.jdk.core.util.AHTML; import org.eclipse.osee.framework.jdk.core.util.Conditions; import org.eclipse.osee.framework.jdk.core.util.ElapsedTime; @@ -76,7 +77,9 @@ public class WorldResource { @Path("my/{uuid}") @Produces(MediaType.APPLICATION_JSON) public Collection<IAtsWorkItem> getMyWorld(@PathParam("uuid") int uuid) throws Exception { - IAtsUser userById = atsServer.getUserService().getUserById(new Long(uuid)); + ArtifactReadable userArt = atsServer.getArtifact(Long.valueOf(uuid)); + IAtsUser userById = + atsServer.getUserService().getUserById(userArt.getSoleAttributeValue(CoreAttributeTypes.UserId)); Collection<IAtsWorkItem> myWorldItems = atsServer.getQueryService().createQuery(WorkItemType.WorkItem).andAssignee(userById).getItems( IAtsWorkItem.class); @@ -88,7 +91,9 @@ public class WorldResource { @Produces(MediaType.TEXT_HTML) public String getMyWorldUI(@PathParam("uuid") int uuid) throws Exception { StringBuilder sb = new StringBuilder(); - IAtsUser userById = atsServer.getUserService().getUserById(new Long(uuid)); + ArtifactReadable userArt = atsServer.getArtifact(Long.valueOf(uuid)); + IAtsUser userById = + atsServer.getUserService().getUserById(userArt.getSoleAttributeValue(CoreAttributeTypes.UserId)); Collection<IAtsWorkItem> myWorldItems = atsServer.getQueryService().createQuery(WorkItemType.WorkItem).andAssignee(userById).getItems( IAtsWorkItem.class); @@ -101,7 +106,9 @@ public class WorldResource { @Produces(MediaType.TEXT_HTML) public String getMyWorldUICustomized(@PathParam("uuid") int uuid, @PathParam("customize_guid") String customize_guid) throws Exception { ElapsedTime time = new ElapsedTime("start"); - IAtsUser userById = atsServer.getUserService().getUserById(new Long(uuid)); + ArtifactReadable userArt = atsServer.getArtifact(Long.valueOf(uuid)); + IAtsUser userById = + atsServer.getUserService().getUserById(userArt.getSoleAttributeValue(CoreAttributeTypes.UserId)); Conditions.checkNotNull(userById, "User by Id " + uuid); ElapsedTime getCustomization = new ElapsedTime("getCustomizationByGuid"); diff --git a/plugins/org.eclipse.osee.ats/src/org/eclipse/osee/ats/config/AtsConfigOperation.java b/plugins/org.eclipse.osee.ats/src/org/eclipse/osee/ats/config/AtsConfigOperation.java index 37553cd99dd..a5507bd99dc 100644 --- a/plugins/org.eclipse.osee.ats/src/org/eclipse/osee/ats/config/AtsConfigOperation.java +++ b/plugins/org.eclipse.osee.ats/src/org/eclipse/osee/ats/config/AtsConfigOperation.java @@ -202,17 +202,21 @@ public class AtsConfigOperation extends AbstractOperation { IAtsWorkDefinition workDef = null; // If can't be found, create a new one if (!workDefMatch.isMatched()) { - workDef = generateDefaultWorkflow(name, resultData, changes, teamDef); + IAtsChangeSet changes2 = AtsClientService.get().getStoreService().createAtsChangeSet("Create Work Definition", + AtsClientService.get().getUserService().getCurrentUser()); + workDef = generateDefaultWorkflow(name, resultData, changes2, teamDef); try { String workDefXml = AtsClientService.get().getWorkDefinitionAdmin().getStorageString(workDef, resultData); Artifact workDefArt = AtsWorkDefinitionImporter.get().importWorkDefinitionToDb(workDefXml, - workDef.getName(), name, null, resultData, changes); + workDef.getName(), name, null, resultData, changes2); Artifact folder = AtsUtilClient.getFromToken(AtsArtifactToken.WorkDefinitionsFolder); folder.addChild(workDefArt); - changes.add(folder); + changes2.add(folder); } catch (Exception ex) { throw new OseeWrappedException(ex); } + changes2.executeIfNeeded(); + AtsClientService.get().getWorkDefinitionAdmin().clearCaches(); } else { workDef = workDefMatch.getWorkDefinition(); } |