diff options
Diffstat (limited to 'plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal')
95 files changed, 7665 insertions, 54 deletions
diff --git a/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/AtsApplication.java b/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/AtsApplication.java index a8a522e50e4..c292e3f96aa 100644 --- a/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/AtsApplication.java +++ b/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/AtsApplication.java @@ -14,7 +14,7 @@ import java.util.HashSet; import java.util.Set; import javax.ws.rs.ApplicationPath; import javax.ws.rs.core.Application; -import org.eclipse.osee.ats.impl.IAtsServer; +import org.eclipse.osee.ats.rest.IAtsServer; import org.eclipse.osee.ats.rest.internal.agile.AgileEndpointImpl; import org.eclipse.osee.ats.rest.internal.config.ActionableItemResource; import org.eclipse.osee.ats.rest.internal.config.AtsConfigEndpointImpl; 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 new file mode 100644 index 00000000000..32b2ebcdc0d --- /dev/null +++ b/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/AtsServerImpl.java @@ -0,0 +1,607 @@ +/******************************************************************************* + * 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; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.Iterator; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.CopyOnWriteArrayList; +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.IAtsWorkItem; +import org.eclipse.osee.ats.api.agile.IAgileService; +import org.eclipse.osee.ats.api.data.AtsArtifactToken; +import org.eclipse.osee.ats.api.data.AtsAttributeTypes; +import org.eclipse.osee.ats.api.notify.AtsNotificationCollector; +import org.eclipse.osee.ats.api.program.IAtsProgramService; +import org.eclipse.osee.ats.api.query.IAtsQueryService; +import org.eclipse.osee.ats.api.review.IAtsReviewService; +import org.eclipse.osee.ats.api.task.IAtsTaskService; +import org.eclipse.osee.ats.api.team.ChangeType; +import org.eclipse.osee.ats.api.team.IAtsConfigItemFactory; +import org.eclipse.osee.ats.api.team.IAtsTeamDefinitionService; +import org.eclipse.osee.ats.api.team.IAtsWorkItemFactory; +import org.eclipse.osee.ats.api.user.IAtsUserService; +import org.eclipse.osee.ats.api.util.IArtifactResolver; +import org.eclipse.osee.ats.api.util.IAtsChangeSet; +import org.eclipse.osee.ats.api.util.IAtsDatabaseConversion; +import org.eclipse.osee.ats.api.util.IAtsStoreService; +import org.eclipse.osee.ats.api.util.IAtsUtilService; +import org.eclipse.osee.ats.api.util.ISequenceProvider; +import org.eclipse.osee.ats.api.version.IAtsVersionService; +import org.eclipse.osee.ats.api.workdef.IAtsStateDefinition; +import org.eclipse.osee.ats.api.workdef.IAtsWorkDefinitionAdmin; +import org.eclipse.osee.ats.api.workdef.IAtsWorkDefinitionService; +import org.eclipse.osee.ats.api.workdef.IAttributeResolver; +import org.eclipse.osee.ats.api.workdef.IRelationResolver; +import org.eclipse.osee.ats.api.workdef.WidgetResult; +import org.eclipse.osee.ats.api.workflow.IAtsAction; +import org.eclipse.osee.ats.api.workflow.IAtsBranchService; +import org.eclipse.osee.ats.api.workflow.IAtsWorkItemService; +import org.eclipse.osee.ats.api.workflow.log.IAtsLogFactory; +import org.eclipse.osee.ats.api.workflow.state.IAtsStateFactory; +import org.eclipse.osee.ats.api.workflow.transition.ITransitionListener; +import org.eclipse.osee.ats.core.ai.ActionableItemManager; +import org.eclipse.osee.ats.core.config.IAtsConfig; +import org.eclipse.osee.ats.core.util.ActionFactory; +import org.eclipse.osee.ats.core.util.AtsCoreFactory; +import org.eclipse.osee.ats.core.util.AtsCoreServiceImpl; +import org.eclipse.osee.ats.core.util.AtsUtilCore; +import org.eclipse.osee.ats.core.util.IAtsActionFactory; +import org.eclipse.osee.ats.core.workdef.AtsWorkDefinitionAdminImpl; +import org.eclipse.osee.ats.core.workflow.AtsWorkItemServiceImpl; +import org.eclipse.osee.ats.core.workflow.TeamWorkflowProviders; +import org.eclipse.osee.ats.rest.IAtsServer; +import org.eclipse.osee.ats.rest.internal.agile.AgileService; +import org.eclipse.osee.ats.rest.internal.convert.ConvertBaselineGuidToBaselineUuid; +import org.eclipse.osee.ats.rest.internal.convert.ConvertFavoriteBranchGuidToUuid; +import org.eclipse.osee.ats.rest.internal.notify.AtsNotificationEventProcessor; +import org.eclipse.osee.ats.rest.internal.notify.AtsNotifierServiceImpl; +import org.eclipse.osee.ats.rest.internal.notify.WorkItemNotificationProcessor; +import org.eclipse.osee.ats.rest.internal.query.AtsQueryServiceIimpl; +import org.eclipse.osee.ats.rest.internal.util.ArtifactResolverImpl; +import org.eclipse.osee.ats.rest.internal.util.AtsArtifactConfigCache; +import org.eclipse.osee.ats.rest.internal.util.AtsAttributeResolverServiceImpl; +import org.eclipse.osee.ats.rest.internal.util.AtsBranchServiceImpl; +import org.eclipse.osee.ats.rest.internal.util.AtsRelationResolverServiceImpl; +import org.eclipse.osee.ats.rest.internal.util.AtsReviewServiceImpl; +import org.eclipse.osee.ats.rest.internal.util.AtsStoreServiceImpl; +import org.eclipse.osee.ats.rest.internal.util.AtsWorkDefinitionCacheProvider; +import org.eclipse.osee.ats.rest.internal.util.ChangeTypeUtil; +import org.eclipse.osee.ats.rest.internal.workitem.AtsProgramService; +import org.eclipse.osee.ats.rest.internal.workitem.AtsTaskService; +import org.eclipse.osee.ats.rest.internal.workitem.AtsTeamDefinitionService; +import org.eclipse.osee.ats.rest.internal.workitem.AtsVersionServiceImpl; +import org.eclipse.osee.ats.rest.internal.workitem.ConfigItemFactory; +import org.eclipse.osee.ats.rest.internal.workitem.WorkItemFactory; +import org.eclipse.osee.ats.rest.util.IAtsNotifierServer; +import org.eclipse.osee.framework.core.data.ArtifactId; +import org.eclipse.osee.framework.core.data.IArtifactToken; +import org.eclipse.osee.framework.core.data.IArtifactType; +import org.eclipse.osee.framework.core.enums.CoreAttributeTypes; +import org.eclipse.osee.framework.core.enums.CoreBranches; +import org.eclipse.osee.framework.jdk.core.type.ItemDoesNotExist; +import org.eclipse.osee.framework.jdk.core.type.OseeCoreException; +import org.eclipse.osee.framework.jdk.core.type.OseeStateException; +import org.eclipse.osee.framework.jdk.core.util.GUID; +import org.eclipse.osee.jdbc.JdbcClient; +import org.eclipse.osee.jdbc.JdbcService; +import org.eclipse.osee.logger.Log; +import org.eclipse.osee.orcs.OrcsApi; +import org.eclipse.osee.orcs.data.ArtifactReadable; +import org.eclipse.osee.orcs.search.QueryBuilder; + +/** + * @author Donald G Dunne + */ +public class AtsServerImpl extends AtsCoreServiceImpl implements IAtsServer { + + public static String PLUGIN_ID = "org.eclipse.osee.ats.rest"; + private OrcsApi orcsApi; + private Log logger; + private IAtsWorkItemFactory workItemFactory; + private IAtsWorkDefinitionService workDefService; + private IAtsUserService userService; + private AtsNotifierServiceImpl notifyService; + private IAtsWorkItemService workItemService; + private IAtsBranchService branchService; + private IAtsReviewService reviewService; + private IAtsWorkDefinitionAdmin workDefAdmin; + private AtsWorkDefinitionCacheProvider workDefCacheProvider; + private AtsAttributeResolverServiceImpl attributeResolverService; + private IAtsConfig config; + private IAtsConfigItemFactory configItemFactory; + private IAtsLogFactory atsLogFactory; + private IAtsStateFactory atsStateFactory; + private IAtsStoreService atsStoreService; + private IAtsUtilService utilService; + private ISequenceProvider sequenceProvider; + private IAtsActionFactory actionFactory; + private ActionableItemManager actionableItemManager; + private JdbcService jdbcService; + private WorkItemNotificationProcessor workItemNotificationProcessor; + private AtsNotificationEventProcessor notificationEventProcessor; + private IAtsVersionService versionService; + private IRelationResolver relationResolver; + private IAtsProgramService atsProgramService; + private IAtsTeamDefinitionService atsTeamDefinitionService; + private JdbcClient jdbcClient; + private IAgileService agileService; + private IAtsQueryService atsQueryService; + private IAtsTaskService taskService; + + private volatile boolean emailEnabled = true; + private boolean loggedNotificationDisabled = false; + + private final List<IAtsNotifierServer> notifiers = new CopyOnWriteArrayList<>(); + private final Map<String, IAtsDatabaseConversion> externalConversions = + new ConcurrentHashMap<String, IAtsDatabaseConversion>(); + private IArtifactResolver artifactResolver; + + public void setLogger(Log logger) { + this.logger = logger; + } + + @Override + public IAtsConfigItemFactory getConfigItemFactory() { + return configItemFactory; + } + + public void setJdbcService(JdbcService jdbcService) { + this.jdbcService = jdbcService; + } + + public void setOrcsApi(OrcsApi orcsApi) { + this.orcsApi = orcsApi; + } + + public void setWorkDefService(IAtsWorkDefinitionService workDefService) { + this.workDefService = workDefService; + } + + public void setAtsUserService(IAtsUserService userService) { + this.userService = userService; + } + + @Override + public void addAtsDatabaseConversion(IAtsDatabaseConversion conversion) { + externalConversions.put(conversion.getName(), conversion); + } + + public void removeAtsDatabaseConversion(IAtsDatabaseConversion conversion) { + externalConversions.remove(conversion.getName()); + } + + public void addNotifier(IAtsNotifierServer notifier) { + notifiers.add(notifier); + } + + public void removeNotifier(IAtsNotifierServer notifier) { + notifiers.remove(notifier); + } + + public void start() throws OseeCoreException { + jdbcClient = jdbcService.getClient(); + + notifyService = new AtsNotifierServiceImpl(); + workItemFactory = new WorkItemFactory(logger, this); + configItemFactory = new ConfigItemFactory(logger, this); + + TeamWorkflowProviders teamWorkflowProvidersLazy = new TeamWorkflowProviders(); + artifactResolver = new ArtifactResolverImpl(this, orcsApi); + workItemService = new AtsWorkItemServiceImpl(this, teamWorkflowProvidersLazy); + branchService = new AtsBranchServiceImpl(getServices(), orcsApi, teamWorkflowProvidersLazy); + reviewService = new AtsReviewServiceImpl(this, this, workItemService); + workDefCacheProvider = new AtsWorkDefinitionCacheProvider(workDefService); + + attributeResolverService = new AtsAttributeResolverServiceImpl(); + relationResolver = new AtsRelationResolverServiceImpl(this); + attributeResolverService.setOrcsApi(orcsApi); + workDefAdmin = new AtsWorkDefinitionAdminImpl(workDefCacheProvider, workDefService, attributeResolverService, + teamWorkflowProvidersLazy); + + atsLogFactory = AtsCoreFactory.newLogFactory(); + atsStateFactory = AtsCoreFactory.newStateFactory(getServices(), atsLogFactory); + atsStoreService = new AtsStoreServiceImpl(attributeResolverService, this, atsStateFactory, atsLogFactory, this); + + utilService = AtsCoreFactory.getUtilService(attributeResolverService); + sequenceProvider = new ISequenceProvider() { + + @Override + public long getNext(String sequenceName) { + // Sequence is set to sequential + return jdbcClient.getNextSequence(sequenceName, false); + } + + }; + config = new AtsArtifactConfigCache(configItemFactory, orcsApi); + actionableItemManager = new ActionableItemManager(config, attributeResolverService, atsStoreService); + actionFactory = new ActionFactory(workItemFactory, utilService, sequenceProvider, actionableItemManager, + userService, attributeResolverService, atsStateFactory, config, getServices()); + atsProgramService = new AtsProgramService(this); + atsTeamDefinitionService = new AtsTeamDefinitionService(this); + + agileService = new AgileService(logger, this); + atsQueryService = new AtsQueryServiceIimpl(this); + versionService = new AtsVersionServiceImpl(getServices()); + taskService = new AtsTaskService(this); + + addAtsDatabaseConversion(new ConvertBaselineGuidToBaselineUuid(logger, jdbcClient, orcsApi, this)); + addAtsDatabaseConversion(new ConvertFavoriteBranchGuidToUuid(logger, jdbcClient, orcsApi, this)); + + logger.info("ATS Application started"); + } + + public void stop() { + jdbcClient = null; + } + + @Override + public OrcsApi getOrcsApi() throws OseeCoreException { + return orcsApi; + } + + @Override + public IAtsWorkItemFactory getWorkItemFactory() throws OseeCoreException { + return workItemFactory; + } + + @Override + public IAtsWorkDefinitionService getWorkDefService() throws OseeCoreException { + return workDefService; + } + + @Override + public IAtsUserService getUserService() throws OseeCoreException { + return userService; + } + + @Override + public ArtifactReadable getArtifact(ArtifactId artifact) throws OseeCoreException { + ArtifactReadable result = null; + if (artifact instanceof ArtifactReadable) { + result = (ArtifactReadable) artifact; + } else if (artifact instanceof IAtsObject) { + IAtsObject atsObject = (IAtsObject) artifact; + if (atsObject.getStoreObject() != null) { + result = (ArtifactReadable) atsObject.getStoreObject(); + } else { + result = orcsApi.getQueryFactory().fromBranch(AtsUtilCore.getAtsBranch()).andUuid( + atsObject.getUuid()).getResults().getAtMostOneOrNull(); + } + } + return result; + } + + @Override + public ArtifactReadable getArtifact(IAtsObject atsObject) throws OseeCoreException { + ArtifactReadable result = null; + if (atsObject.getStoreObject() != null) { + result = (ArtifactReadable) atsObject.getStoreObject(); + } else { + result = orcsApi.getQueryFactory().fromBranch(AtsUtilCore.getAtsBranch()).andUuid( + atsObject.getUuid()).getResults().getAtMostOneOrNull(); + } + return result; + } + + @Override + public IAtsWorkItemService getWorkItemService() throws OseeStateException { + return workItemService; + } + + @Override + public IAtsBranchService getBranchService() { + return branchService; + } + + @Override + public IAtsReviewService getReviewService() { + return reviewService; + } + + @Override + public ArtifactReadable getArtifactByGuid(String guid) throws OseeCoreException { + ArtifactReadable artifact = null; + try { + artifact = + orcsApi.getQueryFactory().fromBranch(AtsUtilCore.getAtsBranch()).andGuid(guid).getResults().getExactlyOne(); + } catch (ItemDoesNotExist ex) { + // do nothing + } + return artifact; + } + + @Override + public ArtifactReadable getArtifactByAtsId(String id) { + ArtifactReadable artifact = null; + try { + artifact = orcsApi.getQueryFactory().fromBranch(AtsUtilCore.getAtsBranch()).and(AtsAttributeTypes.AtsId, + id).getResults().getOneOrNull(); + } catch (ItemDoesNotExist ex) { + // do nothing + } + return artifact; + } + + @Override + public IAtsWorkDefinitionAdmin getWorkDefAdmin() { + return workDefAdmin; + } + + @Override + public IAttributeResolver getAttributeResolver() { + return attributeResolverService; + } + + @Override + public IAtsConfig getConfig() throws OseeStateException { + return config; + } + + @Override + public IAtsStoreService getStoreService() { + return atsStoreService; + } + + @Override + public IAtsLogFactory getLogFactory() { + return atsLogFactory; + } + + @Override + public IAtsStateFactory getStateFactory() { + return atsStateFactory; + } + + @Override + public Iterable<IAtsDatabaseConversion> getDatabaseConversions() { + return externalConversions.values(); + } + + @Override + public IAtsUtilService getUtilService() { + return utilService; + } + + @Override + public ISequenceProvider getSequenceProvider() { + return sequenceProvider; + } + + @Override + public IAtsActionFactory getActionFactory() { + return actionFactory; + } + + @Override + public ArtifactId getArtifactById(String id) { + ArtifactReadable action = null; + if (GUID.isValid(id)) { + action = getArtifactByGuid(id); + } + Long uuid = null; + try { + uuid = Long.parseLong(id); + } catch (NumberFormatException ex) { + // do nothing + } + if (uuid != null) { + action = getArtifact(uuid); + } + if (action == null) { + action = getArtifactByAtsId(id); + } + return action; + } + + @Override + public ArtifactReadable getArtifact(Long uuid) { + return orcsApi.getQueryFactory().fromBranch(AtsUtilCore.getAtsBranch()).andUuid( + new Long(uuid).intValue()).getResults().getOneOrNull(); + } + + @Override + public Collection<ArtifactReadable> getArtifacts(List<Long> uuids) { + Collection<ArtifactReadable> artifacts = new LinkedList<>(); + Iterator<ArtifactReadable> iterator = + orcsApi.getQueryFactory().fromBranch(AtsUtilCore.getAtsBranch()).andUuids(uuids).getResults().iterator(); + while (iterator.hasNext()) { + artifacts.add(iterator.next()); + } + return artifacts; + } + + @Override + public List<ArtifactReadable> getArtifactListByIds(String ids) { + List<ArtifactReadable> actions = new ArrayList<>(); + for (String id : ids.split(",")) { + id = id.replaceAll("^ +", ""); + id = id.replaceAll(" +$", ""); + ArtifactReadable action = (ArtifactReadable) getArtifactById(id); + if (action != null) { + actions.add(action); + } + } + return actions; + } + + @Override + public QueryBuilder getQuery() { + return getOrcsApi().getQueryFactory().fromBranch(AtsUtilCore.getAtsBranch()); + } + + @Override + public String getConfigValue(String key) { + String result = null; + @SuppressWarnings("unchecked") + ArtifactReadable atsConfig = orcsApi.getQueryFactory().fromBranch(CoreBranches.COMMON).andIds( + AtsArtifactToken.AtsConfig).getResults().getAtMostOneOrNull(); + if (atsConfig != null) { + for (Object obj : atsConfig.getAttributeValues(CoreAttributeTypes.GeneralStringData)) { + String str = (String) obj; + if (str.startsWith(key)) { + result = str.replaceFirst(key + "=", ""); + break; + } + } + } + return result; + } + + @Override + public boolean isProduction() { + return jdbcClient.getConfig().isProduction(); + } + + @Override + public IAtsServices getServices() { + return this; + } + + @Override + public void sendNotifications(AtsNotificationCollector notifications) { + if (isEmailEnabled()) { + if (notifiers.isEmpty() || !isProduction()) { + if (!loggedNotificationDisabled) { + logger.info("Osee Notification Disabled"); + loggedNotificationDisabled = true; + } + } else { + workItemNotificationProcessor = + new WorkItemNotificationProcessor(logger, this, workItemFactory, userService, attributeResolverService); + notificationEventProcessor = new AtsNotificationEventProcessor(workItemNotificationProcessor, userService, + getConfigValue("NoReplyEmail")); + notificationEventProcessor.sendNotifications(notifications, notifiers); + } + } + } + + @Override + public IAtsVersionService getVersionService() { + return versionService; + } + + public AtsNotifierServiceImpl getNotifyService() { + return notifyService; + } + + @Override + public List<IAtsWorkItem> getWorkItemListByIds(String ids) { + List<IAtsWorkItem> workItems = new ArrayList<>(); + for (ArtifactReadable art : getArtifactListByIds(ids)) { + IAtsWorkItem workItem = workItemFactory.getWorkItem(art); + if (workItem != null) { + workItems.add(workItem); + } + } + return workItems; + } + + @Override + public void setChangeType(IAtsObject atsObject, ChangeType changeType, IAtsChangeSet changes) { + ChangeTypeUtil.setChangeType(atsObject, changeType, changes); + } + + @Override + public ChangeType getChangeType(IAtsAction fromAction) { + return ChangeTypeUtil.getChangeType(fromAction); + } + + @Override + public Collection<IArtifactType> getArtifactTypes() { + List<IArtifactType> types = new ArrayList<>(); + types.addAll(orcsApi.getOrcsTypes().getArtifactTypes().getAll()); + return types; + } + + @Override + public IRelationResolver getRelationResolver() { + return relationResolver; + } + + public boolean isEmailEnabled() { + return emailEnabled; + } + + @Override + public void setEmailEnabled(boolean emailEnabled) { + this.emailEnabled = emailEnabled; + } + + @Override + public IAtsProgramService getProgramService() { + return atsProgramService; + } + + @Override + public IAtsTeamDefinitionService getTeamDefinitionService() { + return atsTeamDefinitionService; + } + + @Override + public IAgileService getAgileService() { + return agileService; + } + + @Override + public IAtsQueryService getQueryService() { + return atsQueryService; + } + + @Override + public ArtifactReadable getArtifact(IArtifactToken token) { + return getArtifact(token.getUuid()); + } + + @Override + public <A extends IAtsConfigObject> A getSoleByUuid(long uuid, Class<A> clazz) throws OseeCoreException { + return getConfig().getSoleByUuid(uuid, clazz); + } + + @Override + public Collection<ITransitionListener> getTransitionListeners() { + return Collections.emptyList(); + } + + @Override + public Collection<WidgetResult> validateWidgetTransition(IAtsWorkItem workItem, IAtsStateDefinition toStateDef) { + return Collections.emptyList(); + } + + @Override + public void clearImplementersCache(IAtsWorkItem workItem) { + // do nothing; no cache on server + } + + @Override + public IArtifactResolver getArtifactResolver() { + return artifactResolver; + } + + @Override + public IAtsTaskService getTaskService() { + return taskService; + } + + @Override + public ArtifactId getArtifactByName(IArtifactType artifactType, String name) { + return orcsApi.getQueryFactory().fromBranch(AtsUtilCore.getAtsBranch()).andIsOfType(artifactType).andNameEquals( + name).getResults().getAtMostOneOrNull(); + } + +} diff --git a/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/agile/AgileEndpointImpl.java b/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/agile/AgileEndpointImpl.java index 4f156291ee6..b1c48d7f9b2 100644 --- a/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/agile/AgileEndpointImpl.java +++ b/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/agile/AgileEndpointImpl.java @@ -40,7 +40,7 @@ import org.eclipse.osee.ats.api.agile.JaxNewAgileTeam; import org.eclipse.osee.ats.api.data.AtsArtifactTypes; import org.eclipse.osee.ats.api.data.AtsRelationTypes; import org.eclipse.osee.ats.core.util.AtsUtilCore; -import org.eclipse.osee.ats.impl.IAtsServer; +import org.eclipse.osee.ats.rest.IAtsServer; import org.eclipse.osee.framework.core.enums.CoreBranches; import org.eclipse.osee.framework.jdk.core.type.ClassBasedResourceToken; import org.eclipse.osee.framework.jdk.core.type.IResourceRegistry; diff --git a/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/agile/AgileFactory.java b/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/agile/AgileFactory.java new file mode 100644 index 00000000000..be207cb0f36 --- /dev/null +++ b/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/agile/AgileFactory.java @@ -0,0 +1,224 @@ +/******************************************************************************* + * Copyright (c) 2015 Boeing. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.ats.rest.internal.agile; + +import java.util.Arrays; +import java.util.Date; +import java.util.HashSet; +import java.util.Set; +import javax.ws.rs.core.Response.Status; +import org.eclipse.osee.ats.api.agile.IAgileBacklog; +import org.eclipse.osee.ats.api.agile.IAgileFeatureGroup; +import org.eclipse.osee.ats.api.agile.IAgileSprint; +import org.eclipse.osee.ats.api.agile.IAgileTeam; +import org.eclipse.osee.ats.api.agile.JaxAgileFeatureGroup; +import org.eclipse.osee.ats.api.agile.JaxAgileTeam; +import org.eclipse.osee.ats.api.agile.JaxNewAgileTeam; +import org.eclipse.osee.ats.api.data.AtsArtifactTypes; +import org.eclipse.osee.ats.api.data.AtsAttributeTypes; +import org.eclipse.osee.ats.api.data.AtsRelationTypes; +import org.eclipse.osee.ats.core.config.TeamDefinitions; +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.ats.rest.internal.agile.model.AgileBacklog; +import org.eclipse.osee.ats.rest.internal.agile.model.AgileFeatureGroup; +import org.eclipse.osee.ats.rest.internal.agile.model.AgileSprint; +import org.eclipse.osee.ats.rest.internal.agile.model.AgileTeam; +import org.eclipse.osee.ats.rest.internal.agile.util.AgileFolders; +import org.eclipse.osee.ats.rest.internal.util.AtsChangeSet; +import org.eclipse.osee.framework.core.enums.CoreRelationTypes; +import org.eclipse.osee.framework.jdk.core.type.OseeArgumentException; +import org.eclipse.osee.framework.jdk.core.util.GUID; +import org.eclipse.osee.framework.jdk.core.util.Strings; +import org.eclipse.osee.jaxrs.OseeWebApplicationException; +import org.eclipse.osee.logger.Log; +import org.eclipse.osee.orcs.data.ArtifactReadable; +import org.eclipse.osee.orcs.transaction.TransactionBuilder; + +/** + * @author Donald G. Dunne + */ +public class AgileFactory { + + private AgileFactory() { + // Utilitiy class + } + + public static IAgileTeam createAgileTeam(Log logger, IAtsServer atsServer, JaxNewAgileTeam newTeam) { + ArtifactReadable userArt = atsServer.getArtifact(atsServer.getUserService().getCurrentUser()); + + ArtifactReadable agileTeamArt = atsServer.getArtifact(newTeam.getUuid()); + if (agileTeamArt == null) { + + TransactionBuilder transaction = + atsServer.getOrcsApi().getTransactionFactory().createTransaction(AtsUtilCore.getAtsBranch(), userArt, + "Create new Agile Team"); + + agileTeamArt = + (ArtifactReadable) transaction.createArtifact(AtsArtifactTypes.AgileTeam, newTeam.getName(), GUID.create(), + newTeam.getUuid()); + transaction.setSoleAttributeValue(agileTeamArt, AtsAttributeTypes.Active, true); + ArtifactReadable topAgileFolder = AgileFolders.getOrCreateTopAgileFolder(atsServer, transaction, userArt); + if (!topAgileFolder.equals(agileTeamArt.getParent())) { + transaction.unrelateFromAll(CoreRelationTypes.Default_Hierarchical__Parent, agileTeamArt); + transaction.addChildren(topAgileFolder, agileTeamArt); + } + + Set<ArtifactReadable> atsTeamArts = new HashSet<>(); + transaction.setRelations(agileTeamArt, AtsRelationTypes.AgileTeamToAtsTeam_AtsTeam, atsTeamArts); + + transaction.commit(); + } + return getAgileTeam(logger, atsServer, agileTeamArt); + } + + public static IAgileTeam updateAgileTeam(Log logger, IAtsServer atsServer, JaxAgileTeam team) { + ArtifactReadable userArt = atsServer.getArtifact(atsServer.getUserService().getCurrentUser()); + + TransactionBuilder transaction = + atsServer.getOrcsApi().getTransactionFactory().createTransaction(AtsUtilCore.getAtsBranch(), userArt, + "Update new Agile Team"); + + ArtifactReadable agileTeamArt = atsServer.getArtifact(team.getUuid()); + if (agileTeamArt == null) { + throw new OseeWebApplicationException(Status.NOT_FOUND, "Agile Team not found with Uuid [%d]", team.getUuid()); + } + if (Strings.isValid(team.getName()) && !team.getName().equals(agileTeamArt.getName())) { + transaction.setName(agileTeamArt, team.getName()); + } + if (Strings.isValid(team.getDescription()) && !team.getDescription().equals( + agileTeamArt.getSoleAttributeValue(AtsAttributeTypes.Description, ""))) { + transaction.setSoleAttributeValue(agileTeamArt, AtsAttributeTypes.Description, team.getDescription()); + } + transaction.setSoleAttributeValue(agileTeamArt, AtsAttributeTypes.Active, team.isActive()); + ArtifactReadable topAgileFolder = AgileFolders.getOrCreateTopAgileFolder(atsServer, transaction, userArt); + if (!topAgileFolder.equals(agileTeamArt.getParent())) { + transaction.unrelateFromAll(CoreRelationTypes.Default_Hierarchical__Parent, agileTeamArt); + transaction.addChildren(topAgileFolder, agileTeamArt); + } + + Set<ArtifactReadable> atsTeamArts = new HashSet<>(); + for (long atsTeamUuid : team.getAtsTeamUuids()) { + ArtifactReadable atsTeamArt = atsServer.getArtifact(atsTeamUuid); + if (atsTeamArt != null && atsTeamArt.isOfType(AtsArtifactTypes.TeamDefinition)) { + atsTeamArts.add(atsTeamArt); + } else { + throw new OseeArgumentException("UUID %d is not a valid Ats Team Definition", atsTeamUuid); + } + } + transaction.setRelations(agileTeamArt, AtsRelationTypes.AgileTeamToAtsTeam_AtsTeam, atsTeamArts); + + transaction.commit(); + return getAgileTeam(logger, atsServer, agileTeamArt); + } + + public static IAgileTeam getAgileTeam(Log logger, IAtsServer atsServer, Object artifact) { + return new AgileTeam(logger, atsServer, (ArtifactReadable) artifact); + } + + public static IAgileFeatureGroup createAgileFeatureGroup(Log logger, IAtsServer atsServer, long teamUuid, String name, String guid, Long uuid) { + JaxAgileFeatureGroup feature = new JaxAgileFeatureGroup(); + feature.setName(name); + feature.setUuid(uuid); + feature.setTeamUuid(teamUuid); + feature.setActive(true); + return createAgileFeatureGroup(logger, atsServer, feature); + } + + public static IAgileFeatureGroup createAgileFeatureGroup(Log logger, IAtsServer atsServer, JaxAgileFeatureGroup newFeatureGroup) { + ArtifactReadable userArt = atsServer.getArtifact(atsServer.getUserService().getCurrentUser()); + TransactionBuilder transaction = + atsServer.getOrcsApi().getTransactionFactory().createTransaction(AtsUtilCore.getAtsBranch(), userArt, + "Create new Agile Feature Group"); + ArtifactReadable featureGroupArt = + (ArtifactReadable) transaction.createArtifact(AtsArtifactTypes.AgileFeatureGroup, newFeatureGroup.getName(), + GUID.create(), newFeatureGroup.getUuid()); + transaction.setSoleAttributeValue(featureGroupArt, AtsAttributeTypes.Active, newFeatureGroup.isActive()); + + ArtifactReadable featureGroupFolder = + AgileFolders.getOrCreateTopFeatureGroupFolder(atsServer, transaction, newFeatureGroup.getTeamUuid(), userArt); + transaction.addChildren(featureGroupFolder, featureGroupArt); + + ArtifactReadable team = AgileFolders.getTeamFolder(atsServer, newFeatureGroup.getTeamUuid()); + transaction.relate(team, AtsRelationTypes.AgileTeamToFeatureGroup_FeatureGroup, featureGroupArt); + + transaction.commit(); + return getAgileFeatureGroup(logger, atsServer, featureGroupArt); + } + + public static IAgileFeatureGroup getAgileFeatureGroup(Log logger, IAtsServer atsServer, Object artifact) { + return new AgileFeatureGroup(logger, atsServer, (ArtifactReadable) artifact); + } + + public static IAgileSprint createAgileSprint(Log logger, IAtsServer atsServer, long teamUuid, String name, String guid, Long uuid) { + + AtsChangeSet changes = + (AtsChangeSet) atsServer.getStoreService().createAtsChangeSet("Create new Agile Sprint", + AtsCoreUsers.SYSTEM_USER); + + ArtifactReadable sprintArt = + (ArtifactReadable) changes.createArtifact(AtsArtifactTypes.AgileSprint, name, guid, uuid); + IAgileSprint sprint = atsServer.getWorkItemFactory().getAgileSprint(sprintArt); + + atsServer.getUtilService().setAtsId(atsServer.getSequenceProvider(), sprint, + TeamDefinitions.getTopTeamDefinition(atsServer.getConfig()), changes); + + // Initialize state machine + atsServer.getActionFactory().initializeNewStateMachine(sprint, Arrays.asList(AtsCoreUsers.UNASSIGNED_USER), + new Date(), atsServer.getUserService().getCurrentUser(), changes); + + changes.add(sprintArt); + + ArtifactReadable teamFolder = AgileFolders.getTeamFolder(atsServer, teamUuid); + ArtifactReadable agileSprintFolderArt = AgileFolders.getOrCreateTopSprintFolder(atsServer, teamUuid, changes); + changes.relate(agileSprintFolderArt, CoreRelationTypes.Default_Hierarchical__Child, sprintArt); + changes.relate(teamFolder, AtsRelationTypes.AgileTeamToSprint_Sprint, sprintArt); + + changes.execute(); + return getAgileSprint(logger, atsServer, sprintArt); + } + + public static IAgileSprint getAgileSprint(Log logger, IAtsServer atsServer, Object artifact) { + return new AgileSprint(logger, atsServer, (ArtifactReadable) artifact); + } + + public static IAgileBacklog createAgileBacklog(Log logger, IAtsServer atsServer, long teamUuid, String name, String guid, Long uuid) { + + AtsChangeSet changes = + (AtsChangeSet) atsServer.getStoreService().createAtsChangeSet("Create new Agile Backlog", + AtsCoreUsers.SYSTEM_USER); + + ArtifactReadable backlogArt = (ArtifactReadable) changes.createArtifact(AtsArtifactTypes.Goal, name, guid, uuid); + IAgileBacklog sprint = atsServer.getWorkItemFactory().getAgileBacklog(backlogArt); + + atsServer.getUtilService().setAtsId(atsServer.getSequenceProvider(), sprint, + TeamDefinitions.getTopTeamDefinition(atsServer.getConfig()), changes); + + // Initialize state machine + atsServer.getActionFactory().initializeNewStateMachine(sprint, Arrays.asList(AtsCoreUsers.UNASSIGNED_USER), + new Date(), atsServer.getUserService().getCurrentUser(), changes); + + changes.add(backlogArt); + + ArtifactReadable teamFolder = AgileFolders.getTeamFolder(atsServer, teamUuid); + changes.relate(teamFolder, AtsRelationTypes.AgileTeamToBacklog_Backlog, backlogArt); + changes.relate(teamFolder, CoreRelationTypes.Default_Hierarchical__Child, backlogArt); + + changes.execute(); + return getAgileBacklog(logger, atsServer, backlogArt); + } + + public static IAgileBacklog getAgileBacklog(Log logger, IAtsServer atsServer, Object artifact) { + return new AgileBacklog(logger, atsServer, (ArtifactReadable) artifact); + } + +} diff --git a/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/agile/AgileService.java b/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/agile/AgileService.java new file mode 100644 index 00000000000..88db7b54e27 --- /dev/null +++ b/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/agile/AgileService.java @@ -0,0 +1,352 @@ +/******************************************************************************* + * Copyright (c) 2015 Boeing. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.ats.rest.internal.agile; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.Iterator; +import java.util.LinkedList; +import java.util.List; +import org.eclipse.osee.ats.api.agile.IAgileBacklog; +import org.eclipse.osee.ats.api.agile.IAgileFeatureGroup; +import org.eclipse.osee.ats.api.agile.IAgileItem; +import org.eclipse.osee.ats.api.agile.IAgileService; +import org.eclipse.osee.ats.api.agile.IAgileSprint; +import org.eclipse.osee.ats.api.agile.IAgileTeam; +import org.eclipse.osee.ats.api.agile.JaxAgileBacklog; +import org.eclipse.osee.ats.api.agile.JaxAgileFeatureGroup; +import org.eclipse.osee.ats.api.agile.JaxAgileItem; +import org.eclipse.osee.ats.api.agile.JaxAgileTeam; +import org.eclipse.osee.ats.api.agile.JaxNewAgileTeam; +import org.eclipse.osee.ats.api.data.AtsArtifactTypes; +import org.eclipse.osee.ats.api.data.AtsAttributeTypes; +import org.eclipse.osee.ats.api.data.AtsRelationTypes; +import org.eclipse.osee.ats.core.util.AtsUtilCore; +import org.eclipse.osee.ats.rest.IAtsServer; +import org.eclipse.osee.ats.rest.internal.agile.model.AgileBacklog; +import org.eclipse.osee.ats.rest.internal.agile.util.AgileBacklogWriter; +import org.eclipse.osee.ats.rest.internal.agile.util.AgileFolders; +import org.eclipse.osee.ats.rest.internal.agile.util.AgileItemWriter; +import org.eclipse.osee.framework.core.data.ArtifactId; +import org.eclipse.osee.framework.core.data.IAttributeType; +import org.eclipse.osee.framework.core.enums.CoreBranches; +import org.eclipse.osee.framework.jdk.core.type.OseeArgumentException; +import org.eclipse.osee.framework.jdk.core.type.OseeCoreException; +import org.eclipse.osee.framework.jdk.core.type.OseeStateException; +import org.eclipse.osee.framework.jdk.core.type.ResultSet; +import org.eclipse.osee.framework.jdk.core.util.Strings; +import org.eclipse.osee.logger.Log; +import org.eclipse.osee.orcs.data.ArtifactReadable; +import org.eclipse.osee.orcs.transaction.TransactionBuilder; + +/** + * @author Donald G. Dunne + */ +public class AgileService implements IAgileService { + + private final Log logger; + private final IAtsServer atsServer; + + public AgileService(Log logger, IAtsServer atsServer) { + this.logger = logger; + this.atsServer = atsServer; + } + + /******************************** + ** Agile Team + ***********************************/ + @Override + public IAgileTeam getAgileTeam(ArtifactId artifact) { + return AgileFactory.getAgileTeam(logger, atsServer, artifact); + } + + @Override + public IAgileTeam getAgileTeam(long uuid) { + IAgileTeam team = null; + ArtifactReadable teamArt = atsServer.getArtifact(uuid); + if (teamArt != null) { + team = getAgileTeam(teamArt); + } + return team; + } + + @Override + public IAgileTeam getAgileTeamById(long teamUuid) { + IAgileTeam team = null; + ArtifactReadable artifact = getArtifact(teamUuid); + if (artifact != null) { + team = getAgileTeam(artifact); + } + return team; + } + + @Override + public IAgileTeam createAgileTeam(JaxNewAgileTeam newTeam) { + return AgileFactory.createAgileTeam(logger, atsServer, newTeam); + } + + @Override + public IAgileTeam updateAgileTeam(JaxAgileTeam team) { + return AgileFactory.updateAgileTeam(logger, atsServer, team); + } + + @Override + public void deleteAgileTeam(long uuid) { + ArtifactReadable team = atsServer.getArtifact(uuid); + if (!team.isOfType(AtsArtifactTypes.AgileTeam)) { + throw new OseeArgumentException("UUID %d is not a valid Agile Team", uuid); + } + TransactionBuilder transaction = atsServer.getOrcsApi().getTransactionFactory().createTransaction( + AtsUtilCore.getAtsBranch(), team, "Delete Agile Team"); + deleteRecurse(transaction, team.getChildren()); + transaction.deleteArtifact(team); + transaction.commit(); + } + + private void deleteRecurse(TransactionBuilder transaction, ResultSet<ArtifactReadable> resultSet) { + Iterator<ArtifactReadable> iterator = resultSet.iterator(); + while (iterator.hasNext()) { + ArtifactReadable art = iterator.next(); + deleteRecurse(transaction, art.getChildren()); + transaction.deleteArtifact(art); + } + } + + @Override + public Collection<IAgileTeam> getTeams() { + List<IAgileTeam> teams = new ArrayList<>(); + for (ArtifactReadable teamArt : atsServer.getQuery().andTypeEquals(AtsArtifactTypes.AgileTeam).getResults()) { + teams.add(getAgileTeam(teamArt)); + } + return teams; + } + + @Override + public IAttributeType getAgileTeamPointsAttributeType(IAgileTeam team) { + IAttributeType type = AtsAttributeTypes.Points; + String attrTypeName = + atsServer.getAttributeResolver().getSoleAttributeValue(team, AtsAttributeTypes.PointsAttributeType, null); + if (Strings.isValid(attrTypeName)) { + type = getTypeFromName(attrTypeName); + } + return type; + } + + private IAttributeType getTypeFromName(String attrTypeName) { + IAttributeType type = null; + for (IAttributeType attrType : atsServer.getOrcsApi().getOrcsTypes().getAttributeTypes().getAll()) { + if (attrType.getName().equals(attrTypeName)) { + type = attrType; + break; + } + } + if (type == null) { + throw new OseeCoreException("Invalid attribute type name provided: %s", attrTypeName); + } + return type; + } + + /******************************** + ** Agile Feature Group + ***********************************/ + @Override + public IAgileFeatureGroup getAgileFeatureGroup(ArtifactId artifact) { + return AgileFactory.getAgileFeatureGroup(logger, atsServer, artifact); + } + + @Override + public void deleteAgileFeatureGroup(long uuid) { + ArtifactReadable featureGroup = atsServer.getArtifact(uuid); + if (!featureGroup.isOfType(AtsArtifactTypes.AgileFeatureGroup)) { + throw new OseeArgumentException("UUID %d is not a valid Agile Feature Group", uuid); + } + TransactionBuilder transaction = atsServer.getOrcsApi().getTransactionFactory().createTransaction( + AtsUtilCore.getAtsBranch(), featureGroup, "Delete Agile Feature Group"); + transaction.deleteArtifact(featureGroup); + transaction.commit(); + } + + @Override + public IAgileFeatureGroup createAgileFeatureGroup(long teamUuid, String name, String guid, Long uuid) { + return AgileFactory.createAgileFeatureGroup(logger, atsServer, teamUuid, name, guid, uuid); + } + + @Override + public IAgileFeatureGroup createAgileFeatureGroup(JaxAgileFeatureGroup newFeatureGroup) { + return AgileFactory.createAgileFeatureGroup(logger, atsServer, newFeatureGroup); + } + + @Override + public Collection<IAgileFeatureGroup> getAgileFeatureGroups(IAgileTeam team) { + List<IAgileFeatureGroup> groups = new LinkedList<>(); + ArtifactReadable artifact = (ArtifactReadable) team.getStoreObject(); + for (ArtifactReadable groupArt : artifact.getRelated(AtsRelationTypes.AgileTeamToFeatureGroup_FeatureGroup)) { + groups.add(atsServer.getConfigItemFactory().getAgileFeatureGroup(groupArt)); + } + return groups; + } + + @Override + public IAgileBacklog getBacklogForTeam(long teamUuid) { + IAgileBacklog backlog = null; + ArtifactReadable teamArt = + atsServer.getQuery().andUuid(Long.valueOf(teamUuid).intValue()).getResults().getAtMostOneOrNull(); + ArtifactReadable backlogArt = + teamArt.getRelated(AtsRelationTypes.AgileTeamToBacklog_Backlog).getAtMostOneOrNull(); + if (backlogArt != null) { + backlog = getAgileBacklog(backlogArt); + } + return backlog; + } + + /******************************** + ** Agile Sprint + ***********************************/ + @Override + public IAgileSprint getAgileSprint(ArtifactId artifact) { + return AgileFactory.getAgileSprint(logger, atsServer, artifact); + } + + @Override + public IAgileSprint createAgileSprint(long teamUuid, String name, String guid, Long uuid) { + return AgileFactory.createAgileSprint(logger, atsServer, teamUuid, name, guid, uuid); + } + + private ArtifactReadable getArtifact(long teamUuid) { + return atsServer.getOrcsApi().getQueryFactory().fromBranch(CoreBranches.COMMON).andUuid( + new Long(teamUuid).intValue()).getResults().getAtMostOneOrNull(); + } + + @Override + public Collection<IAgileSprint> getSprintsForTeam(long teamUuid) { + List<IAgileSprint> sprints = new ArrayList<>(); + ArtifactReadable team = getArtifact(teamUuid); + for (ArtifactReadable sprintArt : team.getRelated(AtsRelationTypes.AgileTeamToSprint_Sprint)) { + sprints.add(getAgileSprint(sprintArt)); + } + return sprints; + } + + @Override + public Collection<IAgileSprint> getAgileSprints(IAgileTeam team) { + List<IAgileSprint> sprints = new LinkedList<>(); + ArtifactReadable artifact = (ArtifactReadable) team.getStoreObject(); + for (ArtifactReadable groupArt : artifact.getRelated(AtsRelationTypes.AgileTeamToSprint_Sprint)) { + sprints.add(atsServer.getWorkItemFactory().getAgileSprint(groupArt)); + } + return sprints; + } + + /******************************** + ** Agile Backlog + ***********************************/ + @Override + public IAgileBacklog getAgileBacklog(ArtifactId artifact) { + return AgileFactory.getAgileBacklog(logger, atsServer, artifact); + } + + @Override + public IAgileBacklog getAgileBacklog(IAgileTeam team) { + ArtifactReadable teamFolder = AgileFolders.getTeamFolder(atsServer, team.getUuid()); + if (teamFolder == null) { + return null; + } + ArtifactReadable backlogArt = teamFolder.getRelated(AtsRelationTypes.AgileTeamToBacklog_Backlog).getOneOrNull(); + if (backlogArt == null) { + return null; + } + return new AgileBacklog(logger, atsServer, backlogArt); + } + + @Override + public IAgileBacklog getAgileBacklog(long uuid) { + IAgileBacklog backlog = null; + ArtifactReadable teamArt = atsServer.getArtifact(uuid); + if (teamArt != null) { + backlog = getAgileBacklog(teamArt); + } + return backlog; + } + + @Override + public IAgileBacklog createAgileBacklog(long teamUuid, String name, String guid, Long uuid) { + return AgileFactory.createAgileBacklog(logger, atsServer, teamUuid, name, guid, uuid); + } + + @Override + public IAgileBacklog updateAgileBacklog(JaxAgileBacklog updatedBacklog) { + AgileBacklogWriter writer = new AgileBacklogWriter(atsServer, this, updatedBacklog); + return writer.write(); + } + + @Override + public JaxAgileItem updateItem(JaxAgileItem newItem) { + AgileItemWriter writer = new AgileItemWriter(atsServer, this, newItem); + return writer.write(); + } + + @Override + public Collection<IAgileFeatureGroup> getAgileFeatureGroups(List<Long> uuids) { + List<IAgileFeatureGroup> features = new LinkedList<>(); + for (ArtifactReadable featureArt : atsServer.getArtifacts(uuids)) { + features.add(atsServer.getConfigItemFactory().getAgileFeatureGroup(featureArt)); + } + return features; + } + + @Override + public Collection<IAgileItem> getItems(IAgileBacklog backlog) { + List<IAgileItem> items = new LinkedList<>(); + ArtifactReadable backlogArt = (ArtifactReadable) backlog.getStoreObject(); + for (ArtifactReadable art : backlogArt.getRelated(AtsRelationTypes.Goal_Member)) { + if (art.isOfType(AtsArtifactTypes.AbstractWorkflowArtifact)) { + items.add(atsServer.getWorkItemFactory().getAgileItem(art)); + } else { + throw new OseeStateException("Inavlid artifact [%s] in backlog. Only workflows are allowed, not [%s]", + AtsUtilCore.toStringWithId(art), art.getArtifactType().getName()); + } + } + return items; + } + + @Override + public Collection<IAgileFeatureGroup> getFeatureGroups(IAgileItem aItem) { + List<IAgileFeatureGroup> groups = new LinkedList<>(); + ArtifactReadable itemArt = atsServer.getArtifact(aItem); + for (ArtifactReadable featureGroup : itemArt.getRelated(AtsRelationTypes.AgileFeatureToItem_FeatureGroup)) { + groups.add(atsServer.getAgileService().getAgileFeatureGroup(featureGroup)); + } + return groups; + } + + @Override + public IAgileSprint getSprint(IAgileItem item) { + IAgileSprint sprint = null; + ArtifactReadable itemArt = atsServer.getArtifact(item); + ArtifactReadable sprintArt = itemArt.getRelated(AtsRelationTypes.AgileSprintToItem_Sprint).getAtMostOneOrNull(); + if (sprintArt != null) { + sprint = atsServer.getWorkItemFactory().getAgileSprint(sprintArt); + } + return sprint; + } + + @Override + public void deleteSprint(long sprintUuid) { + ArtifactReadable sprint = atsServer.getArtifact(sprintUuid); + if (sprint != null) { + TransactionBuilder transaction = atsServer.getOrcsApi().getTransactionFactory().createTransaction( + AtsUtilCore.getAtsBranch(), sprint, "Delete Agile Sprint"); + transaction.deleteArtifact(sprint); + transaction.commit(); + } + } + +} diff --git a/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/agile/SprintPageBuilder.java b/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/agile/SprintPageBuilder.java index 771ec38d43e..50ca855660f 100644 --- a/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/agile/SprintPageBuilder.java +++ b/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/agile/SprintPageBuilder.java @@ -17,7 +17,7 @@ import java.util.Map.Entry; import java.util.TreeMap; import org.eclipse.osee.ats.api.data.AtsAttributeTypes; import org.eclipse.osee.ats.api.data.AtsRelationTypes; -import org.eclipse.osee.ats.impl.IAtsServer; +import org.eclipse.osee.ats.rest.IAtsServer; import org.eclipse.osee.framework.jdk.core.type.OseeCoreException; import org.eclipse.osee.framework.jdk.core.type.ResourceToken; import org.eclipse.osee.framework.jdk.core.type.ResultSet; diff --git a/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/agile/model/AgileBacklog.java b/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/agile/model/AgileBacklog.java new file mode 100644 index 00000000000..a626bb9f19b --- /dev/null +++ b/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/agile/model/AgileBacklog.java @@ -0,0 +1,49 @@ +/******************************************************************************* + * Copyright (c) 2015 Boeing. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.ats.rest.internal.agile.model; + +import org.eclipse.osee.ats.api.agile.IAgileBacklog; +import org.eclipse.osee.ats.api.data.AtsRelationTypes; +import org.eclipse.osee.ats.rest.IAtsServer; +import org.eclipse.osee.ats.rest.internal.workitem.model.WorkItem; +import org.eclipse.osee.framework.core.exception.ArtifactDoesNotExist; +import org.eclipse.osee.logger.Log; +import org.eclipse.osee.orcs.data.ArtifactReadable; + +/** + * @author Donald G Dunne + */ +public class AgileBacklog extends WorkItem implements IAgileBacklog { + + public AgileBacklog(Log logger, IAtsServer atsServer, ArtifactReadable artifact) { + super(logger, atsServer, artifact); + } + + @Override + public boolean isActive() { + return getStateMgr().getStateType().isInWork(); + } + + @Override + public long getTeamUuid() { + long result = 0; + try { + ArtifactReadable agileTeam = artifact.getRelated(AtsRelationTypes.AgileTeamToBacklog_AgileTeam).getOneOrNull(); + if (agileTeam != null) { + result = agileTeam.getUuid(); + } + } catch (ArtifactDoesNotExist ex) { + // do nothing + } + return result; + } + +} diff --git a/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/agile/model/AgileFeatureGroup.java b/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/agile/model/AgileFeatureGroup.java new file mode 100644 index 00000000000..2cfe82accc6 --- /dev/null +++ b/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/agile/model/AgileFeatureGroup.java @@ -0,0 +1,50 @@ +/******************************************************************************* + * Copyright (c) 2015 Boeing. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.ats.rest.internal.agile.model; + +import org.eclipse.osee.ats.api.agile.IAgileFeatureGroup; +import org.eclipse.osee.ats.api.data.AtsRelationTypes; +import org.eclipse.osee.ats.core.model.impl.AtsConfigObject; +import org.eclipse.osee.ats.rest.IAtsServer; +import org.eclipse.osee.framework.core.exception.ArtifactDoesNotExist; +import org.eclipse.osee.logger.Log; +import org.eclipse.osee.orcs.data.ArtifactReadable; + +/** + * @author Donald G Dunne + */ +public class AgileFeatureGroup extends AtsConfigObject implements IAgileFeatureGroup { + + public AgileFeatureGroup(Log logger, IAtsServer atsServer, ArtifactReadable artifact) { + super(logger, atsServer, artifact); + } + + @Override + public String getTypeName() { + return "Agile Feature Group"; + } + + @Override + public long getTeamUuid() { + long result = 0; + try { + ArtifactReadable agileTeam = + ((ArtifactReadable) artifact).getRelated(AtsRelationTypes.AgileTeamToFeatureGroup_AgileTeam).getOneOrNull(); + if (agileTeam != null) { + result = agileTeam.getUuid(); + } + } catch (ArtifactDoesNotExist ex) { + // do nothing + } + return result; + } + +} diff --git a/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/agile/model/AgileItem.java b/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/agile/model/AgileItem.java new file mode 100644 index 00000000000..77e587a579c --- /dev/null +++ b/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/agile/model/AgileItem.java @@ -0,0 +1,33 @@ +/******************************************************************************* + * Copyright (c) 2015 Boeing. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.ats.rest.internal.agile.model; + +import org.eclipse.osee.ats.api.agile.IAgileItem; +import org.eclipse.osee.ats.rest.IAtsServer; +import org.eclipse.osee.ats.rest.internal.workitem.model.WorkItem; +import org.eclipse.osee.logger.Log; +import org.eclipse.osee.orcs.data.ArtifactReadable; + +/** + * @author Donald G Dunne + */ +public class AgileItem extends WorkItem implements IAgileItem { + + public AgileItem(Log logger, IAtsServer atsServer, ArtifactReadable artifact) { + super(logger, atsServer, artifact); + } + + @Override + public long getTeamUuid() { + return 0; + } + +} diff --git a/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/agile/model/AgileSprint.java b/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/agile/model/AgileSprint.java new file mode 100644 index 00000000000..75a720a706b --- /dev/null +++ b/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/agile/model/AgileSprint.java @@ -0,0 +1,49 @@ +/******************************************************************************* + * Copyright (c) 2015 Boeing. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.ats.rest.internal.agile.model; + +import org.eclipse.osee.ats.api.agile.IAgileSprint; +import org.eclipse.osee.ats.api.data.AtsRelationTypes; +import org.eclipse.osee.ats.rest.IAtsServer; +import org.eclipse.osee.ats.rest.internal.workitem.model.WorkItem; +import org.eclipse.osee.framework.core.exception.ArtifactDoesNotExist; +import org.eclipse.osee.logger.Log; +import org.eclipse.osee.orcs.data.ArtifactReadable; + +/** + * @author Donald G Dunne + */ +public class AgileSprint extends WorkItem implements IAgileSprint { + + public AgileSprint(Log logger, IAtsServer atsServer, ArtifactReadable artifact) { + super(logger, atsServer, artifact); + } + + @Override + public boolean isActive() { + return getStateMgr().getStateType().isInWork(); + } + + @Override + public long getTeamUuid() { + long result = 0; + try { + ArtifactReadable agileTeam = artifact.getRelated(AtsRelationTypes.AgileTeamToSprint_AgileTeam).getOneOrNull(); + if (agileTeam != null) { + result = agileTeam.getUuid(); + } + } catch (ArtifactDoesNotExist ex) { + // do nothing + } + return result; + } + +} diff --git a/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/agile/model/AgileTeam.java b/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/agile/model/AgileTeam.java new file mode 100644 index 00000000000..5778d967c34 --- /dev/null +++ b/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/agile/model/AgileTeam.java @@ -0,0 +1,70 @@ +/******************************************************************************* + * Copyright (c) 2015 Boeing. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.ats.rest.internal.agile.model; + +import java.util.ArrayList; +import java.util.List; +import org.eclipse.osee.ats.api.agile.IAgileTeam; +import org.eclipse.osee.ats.api.data.AtsAttributeTypes; +import org.eclipse.osee.ats.api.data.AtsRelationTypes; +import org.eclipse.osee.ats.core.model.impl.AtsConfigObject; +import org.eclipse.osee.ats.rest.IAtsServer; +import org.eclipse.osee.logger.Log; +import org.eclipse.osee.orcs.data.ArtifactReadable; + +/** + * @author Donald G Dunne + */ +public class AgileTeam extends AtsConfigObject implements IAgileTeam { + + public AgileTeam(Log logger, IAtsServer atsServer, ArtifactReadable artifact) { + super(logger, atsServer, artifact); + } + + private ArtifactReadable getArtifact() { + return (ArtifactReadable) artifact; + } + + @Override + public String getTypeName() { + return "Agile Team"; + } + + @Override + public List<Long> getAtsTeamUuids() { + List<Long> uuids = new ArrayList<>(); + for (ArtifactReadable atsTeam : getArtifact().getRelated(AtsRelationTypes.AgileTeamToAtsTeam_AtsTeam)) { + uuids.add(new Long(atsTeam.getUuid())); + } + return uuids; + } + + @Override + public String getDescription() { + return getArtifact().getSoleAttributeValue(AtsAttributeTypes.Description, ""); + } + + @Override + public long getBacklogUuid() { + long backlogUuid = -1; + try { + ArtifactReadable backlogArt = + getArtifact().getRelated(AtsRelationTypes.AgileTeamToBacklog_Backlog).getAtMostOneOrNull(); + if (backlogArt != null) { + backlogUuid = backlogArt.getUuid(); + } + } catch (Exception ex) { + // do nothing + } + return backlogUuid; + } + +} diff --git a/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/agile/util/AgileBacklogWriter.java b/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/agile/util/AgileBacklogWriter.java new file mode 100644 index 00000000000..8c3743c9bbe --- /dev/null +++ b/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/agile/util/AgileBacklogWriter.java @@ -0,0 +1,93 @@ +/******************************************************************************* + * Copyright (c) 2015 Boeing. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.ats.rest.internal.agile.util; + +import org.eclipse.osee.ats.api.agile.AgileUtil; +import org.eclipse.osee.ats.api.agile.IAgileBacklog; +import org.eclipse.osee.ats.api.agile.IAgileService; +import org.eclipse.osee.ats.api.agile.IAgileTeam; +import org.eclipse.osee.ats.api.agile.JaxAgileBacklog; +import org.eclipse.osee.ats.api.data.AtsArtifactTypes; +import org.eclipse.osee.ats.api.data.AtsRelationTypes; +import org.eclipse.osee.ats.core.users.AtsCoreUsers; +import org.eclipse.osee.ats.rest.IAtsServer; +import org.eclipse.osee.ats.rest.internal.util.AtsChangeSet; +import org.eclipse.osee.framework.core.enums.CoreRelationTypes; +import org.eclipse.osee.framework.jdk.core.type.OseeArgumentException; +import org.eclipse.osee.orcs.data.ArtifactReadable; + +/** + * @author Donald G. Dunne + */ +public class AgileBacklogWriter { + + private final IAtsServer atsServer; + private final IAgileService agileService; + private final JaxAgileBacklog updatedBacklog; + + public AgileBacklogWriter(IAtsServer atsServer, IAgileService agileService, JaxAgileBacklog updatedBacklog) { + this.atsServer = atsServer; + this.agileService = agileService; + this.updatedBacklog = updatedBacklog; + } + + public IAgileBacklog write() { + AtsChangeSet changes = + (AtsChangeSet) atsServer.getStoreService().createAtsChangeSet("Update Agile Backlog", AtsCoreUsers.SYSTEM_USER); + + // Validate backlog exists + IAgileBacklog currentBacklog = agileService.getAgileBacklog(updatedBacklog.getUuid()); + if (currentBacklog == null) { + throw new OseeArgumentException("No Backlog found with UUID %d", updatedBacklog.getUuid()); + } + if (currentBacklog.getTeamUuid() != updatedBacklog.getTeamUuid()) { + + // If teamUuid is empty, unrelate form backlog + if (currentBacklog.getTeamUuid() == AgileUtil.EMPTY_VALUE) { + IAgileTeam team = agileService.getAgileTeam(currentBacklog.getTeamUuid()); + if (team != null) { + changes.unrelateAll(team, AtsRelationTypes.AgileTeamToBacklog_Backlog); + changes.add(team); + } + } + + // Else validate and relate new team + else { + ArtifactReadable updateBacklogArt = atsServer.getArtifact(updatedBacklog.getUuid()); + IAgileTeam updatedTeam = agileService.getAgileTeam(updatedBacklog.getTeamUuid()); + ArtifactReadable updatedTeamArt = (ArtifactReadable) updatedTeam.getStoreObject(); + if (!updateBacklogArt.isOfType(AtsArtifactTypes.Goal)) { + throw new OseeArgumentException("Backlog UUID %d not valid type", updatedBacklog.getUuid()); + } else if (updateBacklogArt.getRelatedCount(AtsRelationTypes.AgileTeamToBacklog_AgileTeam) > 0) { + ArtifactReadable currentTeamArt = + updateBacklogArt.getRelated(AtsRelationTypes.AgileTeamToBacklog_AgileTeam).getExactlyOne(); + if (!updatedTeamArt.equals(currentTeamArt)) { + changes.unrelate(currentTeamArt, AtsRelationTypes.AgileTeamToBacklog_Backlog, updatedBacklog); + changes.add(currentTeamArt); + } + } + changes.relate(updatedTeamArt, AtsRelationTypes.AgileTeamToBacklog_Backlog, updateBacklogArt); + if (!updatedTeamArt.areRelated(CoreRelationTypes.Default_Hierarchical__Child, updateBacklogArt)) { + if (updateBacklogArt.getParent() != null) { + changes.unrelate(updateBacklogArt.getParent(), CoreRelationTypes.Default_Hierarchical__Child, + updateBacklogArt); + } + changes.relate(updatedTeamArt, CoreRelationTypes.Default_Hierarchical__Child, updateBacklogArt); + } + changes.add(updatedTeamArt); + } + } + if (!changes.isEmpty()) { + changes.execute(); + } + return agileService.getAgileBacklog(updatedBacklog.getUuid()); + } +} diff --git a/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/agile/util/AgileFolders.java b/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/agile/util/AgileFolders.java new file mode 100644 index 00000000000..d1a51f782a7 --- /dev/null +++ b/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/agile/util/AgileFolders.java @@ -0,0 +1,81 @@ +/******************************************************************************* + * Copyright (c) 2015 Boeing. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.ats.rest.internal.agile.util; + +import org.eclipse.osee.ats.api.agile.AgileUtil; +import org.eclipse.osee.ats.api.data.AtsArtifactToken; +import org.eclipse.osee.ats.core.util.AtsUtilCore; +import org.eclipse.osee.ats.rest.IAtsServer; +import org.eclipse.osee.ats.rest.internal.util.AtsChangeSet; +import org.eclipse.osee.framework.core.data.ArtifactId; +import org.eclipse.osee.framework.core.enums.CoreArtifactTypes; +import org.eclipse.osee.framework.core.enums.CoreBranches; +import org.eclipse.osee.framework.core.enums.CoreRelationTypes; +import org.eclipse.osee.orcs.data.ArtifactReadable; +import org.eclipse.osee.orcs.transaction.TransactionBuilder; + +/** + * @author Donald G. Dunne + */ +public class AgileFolders { + + public static ArtifactReadable getOrCreateTopSprintFolder(IAtsServer atsServer, long teamUuid, AtsChangeSet changes) { + ArtifactReadable teamFolder = getTeamFolder(atsServer, teamUuid); + ArtifactReadable sprintFolder = null; + for (ArtifactReadable child : teamFolder.getChildren()) { + if (child.getName().equals(AgileUtil.SPRINT_FOLDER_NAME)) { + sprintFolder = child; + } + } + if (sprintFolder == null) { + sprintFolder = + (ArtifactReadable) changes.createArtifact(CoreArtifactTypes.Folder, AgileUtil.SPRINT_FOLDER_NAME); + changes.relate(teamFolder, CoreRelationTypes.Default_Hierarchical__Child, sprintFolder); + } + return sprintFolder; + } + + public static ArtifactReadable getTeamFolder(IAtsServer atsServer, long teamUuid) { + return atsServer.getOrcsApi().getQueryFactory().fromBranch(CoreBranches.COMMON).andUuid( + new Long(teamUuid).intValue()).getResults().getAtMostOneOrNull(); + } + + public static ArtifactReadable getOrCreateTopFeatureGroupFolder(IAtsServer atsServer, TransactionBuilder tx, long teamUuid, ArtifactReadable userArt) { + ArtifactReadable teamFolder = AgileFolders.getTeamFolder(atsServer, teamUuid); + ArtifactReadable featureGroupFolder = null; + for (ArtifactReadable child : teamFolder.getChildren()) { + if (child.getName().equals(AgileUtil.FEATURE_GROUP_FOLDER_NAME)) { + featureGroupFolder = child; + } + } + if (featureGroupFolder == null) { + featureGroupFolder = + (ArtifactReadable) tx.createArtifact(CoreArtifactTypes.Folder, AgileUtil.FEATURE_GROUP_FOLDER_NAME); + tx.addChildren(teamFolder, featureGroupFolder); + } + return featureGroupFolder; + } + + @SuppressWarnings("unchecked") + public static ArtifactReadable getOrCreateTopAgileFolder(IAtsServer atsServer, TransactionBuilder tx, ArtifactReadable userArt) { + ArtifactId agileFolder = + atsServer.getOrcsApi().getQueryFactory().fromBranch(CoreBranches.COMMON).andIds( + AtsArtifactToken.TopAgileFolder).getResults().getAtMostOneOrNull(); + if (agileFolder == null) { + agileFolder = tx.createArtifact(AtsArtifactToken.TopAgileFolder); + ArtifactReadable rootArtifact = + atsServer.getOrcsApi().getQueryFactory().fromBranch(AtsUtilCore.getAtsBranch()).andIsHeirarchicalRootArtifact().getResults().getExactlyOne(); + tx.addChildren(rootArtifact, agileFolder); + } + return (ArtifactReadable) agileFolder; + } + +} diff --git a/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/agile/util/AgileItemWriter.java b/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/agile/util/AgileItemWriter.java new file mode 100644 index 00000000000..212a8f9cc04 --- /dev/null +++ b/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/agile/util/AgileItemWriter.java @@ -0,0 +1,98 @@ +/******************************************************************************* + * Copyright (c) 2015 Boeing. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.ats.rest.internal.agile.util; + +import java.util.Collection; +import java.util.LinkedList; +import java.util.List; +import org.eclipse.osee.ats.api.agile.IAgileFeatureGroup; +import org.eclipse.osee.ats.api.agile.IAgileService; +import org.eclipse.osee.ats.api.agile.IAgileSprint; +import org.eclipse.osee.ats.api.agile.JaxAgileItem; +import org.eclipse.osee.ats.api.data.AtsRelationTypes; +import org.eclipse.osee.ats.core.users.AtsCoreUsers; +import org.eclipse.osee.ats.rest.IAtsServer; +import org.eclipse.osee.ats.rest.internal.util.AtsChangeSet; +import org.eclipse.osee.orcs.data.ArtifactReadable; + +/** + * @author Donald G. Dunne + */ +public class AgileItemWriter { + + private final IAtsServer atsServer; + private final JaxAgileItem newItem; + private final IAgileService agileService; + + public AgileItemWriter(IAtsServer atsServer, IAgileService agileService, JaxAgileItem newItem) { + this.atsServer = atsServer; + this.agileService = agileService; + this.newItem = newItem; + } + + public JaxAgileItem write() { + AtsChangeSet changes = + (AtsChangeSet) atsServer.getStoreService().createAtsChangeSet("Update new Agile Item", + AtsCoreUsers.SYSTEM_USER); + + if (newItem.isSetFeatures()) { + Collection<IAgileFeatureGroup> features = agileService.getAgileFeatureGroups(newItem.getFeatures()); + List<ArtifactReadable> featureArts = new LinkedList<>(); + for (IAgileFeatureGroup feature : features) { + featureArts.add((ArtifactReadable) feature.getStoreObject()); + } + for (ArtifactReadable awa : atsServer.getArtifacts(newItem.getUuids())) { + for (IAgileFeatureGroup feature : features) { + ArtifactReadable featureArt = (ArtifactReadable) feature.getStoreObject(); + if (!featureArt.areRelated(AtsRelationTypes.AgileFeatureToItem_FeatureGroup, awa)) { + changes.relate(feature, AtsRelationTypes.AgileFeatureToItem_AtsItem, awa); + } + } + for (ArtifactReadable featureArt : awa.getRelated(AtsRelationTypes.AgileFeatureToItem_FeatureGroup)) { + if (!featureArts.contains(featureArt)) { + changes.unrelate(featureArt, AtsRelationTypes.AgileFeatureToItem_AtsItem, awa); + } + } + } + } + + if (newItem.isSetSprint()) { + ArtifactReadable sprintArt = atsServer.getArtifact(newItem.getSprintUuid()); + IAgileSprint sprint = atsServer.getAgileService().getAgileSprint(sprintArt); + for (ArtifactReadable awa : atsServer.getArtifacts(newItem.getUuids())) { + if (sprint != null) { + changes.setRelation(sprint, AtsRelationTypes.AgileSprintToItem_AtsItem, awa); + } else { + changes.unrelateAll(awa, AtsRelationTypes.AgileSprintToItem_AtsItem); + } + changes.add(sprint); + } + } + + if (newItem.isSetBacklog()) { + ArtifactReadable backlogArt = atsServer.getArtifact(newItem.getBacklogUuid()); + IAgileSprint backlog = atsServer.getAgileService().getAgileSprint(backlogArt); + for (ArtifactReadable awa : atsServer.getArtifacts(newItem.getUuids())) { + if (backlog != null) { + changes.setRelation(backlog, AtsRelationTypes.Goal_Member, awa); + } else { + changes.unrelateAll(awa, AtsRelationTypes.Goal_Member); + } + changes.add(backlog); + } + } + + if (!changes.isEmpty()) { + changes.execute(); + } + return newItem; + } +} diff --git a/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/config/ActionableItemResource.java b/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/config/ActionableItemResource.java index 59dd29108d9..2f79bfa3150 100644 --- a/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/config/ActionableItemResource.java +++ b/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/config/ActionableItemResource.java @@ -12,8 +12,8 @@ package org.eclipse.osee.ats.rest.internal.config; import javax.ws.rs.Path; import org.eclipse.osee.ats.api.data.AtsArtifactTypes; -import org.eclipse.osee.ats.impl.IAtsServer; -import org.eclipse.osee.ats.impl.config.AbstractConfigResource; +import org.eclipse.osee.ats.rest.IAtsServer; +import org.eclipse.osee.ats.rest.util.AbstractConfigResource; /** * Donald G. Dunne 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 e7fe014ae95..ee8cd114837 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 @@ -33,7 +33,7 @@ import org.eclipse.osee.ats.api.user.IAtsUser; 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.impl.IAtsServer; +import org.eclipse.osee.ats.rest.IAtsServer; import org.eclipse.osee.framework.core.data.ArtifactId; import org.eclipse.osee.framework.core.data.IArtifactToken; import org.eclipse.osee.framework.core.data.TokenFactory; diff --git a/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/config/BaseConfigEndpointImpl.java b/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/config/BaseConfigEndpointImpl.java new file mode 100644 index 00000000000..2370a05e114 --- /dev/null +++ b/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/config/BaseConfigEndpointImpl.java @@ -0,0 +1,135 @@ +/******************************************************************************* + * Copyright (c) 2014 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 java.net.URI; +import java.util.List; +import javax.ws.rs.DELETE; +import javax.ws.rs.GET; +import javax.ws.rs.POST; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.core.Response; +import org.eclipse.osee.ats.api.IAtsObject; +import org.eclipse.osee.ats.api.config.BaseConfigEndpointApi; +import org.eclipse.osee.ats.api.config.JaxAtsObject; +import org.eclipse.osee.ats.api.data.AtsArtifactToken; +import org.eclipse.osee.ats.api.data.AtsAttributeTypes; +import org.eclipse.osee.ats.api.util.IAtsChangeSet; +import org.eclipse.osee.ats.core.users.AtsCoreUsers; +import org.eclipse.osee.ats.rest.IAtsServer; +import org.eclipse.osee.framework.core.data.ArtifactId; +import org.eclipse.osee.framework.core.data.IArtifactToken; +import org.eclipse.osee.framework.core.data.IArtifactType; +import org.eclipse.osee.framework.core.enums.CoreRelationTypes; +import org.eclipse.osee.framework.jdk.core.type.OseeStateException; +import org.eclipse.osee.framework.jdk.core.util.GUID; +import org.eclipse.osee.framework.jdk.core.util.Strings; +import org.eclipse.osee.orcs.data.ArtifactReadable; + +/** + * @author Donald G. Dunne + */ +public abstract class BaseConfigEndpointImpl<T extends JaxAtsObject> implements BaseConfigEndpointApi<T> { + + protected final IAtsServer atsServer; + protected final IArtifactType artifactType; + protected final IArtifactToken typeFolder; + + public BaseConfigEndpointImpl(IArtifactType artifactType, IArtifactToken typeFolder, IAtsServer atsServer) { + this.artifactType = artifactType; + this.typeFolder = typeFolder; + this.atsServer = atsServer; + } + + @Override + @GET + public List<T> get() throws Exception { + return getObjects(); + } + + @Override + @GET + @Path("{uuid}") + public T get(@PathParam("uuid") long uuid) throws Exception { + return getObject(uuid); + } + + @Override + @POST + public Response create(T jaxAtsObject) throws Exception { + if (jaxAtsObject.getUuid() <= 0L) { + throw new OseeStateException("Invalid uuid %d"); + } else if (!Strings.isValid(jaxAtsObject.getName())) { + throw new OseeStateException("Invalid name [%d]"); + } + ArtifactReadable artifact = atsServer.getArtifact(jaxAtsObject.getUuid()); + if (artifact != null) { + throw new OseeStateException("Artifact with uuid %d already exists", jaxAtsObject.getUuid()); + } + IAtsChangeSet changes = + atsServer.getStoreService().createAtsChangeSet("Create " + artifactType.getName(), AtsCoreUsers.SYSTEM_USER); + ArtifactId newArtifact = + changes.createArtifact(artifactType, jaxAtsObject.getName(), GUID.create(), jaxAtsObject.getUuid()); + IAtsObject newAtsObject = atsServer.getConfigItemFactory().getConfigObject(newArtifact); + if (typeFolder != null) { + ArtifactReadable typeFolderArtifact = atsServer.getArtifact(typeFolder); + if (typeFolderArtifact == null) { + typeFolderArtifact = (ArtifactReadable) changes.createArtifact(AtsArtifactToken.CountryFolder); + } + if (typeFolderArtifact.getParent() == null) { + ArtifactReadable headingFolder = atsServer.getArtifact(AtsArtifactToken.HeadingFolder); + changes.relate(headingFolder, CoreRelationTypes.Default_Hierarchical__Child, typeFolderArtifact); + } + changes.relate(typeFolderArtifact, CoreRelationTypes.Default_Hierarchical__Child, newArtifact); + } + if (Strings.isValid(jaxAtsObject.getDescription())) { + changes.setSoleAttributeValue(newAtsObject, AtsAttributeTypes.Description, jaxAtsObject.getDescription()); + } else { + changes.deleteAttributes(newAtsObject, AtsAttributeTypes.Description); + } + changes.setSoleAttributeValue(newAtsObject, AtsAttributeTypes.Active, jaxAtsObject.isActive()); + create(jaxAtsObject, newArtifact, changes); + changes.execute(); + return Response.created(new URI("/" + jaxAtsObject.getUuid())).build(); + } + + /** + * Implement by subclass to perform other checks and sets during artifact creation + */ + protected void create(T jaxAtsObject, ArtifactId newArtifact, IAtsChangeSet changes) { + // provided for subclass implementation + } + + @Override + @DELETE + public Response delete(@PathParam("uuid") long uuid) throws Exception { + ArtifactReadable artifact = atsServer.getArtifact(uuid); + if (artifact == null) { + throw new OseeStateException("Artifact with uuid %d not found", uuid); + } + IAtsChangeSet changes = + atsServer.getStoreService().createAtsChangeSet("Create " + artifactType.getName(), AtsCoreUsers.SYSTEM_USER); + changes.deleteArtifact(artifact); + changes.execute(); + return Response.ok().build(); + } + + public abstract T getConfigObject(ArtifactId artifact); + + protected T getObject(long uuid) { + ArtifactReadable configArt = atsServer.getQuery().andUuid(uuid).getResults().getExactlyOne(); + return getConfigObject(configArt); + } + + public abstract List<T> getObjects(); + +} diff --git a/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/config/ConfigJsonWriter.java b/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/config/ConfigJsonWriter.java index 5df1f7d1f34..e5f2a28ccfa 100644 --- a/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/config/ConfigJsonWriter.java +++ b/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/config/ConfigJsonWriter.java @@ -27,7 +27,7 @@ import org.eclipse.osee.ats.api.insertion.IAtsInsertionActivity; import org.eclipse.osee.ats.api.program.IAtsProgram; import org.eclipse.osee.ats.api.team.IAtsTeamDefinition; import org.eclipse.osee.ats.api.version.IAtsVersion; -import org.eclipse.osee.ats.impl.IAtsServer; +import org.eclipse.osee.ats.rest.IAtsServer; import org.eclipse.osee.framework.core.data.IAttributeType; import org.eclipse.osee.framework.jdk.core.type.ResultSet; import org.eclipse.osee.jaxrs.mvc.IdentityView; @@ -49,7 +49,7 @@ public class ConfigJsonWriter implements MessageBodyWriter<IAtsConfigObject> { } public void start() { - jsonFactory = org.eclipse.osee.ats.impl.config.JsonFactory.create(); + jsonFactory = org.eclipse.osee.ats.rest.util.JsonFactory.create(); } public void stop() { diff --git a/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/config/ConfigsJsonWriter.java b/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/config/ConfigsJsonWriter.java index edc2cfa6dca..db7a3558471 100644 --- a/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/config/ConfigsJsonWriter.java +++ b/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/config/ConfigsJsonWriter.java @@ -14,7 +14,7 @@ import javax.ws.rs.ext.Provider; import org.codehaus.jackson.JsonFactory; import org.codehaus.jackson.JsonGenerator; import org.eclipse.osee.ats.api.IAtsConfigObject; -import org.eclipse.osee.ats.impl.IAtsServer; +import org.eclipse.osee.ats.rest.IAtsServer; import org.eclipse.osee.jaxrs.mvc.IdentityView; import org.eclipse.osee.orcs.data.AttributeTypes; @@ -33,7 +33,7 @@ public class ConfigsJsonWriter implements MessageBodyWriter<Collection<IAtsConfi } public void start() { - jsonFactory = org.eclipse.osee.ats.impl.config.JsonFactory.create(); + jsonFactory = org.eclipse.osee.ats.rest.util.JsonFactory.create(); } public void stop() { diff --git a/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/config/ConvertCreateUpdateAtsConfig.java b/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/config/ConvertCreateUpdateAtsConfig.java index 33247710d9a..710f1397c71 100644 --- a/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/config/ConvertCreateUpdateAtsConfig.java +++ b/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/config/ConvertCreateUpdateAtsConfig.java @@ -11,7 +11,7 @@ package org.eclipse.osee.ats.rest.internal.config; import org.eclipse.osee.ats.api.util.IAtsDatabaseConversion; -import org.eclipse.osee.ats.impl.IAtsServer; +import org.eclipse.osee.ats.rest.IAtsServer; import org.eclipse.osee.framework.core.util.XResultData; /** diff --git a/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/config/ConvertResource.java b/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/config/ConvertResource.java index b5de2c53de9..af191872ee5 100644 --- a/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/config/ConvertResource.java +++ b/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/config/ConvertResource.java @@ -21,7 +21,7 @@ import javax.ws.rs.core.MediaType; import javax.ws.rs.core.MultivaluedMap; import javax.ws.rs.core.UriInfo; import org.eclipse.osee.ats.api.util.IAtsDatabaseConversion; -import org.eclipse.osee.ats.impl.IAtsServer; +import org.eclipse.osee.ats.rest.IAtsServer; import org.eclipse.osee.ats.rest.internal.util.RestUtil; import org.eclipse.osee.framework.core.util.XResultData; import org.eclipse.osee.framework.jdk.core.type.OseeCoreException; diff --git a/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/config/CountryEndpointImpl.java b/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/config/CountryEndpointImpl.java index 416df774813..4e691e22b6f 100644 --- a/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/config/CountryEndpointImpl.java +++ b/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/config/CountryEndpointImpl.java @@ -23,8 +23,7 @@ import org.eclipse.osee.ats.api.data.AtsArtifactTypes; import org.eclipse.osee.ats.api.program.ProgramEndpointApi; import org.eclipse.osee.ats.api.util.IAtsChangeSet; import org.eclipse.osee.ats.core.users.AtsCoreUsers; -import org.eclipse.osee.ats.impl.IAtsServer; -import org.eclipse.osee.ats.impl.config.BaseConfigEndpointImpl; +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.OseeStateException; diff --git a/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/config/CountryResource.java b/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/config/CountryResource.java index be2394da63e..a3bae72ca4c 100644 --- a/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/config/CountryResource.java +++ b/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/config/CountryResource.java @@ -12,8 +12,8 @@ package org.eclipse.osee.ats.rest.internal.config; import javax.ws.rs.Path; import org.eclipse.osee.ats.api.data.AtsArtifactTypes; -import org.eclipse.osee.ats.impl.IAtsServer; -import org.eclipse.osee.ats.impl.config.AbstractConfigResource; +import org.eclipse.osee.ats.rest.IAtsServer; +import org.eclipse.osee.ats.rest.util.AbstractConfigResource; /** * Donald G. Dunne diff --git a/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/config/InsertionActivityEndpointImpl.java b/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/config/InsertionActivityEndpointImpl.java index 086b3014b39..efdaf9dbfa0 100644 --- a/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/config/InsertionActivityEndpointImpl.java +++ b/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/config/InsertionActivityEndpointImpl.java @@ -23,8 +23,7 @@ import org.eclipse.osee.ats.api.insertion.InsertionActivityEndpointApi; import org.eclipse.osee.ats.api.insertion.JaxInsertionActivity; import org.eclipse.osee.ats.api.util.IAtsChangeSet; import org.eclipse.osee.ats.core.users.AtsCoreUsers; -import org.eclipse.osee.ats.impl.IAtsServer; -import org.eclipse.osee.ats.impl.config.BaseConfigEndpointImpl; +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.OseeStateException; diff --git a/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/config/InsertionActivityResource.java b/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/config/InsertionActivityResource.java index eacfdd21186..01c7dd1ff94 100644 --- a/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/config/InsertionActivityResource.java +++ b/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/config/InsertionActivityResource.java @@ -12,8 +12,8 @@ package org.eclipse.osee.ats.rest.internal.config; import javax.ws.rs.Path; import org.eclipse.osee.ats.api.data.AtsArtifactTypes; -import org.eclipse.osee.ats.impl.IAtsServer; -import org.eclipse.osee.ats.impl.config.AbstractConfigResource; +import org.eclipse.osee.ats.rest.IAtsServer; +import org.eclipse.osee.ats.rest.util.AbstractConfigResource; /** * Donald G. Dunne diff --git a/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/config/InsertionEndpointImpl.java b/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/config/InsertionEndpointImpl.java index 8f2b81deed5..5011f424d39 100644 --- a/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/config/InsertionEndpointImpl.java +++ b/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/config/InsertionEndpointImpl.java @@ -24,8 +24,7 @@ import org.eclipse.osee.ats.api.insertion.InsertionEndpointApi; import org.eclipse.osee.ats.api.insertion.JaxInsertion; import org.eclipse.osee.ats.api.util.IAtsChangeSet; import org.eclipse.osee.ats.core.users.AtsCoreUsers; -import org.eclipse.osee.ats.impl.IAtsServer; -import org.eclipse.osee.ats.impl.config.BaseConfigEndpointImpl; +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.OseeStateException; diff --git a/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/config/InsertionResource.java b/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/config/InsertionResource.java index de46f4bd4a8..8ef86b5e035 100644 --- a/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/config/InsertionResource.java +++ b/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/config/InsertionResource.java @@ -12,8 +12,8 @@ package org.eclipse.osee.ats.rest.internal.config; import javax.ws.rs.Path; import org.eclipse.osee.ats.api.data.AtsArtifactTypes; -import org.eclipse.osee.ats.impl.IAtsServer; -import org.eclipse.osee.ats.impl.config.AbstractConfigResource; +import org.eclipse.osee.ats.rest.IAtsServer; +import org.eclipse.osee.ats.rest.util.AbstractConfigResource; /** * Donald G. Dunne diff --git a/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/config/ProgramEndpointImpl.java b/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/config/ProgramEndpointImpl.java index 646834e683d..7f391363bc1 100644 --- a/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/config/ProgramEndpointImpl.java +++ b/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/config/ProgramEndpointImpl.java @@ -24,8 +24,7 @@ import org.eclipse.osee.ats.api.program.JaxProgram; import org.eclipse.osee.ats.api.program.ProgramEndpointApi; import org.eclipse.osee.ats.api.util.IAtsChangeSet; import org.eclipse.osee.ats.core.users.AtsCoreUsers; -import org.eclipse.osee.ats.impl.IAtsServer; -import org.eclipse.osee.ats.impl.config.BaseConfigEndpointImpl; +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.OseeStateException; diff --git a/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/config/ProgramResource.java b/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/config/ProgramResource.java index b6983d94f2d..f5e6a4f3d03 100644 --- a/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/config/ProgramResource.java +++ b/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/config/ProgramResource.java @@ -34,8 +34,8 @@ import org.eclipse.osee.ats.api.insertion.IAtsInsertion; import org.eclipse.osee.ats.api.insertion.IAtsInsertionActivity; import org.eclipse.osee.ats.api.insertion.JaxInsertion; import org.eclipse.osee.ats.api.insertion.JaxInsertionActivity; -import org.eclipse.osee.ats.impl.IAtsServer; -import org.eclipse.osee.ats.impl.config.AbstractConfigResource; +import org.eclipse.osee.ats.rest.IAtsServer; +import org.eclipse.osee.ats.rest.util.AbstractConfigResource; import org.eclipse.osee.framework.jdk.core.type.OseeCoreException; import org.eclipse.osee.framework.jdk.core.type.OseeStateException; import org.eclipse.osee.framework.jdk.core.type.ResultSet; diff --git a/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/config/ReportResource.java b/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/config/ReportResource.java index 30fdb39b1e4..9a1101ec45b 100644 --- a/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/config/ReportResource.java +++ b/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/config/ReportResource.java @@ -27,7 +27,7 @@ import javax.ws.rs.WebApplicationException; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; import javax.ws.rs.core.StreamingOutput; -import org.eclipse.osee.ats.impl.IAtsServer; +import org.eclipse.osee.ats.rest.IAtsServer; import org.eclipse.osee.framework.core.data.IAttributeType; import org.eclipse.osee.framework.core.data.IOseeBranch; import org.eclipse.osee.framework.core.enums.ModificationType; diff --git a/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/config/TeamResource.java b/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/config/TeamResource.java index 1599c7b7687..24ab6a079a7 100644 --- a/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/config/TeamResource.java +++ b/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/config/TeamResource.java @@ -12,8 +12,8 @@ package org.eclipse.osee.ats.rest.internal.config; import javax.ws.rs.Path; import org.eclipse.osee.ats.api.data.AtsArtifactTypes; -import org.eclipse.osee.ats.impl.IAtsServer; -import org.eclipse.osee.ats.impl.config.AbstractConfigResource; +import org.eclipse.osee.ats.rest.IAtsServer; +import org.eclipse.osee.ats.rest.util.AbstractConfigResource; /** * Donald G. Dunne diff --git a/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/config/UpdateAtsConfiguration.java b/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/config/UpdateAtsConfiguration.java index 083ea796fba..1092598482e 100644 --- a/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/config/UpdateAtsConfiguration.java +++ b/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/config/UpdateAtsConfiguration.java @@ -20,7 +20,7 @@ import org.eclipse.osee.ats.api.data.AtsAttributeTypes; import org.eclipse.osee.ats.api.util.ColorColumns; import org.eclipse.osee.ats.core.column.ColorTeamColumn; import org.eclipse.osee.ats.core.users.AtsCoreUsers; -import org.eclipse.osee.ats.impl.IAtsServer; +import org.eclipse.osee.ats.rest.IAtsServer; import org.eclipse.osee.ats.rest.internal.util.RestUtil; import org.eclipse.osee.framework.core.data.ArtifactId; import org.eclipse.osee.framework.core.enums.CoreAttributeTypes; diff --git a/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/config/VersionResource.java b/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/config/VersionResource.java index 5913cfd8a07..02b3ac65ace 100644 --- a/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/config/VersionResource.java +++ b/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/config/VersionResource.java @@ -12,8 +12,8 @@ package org.eclipse.osee.ats.rest.internal.config; import javax.ws.rs.Path; import org.eclipse.osee.ats.api.data.AtsArtifactTypes; -import org.eclipse.osee.ats.impl.IAtsServer; -import org.eclipse.osee.ats.impl.config.AbstractConfigResource; +import org.eclipse.osee.ats.rest.IAtsServer; +import org.eclipse.osee.ats.rest.util.AbstractConfigResource; /** * Donald G. Dunne diff --git a/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/convert/AbstractConvertGuidToUuid.java b/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/convert/AbstractConvertGuidToUuid.java new file mode 100644 index 00000000000..14efe0a4599 --- /dev/null +++ b/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/convert/AbstractConvertGuidToUuid.java @@ -0,0 +1,78 @@ +/******************************************************************************* + * Copyright (c) 2014 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.convert; + +import static org.eclipse.osee.framework.core.enums.CoreBranches.COMMON; +import org.eclipse.osee.ats.api.util.IAtsDatabaseConversion; +import org.eclipse.osee.ats.rest.IAtsServer; +import org.eclipse.osee.framework.core.enums.SystemUser; +import org.eclipse.osee.framework.jdk.core.type.OseeCoreException; +import org.eclipse.osee.framework.jdk.core.util.Conditions; +import org.eclipse.osee.jdbc.JdbcClient; +import org.eclipse.osee.logger.Log; +import org.eclipse.osee.orcs.OrcsApi; +import org.eclipse.osee.orcs.data.BranchReadable; +import org.eclipse.osee.orcs.transaction.TransactionBuilder; +import org.eclipse.osee.orcs.transaction.TransactionFactory; + +/** + * @author Megumi Telles + */ +public abstract class AbstractConvertGuidToUuid implements IAtsDatabaseConversion { + + private static final String SELECT_BRANCH_ID_BY_GUID = "select branch_id from osee_branch where branch_guid = ?"; + + private final Log logger; + private final JdbcClient jdbcClient; + private final OrcsApi orcsApi; + private final IAtsServer atsServer; + + public AbstractConvertGuidToUuid(Log logger, JdbcClient jdbcClient, OrcsApi orcsApi, IAtsServer atsServer) { + super(); + this.logger = logger; + this.jdbcClient = jdbcClient; + this.orcsApi = orcsApi; + this.atsServer = atsServer; + } + + protected OrcsApi getOrcsApi() { + return orcsApi; + } + + protected Log getLogger() { + return logger; + } + + protected JdbcClient getJdbcClient() { + return jdbcClient; + } + + protected BranchReadable getBranch(String guid) throws OseeCoreException { + return orcsApi.getQueryFactory().branchQuery().andUuids(getBranchIdLegacy(guid)).getResults().getExactlyOne(); + } + + protected TransactionBuilder createTransactionBuilder() throws OseeCoreException { + TransactionFactory txFactory = getOrcsApi().getTransactionFactory(); + Conditions.checkNotNull(txFactory, "transaction factory"); + return txFactory.createTransaction(COMMON, atsServer.getArtifactByGuid(SystemUser.OseeSystem.getGuid()), + getName()); + } + + /** + * Temporary method till all code uses branch uuid. Remove after 0.17.0 + */ + private long getBranchIdLegacy(String branchGuid) { + Long longId = getJdbcClient().runPreparedQueryFetchObject(0L, SELECT_BRANCH_ID_BY_GUID, branchGuid); + Conditions.checkExpressionFailOnTrue(longId <= 0, "Error getting branch_id for branch: [%s]", branchGuid); + return longId; + } + +} diff --git a/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/convert/ConvertBaselineGuidToBaselineUuid.java b/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/convert/ConvertBaselineGuidToBaselineUuid.java new file mode 100644 index 00000000000..1042e8ebd3b --- /dev/null +++ b/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/convert/ConvertBaselineGuidToBaselineUuid.java @@ -0,0 +1,119 @@ +/******************************************************************************* + * 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.convert; + +import java.util.List; +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.ats.rest.IAtsServer; +import org.eclipse.osee.framework.core.data.IAttributeType; +import org.eclipse.osee.framework.core.data.TokenFactory; +import org.eclipse.osee.framework.core.util.XResultData; +import org.eclipse.osee.framework.jdk.core.util.Strings; +import org.eclipse.osee.jdbc.JdbcClient; +import org.eclipse.osee.logger.Log; +import org.eclipse.osee.orcs.OrcsApi; +import org.eclipse.osee.orcs.data.ArtifactReadable; +import org.eclipse.osee.orcs.data.BranchReadable; +import org.eclipse.osee.orcs.transaction.TransactionBuilder; + +/** + * See description below + * + * @author Donald G Dunne + */ +public class ConvertBaselineGuidToBaselineUuid extends AbstractConvertGuidToUuid { + + // Leave this attribute definition and conversion for other OSEE sites to convert + private static final IAttributeType BaselineBranchGuid = TokenFactory.createAttributeType(0x10000000000000A9L, + "ats.Baseline Branch Guid"); + + public ConvertBaselineGuidToBaselineUuid(Log logger, JdbcClient jdbcClient, OrcsApi orcsApi, IAtsServer atsServer) { + super(logger, jdbcClient, orcsApi, atsServer); + } + + @Override + public void run(XResultData data, boolean reportOnly) { + if (reportOnly) { + data.log("REPORT ONLY - Changes not persisted\n"); + } + if (!getOrcsApi().getOrcsTypes().getAttributeTypes().exists(AtsAttributeTypes.BaselineBranchUuid)) { + data.error("ats.BaselineBranchUuid is not configured for this database"); + return; + } + TransactionBuilder tx = createTransactionBuilder(); + int numChanges = 0; + for (ArtifactReadable art : getOrcsApi().getQueryFactory().fromBranch(AtsUtilCore.getAtsBranch()).andTypeEquals( + AtsArtifactTypes.Version, AtsArtifactTypes.TeamDefinition).andExists(BaselineBranchGuid).getResults()) { + List<String> attributeValues = art.getAttributeValues(BaselineBranchGuid); + for (String guid : attributeValues) { + if (!guid.isEmpty()) { + BranchReadable branch = null; + try { + branch = getBranch(guid); + } catch (Exception ex) { + // do nothing + } + if (branch == null) { + data.errorf("Branch with guid %s can't be found", guid); + } else { + long branchUuid = branch.getUuid(); + String uuid = art.getSoleAttributeAsString(AtsAttributeTypes.BaselineBranchUuid, null); + if (!Strings.isValid(uuid) || isUuidDifferent(uuid, branchUuid)) { + if (!Strings.isValid(uuid)) { + data.logf( + "Adding uuid attribute of value %d to artifact type [%s] name [%s] id [%s]\n", branchUuid, + art.getArtifactType(), art.getName(), art.getGuid()); + } else if (isUuidDifferent(uuid, branchUuid)) { + data.logf( + "Updating uuid attribute of value %d to artifact type [%s] name [%s] id [%s]\n", branchUuid, + art.getArtifactType(), art.getName(), art.getGuid()); + } + numChanges++; + if (!reportOnly) { + tx.setSoleAttributeValue(art, AtsAttributeTypes.BaselineBranchUuid, String.valueOf(branchUuid)); + } + } + } + } + } + } + if (!reportOnly) { + data.log("\n" + numChanges + " Changes Persisted"); + tx.commit(); + } else { + data.log("\n" + numChanges + " Need to be Changed"); + } + } + + @Override + public String getDescription() { + StringBuffer data = new StringBuffer(); + data.append("ConvertBaselineGuidToBaselineUuid (required conversion)\n\n"); + data.append("Necessary for upgrading from OSEE 0.16.2 to 0.17.0"); + data.append("- Verify that ats.BaselineBranchUuid is a valid attribute type\n"); + data.append("- Verify Add uuid attribute for every ats.BaselineBranchGuid attribute on Version artifacts\n"); + data.append("- Verify Add uuid attribute for every ats.BaselineBranchGuid attribute on Team Definition artifacts\n\n"); + data.append("NOTE: This operation can be run multiple times\n"); + data.append("Manual Cleanup (optional): Use Purge Attribute Type BLAM to remove the ats.BaselineBranchGuid attributes."); + return data.toString(); + } + + @Override + public String getName() { + return "ConvertBaselineGuidToBaselineUuid"; + } + + private boolean isUuidDifferent(String uuid, long branchUuid) { + return Strings.isValid(uuid) && !Long.valueOf(uuid).equals(branchUuid); + } +} diff --git a/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/convert/ConvertFavoriteBranchGuidToUuid.java b/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/convert/ConvertFavoriteBranchGuidToUuid.java new file mode 100644 index 00000000000..1620e591c26 --- /dev/null +++ b/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/convert/ConvertFavoriteBranchGuidToUuid.java @@ -0,0 +1,141 @@ +/******************************************************************************* + * Copyright (c) 2014 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.convert; + +import org.eclipse.osee.ats.core.util.AtsUtilCore; +import org.eclipse.osee.ats.rest.IAtsServer; +import org.eclipse.osee.framework.core.enums.CoreArtifactTypes; +import org.eclipse.osee.framework.core.enums.CoreAttributeTypes; +import org.eclipse.osee.framework.core.util.XResultData; +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.GUID; +import org.eclipse.osee.jdbc.JdbcClient; +import org.eclipse.osee.logger.Log; +import org.eclipse.osee.orcs.OrcsApi; +import org.eclipse.osee.orcs.data.ArtifactReadable; +import org.eclipse.osee.orcs.data.AttributeReadable; +import org.eclipse.osee.orcs.data.BranchReadable; +import org.eclipse.osee.orcs.search.QueryFactory; +import org.eclipse.osee.orcs.transaction.TransactionBuilder; + +/** + * @author Megumi Telles + */ +public class ConvertFavoriteBranchGuidToUuid extends AbstractConvertGuidToUuid { + + private int numChanges = 0; + + public ConvertFavoriteBranchGuidToUuid(Log logger, JdbcClient jdbcClient, OrcsApi orcsApi, IAtsServer atsServer) { + super(logger, jdbcClient, orcsApi, atsServer); + } + + @Override + public String getName() { + return "FavoriteBranchGuidToUuid"; + } + + @Override + public String getDescription() { + StringBuffer data = new StringBuffer(); + data.append("ConvertFavoriteBranchGuidToUuid (required conversion)\n\n"); + data.append("Necessary for upgrading from OSEE 0.16.2 to 0.17.0\n"); + data.append("-- Converts a User's Favorite Branch Guid(s) to Uuid(s).\n\n"); + data.append("NOTE: This operation can be run multiple times\n"); + return data.toString(); + } + + @Override + public void run(XResultData data, boolean reportOnly) { + if (reportOnly) { + data.log("REPORT ONLY - Changes not persisted\n"); + } + try { + QueryFactory queryFactory = getOrcsApi().getQueryFactory(); + TransactionBuilder tx = createTransactionBuilder(); + for (ArtifactReadable art : getUsersFavoriteBranch(queryFactory)) { + convertAttributeToUuid(data, reportOnly, tx, art, art.getAttributes(CoreAttributeTypes.FavoriteBranch)); + } + if (reportOnly) { + data.log("\n" + numChanges + " Need to be Changed"); + } else { + data.log("\n" + numChanges + " Changes Persisted"); + if (numChanges > 0) { + tx.commit(); + } + } + numChanges = 0; + } catch (OseeCoreException ex) { + getLogger().error(ex, "Exception occurred while trying to convert branch guid to uuid"); + } + } + + private void convertAttributeToUuid(XResultData data, boolean reportOnly, TransactionBuilder tx, ArtifactReadable art, ResultSet<? extends AttributeReadable<Object>> favBranchAttrValues) throws OseeCoreException { + for (AttributeReadable<Object> attr : favBranchAttrValues) { + String value = attr.toString(); + if (GUID.isValid(value)) { + convert(data, reportOnly, tx, art, attr, value); + } else { + data.logf( + "Not a guid attribute value. Actual value [%s] for artifact type [%s] name [%s] id [%s] NOT converted to uuid.\n \n", + value, art.getArtifactType(), art.getName(), art.getGuid()); + } + } + } + + private void convert(XResultData data, boolean reportOnly, TransactionBuilder tx, ArtifactReadable art, AttributeReadable<Object> attr, String value) throws OseeCoreException { + BranchReadable branch = null; + try { + branch = getBranch(value); + } catch (OseeCoreException ex) { + getLogger().warn(ex, "No Branch found with value: [%s]", value); + } + if (branch != null) { + addUuid(data, reportOnly, tx, art, attr, branch); + } else { + removeAttrForNonExistentBranch(data, reportOnly, tx, art, attr, value); + } + } + + private void addUuid(XResultData data, boolean reportOnly, TransactionBuilder tx, ArtifactReadable art, AttributeReadable<Object> attr, BranchReadable branch) throws OseeCoreException { + numChanges++; + Long branchUuid = branch.getUuid(); + data.logf("Adding uuid attribute of value %d to artifact type [%s] name [%s] id [%s]\n", branchUuid, + art.getArtifactType(), art.getName(), art.getGuid()); + if (!reportOnly) { + try { + tx.setAttributeById(art, attr, String.valueOf(branchUuid)); + } catch (OseeCoreException ex) { + data.errorf( + "Error building transaction for convert to uuid attribute of value %d for artifact type [%s] name [%s] id [%s]\n", + branch.getUuid(), art.getArtifactType(), art.getName(), art.getGuid()); + } + } + } + + private void removeAttrForNonExistentBranch(XResultData data, boolean reportOnly, TransactionBuilder tx, ArtifactReadable art, AttributeReadable<Object> attr, String value) throws OseeCoreException { + try { + data.logf("No Branch found with value [%s]. Recommend removing attribute.\n", value); + if (!reportOnly) { + tx.deleteByAttributeId(art, attr); + } + } catch (OseeCoreException ex) { + data.errorf("Error building transaction to remove guid [%s] for branch that no longer exists\n", + value); + } + } + + private ResultSet<ArtifactReadable> getUsersFavoriteBranch(QueryFactory queryFactory) throws OseeCoreException { + return queryFactory.fromBranch(AtsUtilCore.getAtsBranch()).andTypeEquals(CoreArtifactTypes.User).andExists( + CoreAttributeTypes.FavoriteBranch).getResults(); + } + +} diff --git a/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/cpa/CpaDuplicator.java b/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/cpa/CpaDuplicator.java index 0153f5cd487..56a375a84d7 100644 --- a/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/cpa/CpaDuplicator.java +++ b/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/cpa/CpaDuplicator.java @@ -22,7 +22,7 @@ import org.eclipse.osee.ats.api.workflow.transition.TransitionOption; import org.eclipse.osee.ats.core.users.AtsCoreUsers; import org.eclipse.osee.ats.core.workflow.transition.TransitionHelper; import org.eclipse.osee.ats.core.workflow.transition.TransitionManager; -import org.eclipse.osee.ats.impl.IAtsServer; +import org.eclipse.osee.ats.rest.IAtsServer; import org.eclipse.osee.framework.core.util.XResultData; import org.eclipse.osee.framework.jdk.core.util.Strings; import org.eclipse.osee.orcs.data.ArtifactReadable; diff --git a/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/cpa/CpaResource.java b/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/cpa/CpaResource.java index 6f62919e607..4cb6fd6685c 100644 --- a/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/cpa/CpaResource.java +++ b/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/cpa/CpaResource.java @@ -34,7 +34,7 @@ import org.eclipse.osee.ats.api.cpa.DecisionUpdate; import org.eclipse.osee.ats.api.cpa.DuplicateCpa; import org.eclipse.osee.ats.api.cpa.IAtsCpaService; import org.eclipse.osee.ats.api.data.AtsAttributeTypes; -import org.eclipse.osee.ats.impl.IAtsServer; +import org.eclipse.osee.ats.rest.IAtsServer; import org.eclipse.osee.framework.core.util.XResultData; import org.eclipse.osee.framework.jdk.core.util.AHTML; import org.eclipse.osee.jaxrs.OseeWebApplicationException; diff --git a/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/cpa/CpaUtil.java b/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/cpa/CpaUtil.java index 81d4deeda6a..ff2a73e058f 100644 --- a/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/cpa/CpaUtil.java +++ b/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/cpa/CpaUtil.java @@ -12,7 +12,7 @@ package org.eclipse.osee.ats.rest.internal.cpa; import javax.ws.rs.core.UriBuilder; import org.eclipse.osee.ats.core.cpa.CpaFactory; -import org.eclipse.osee.ats.impl.IAtsServer; +import org.eclipse.osee.ats.rest.IAtsServer; /** * @author Donald G. dunne diff --git a/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/cpa/DecisionLoader.java b/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/cpa/DecisionLoader.java index b7902ecc0dc..37638faf194 100644 --- a/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/cpa/DecisionLoader.java +++ b/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/cpa/DecisionLoader.java @@ -22,7 +22,7 @@ import org.eclipse.osee.ats.api.data.AtsAttributeTypes; import org.eclipse.osee.ats.api.workdef.StateType; import org.eclipse.osee.ats.api.workflow.IAtsTeamWorkflow; import org.eclipse.osee.ats.core.cpa.CpaFactory; -import org.eclipse.osee.ats.impl.IAtsServer; +import org.eclipse.osee.ats.rest.IAtsServer; import org.eclipse.osee.framework.jdk.core.type.HashCollection; import org.eclipse.osee.framework.jdk.core.type.ResultSet; import org.eclipse.osee.framework.jdk.core.util.Conditions; diff --git a/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/cpa/DecisionUpdater.java b/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/cpa/DecisionUpdater.java index 6e8e60abfe0..76b0dc977a7 100644 --- a/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/cpa/DecisionUpdater.java +++ b/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/cpa/DecisionUpdater.java @@ -25,7 +25,7 @@ import org.eclipse.osee.ats.core.users.AtsCoreUsers; import org.eclipse.osee.ats.core.workflow.state.TeamState; import org.eclipse.osee.ats.core.workflow.transition.TransitionFactory; import org.eclipse.osee.ats.core.workflow.transition.TransitionHelper; -import org.eclipse.osee.ats.impl.IAtsServer; +import org.eclipse.osee.ats.rest.IAtsServer; import org.eclipse.osee.framework.core.util.XResultData; import org.eclipse.osee.framework.jdk.core.type.ResultSet; import org.eclipse.osee.framework.jdk.core.util.Collections; diff --git a/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/notify/AtsNotificationEventProcessor.java b/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/notify/AtsNotificationEventProcessor.java new file mode 100644 index 00000000000..1911ac526d7 --- /dev/null +++ b/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/notify/AtsNotificationEventProcessor.java @@ -0,0 +1,65 @@ +/******************************************************************************* + * Copyright (c) 2014 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.notify; + +import java.util.List; +import org.eclipse.osee.ats.api.notify.AtsNotificationCollector; +import org.eclipse.osee.ats.api.notify.AtsNotificationEvent; +import org.eclipse.osee.ats.api.notify.AtsWorkItemNotificationEvent; +import org.eclipse.osee.ats.api.user.IAtsUser; +import org.eclipse.osee.ats.api.user.IAtsUserService; +import org.eclipse.osee.ats.rest.util.IAtsNotifierServer; +import org.eclipse.osee.framework.jdk.core.util.EmailUtil; +import org.eclipse.osee.framework.jdk.core.util.Strings; + +public class AtsNotificationEventProcessor { + + private final String noReplyEmail; + private final WorkItemNotificationProcessor workItemNotificationProcessor; + private final IAtsUserService userService; + + public AtsNotificationEventProcessor(WorkItemNotificationProcessor workItemNotificationProcessor, IAtsUserService userService, String noReplyEmail) { + this.workItemNotificationProcessor = workItemNotificationProcessor; + this.userService = userService; + this.noReplyEmail = noReplyEmail; + } + + public void sendNotifications(AtsNotificationCollector notifications, List<IAtsNotifierServer> notifiers) { + + // convert all WorkItem notifications to AtsNotificationEvent + for (AtsWorkItemNotificationEvent workItemEvent : notifications.getWorkItemNotificationEvents()) { + workItemNotificationProcessor.run(notifications, workItemEvent); + } + + String testingUserEmail = ""; // change to email address for testing purposes; all emails will go there + String fromUserEmail = getFromUserEmail(notifications); + + for (IAtsNotifierServer notifier : notifiers) { + notifier.sendNotifications(fromUserEmail, testingUserEmail, notifications.getSubject(), + notifications.getBody(), notifications.getNotificationEvents()); + } + } + + private String getFromUserEmail(AtsNotificationCollector notifications) { + String email = noReplyEmail; + for (AtsNotificationEvent event : notifications.getNotificationEvents()) { + if (Strings.isValid(event.getFromUserId())) { + IAtsUser userById = userService.getUserById(event.getFromUserId()); + if (EmailUtil.isEmailValid(userById.getEmail())) { + email = userById.getEmail(); + break; + } + } + } + return email; + } + +} diff --git a/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/notify/AtsNotifierServiceImpl.java b/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/notify/AtsNotifierServiceImpl.java new file mode 100644 index 00000000000..cc64f1c5e86 --- /dev/null +++ b/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/notify/AtsNotifierServiceImpl.java @@ -0,0 +1,52 @@ +/******************************************************************************* + * 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.notify; + +import java.util.Collection; +import org.eclipse.osee.ats.api.notify.AtsNotificationEvent; +import org.eclipse.osee.ats.api.user.IAtsUserService; +import org.eclipse.osee.ats.rest.util.IAtsNotifierServer; +import org.eclipse.osee.logger.Log; +import org.eclipse.osee.mail.api.MailService; + +/** + * @author Donald G. Dunne + */ +public class AtsNotifierServiceImpl implements IAtsNotifierServer { + + private Log logger; + private MailService mailService; + private IAtsUserService userService; + + public void setLogger(Log logger) { + this.logger = logger; + } + + public void setMailService(MailService mailService) { + this.mailService = mailService; + } + + public void setUserService(IAtsUserService userService) { + this.userService = userService; + } + + /** + * Send notifications + */ + @Override + public void sendNotifications(String fromUserEmail, String testingUserEmail, String subject, String body, Collection<? extends AtsNotificationEvent> notificationEvents) { + SendNotificationEvents job = + new SendNotificationEvents(logger, mailService, fromUserEmail, testingUserEmail, subject, body, + notificationEvents, userService); + job.run(); + } + +} diff --git a/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/notify/AtsNotifyEndpointImpl.java b/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/notify/AtsNotifyEndpointImpl.java index 983e56136b3..d548720d0da 100644 --- a/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/notify/AtsNotifyEndpointImpl.java +++ b/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/notify/AtsNotifyEndpointImpl.java @@ -13,7 +13,7 @@ package org.eclipse.osee.ats.rest.internal.notify; import javax.ws.rs.core.Response; import org.eclipse.osee.ats.api.notify.AtsNotificationCollector; import org.eclipse.osee.ats.api.notify.AtsNotifyEndpointApi; -import org.eclipse.osee.ats.impl.IAtsServer; +import org.eclipse.osee.ats.rest.IAtsServer; /** * @author Donald G. Dunne diff --git a/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/notify/NoOpAtsNotifierServiceImpl.java b/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/notify/NoOpAtsNotifierServiceImpl.java new file mode 100644 index 00000000000..6aa93b22640 --- /dev/null +++ b/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/notify/NoOpAtsNotifierServiceImpl.java @@ -0,0 +1,26 @@ +/******************************************************************************* + * Copyright (c) 2014 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.notify; + +import java.util.Collection; +import org.eclipse.osee.ats.api.notify.AtsNotificationEvent; +import org.eclipse.osee.ats.rest.util.IAtsNotifierServer; + +/** + * @author Donald G. Dunne + */ +public class NoOpAtsNotifierServiceImpl implements IAtsNotifierServer { + + @Override + public void sendNotifications(String fromUserEmail, String testingUserEmail, String subject, String body, Collection<? extends AtsNotificationEvent> notificationEvents) { + // do nothing + } +} diff --git a/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/notify/SendNotificationEvents.java b/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/notify/SendNotificationEvents.java new file mode 100644 index 00000000000..474c73d287f --- /dev/null +++ b/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/notify/SendNotificationEvents.java @@ -0,0 +1,159 @@ +/******************************************************************************* + * Copyright (c) 2004, 2007 Boeing. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.ats.rest.internal.notify; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.HashSet; +import java.util.List; +import java.util.Set; +import org.eclipse.osee.ats.api.notify.AtsNotificationEvent; +import org.eclipse.osee.ats.api.user.IAtsUser; +import org.eclipse.osee.ats.api.user.IAtsUserService; +import org.eclipse.osee.ats.core.users.AtsUsersUtility; +import org.eclipse.osee.framework.core.enums.SystemUser; +import org.eclipse.osee.framework.core.util.Result; +import org.eclipse.osee.framework.core.util.XResultData; +import org.eclipse.osee.framework.jdk.core.type.OseeCoreException; +import org.eclipse.osee.framework.jdk.core.util.AHTML; +import org.eclipse.osee.framework.jdk.core.util.Strings; +import org.eclipse.osee.logger.Log; +import org.eclipse.osee.mail.api.MailMessage; +import org.eclipse.osee.mail.api.MailService; +import org.eclipse.osee.mail.api.MailStatus; + +/** + * @author Donald G. Dunne + */ +public class SendNotificationEvents { + private final Log logger; + private final Collection<? extends AtsNotificationEvent> notificationEvents; + private final String subject; + private final String body; + private final MailService mailService; + private final String fromUserEmail; + private final String testingUserEmail; + private final IAtsUserService userService; + + protected SendNotificationEvents(Log logger, MailService mailService, String fromUserEmail, String testingUserEmail, String subject, String body, Collection<? extends AtsNotificationEvent> notificationEvents, IAtsUserService userService) { + this.logger = logger; + this.mailService = mailService; + this.fromUserEmail = fromUserEmail; + this.testingUserEmail = testingUserEmail; + this.subject = subject; + this.body = body; + this.notificationEvents = notificationEvents; + this.userService = userService; + if (isTesting()) { + logger.error("OseeNotifyUsersJob: testing is enabled....turn off for production."); + } + } + + public Result run() { + try { + Set<IAtsUser> uniqueUusers = new HashSet<>(); + for (AtsNotificationEvent notificationEvent : notificationEvents) { + uniqueUusers.addAll(AtsUsersUtility.getUsers(notificationEvent.getUserIds(), userService)); + } + XResultData resultData = new XResultData(); + if (isTesting()) { + resultData.errorf("Testing Results Report for Osee Notification; Email to user [%s].<br>", + testingUserEmail); + } + for (IAtsUser user : AtsUsersUtility.getValidEmailUsers(uniqueUusers)) { + List<AtsNotificationEvent> notifyEvents = new ArrayList<>(); + for (AtsNotificationEvent notificationEvent : notificationEvents) { + if (isTesting() || AtsUsersUtility.getUsers(notificationEvent.getUserIds(), userService).contains(user)) { + notifyEvents.add(notificationEvent); + } + } + notifyUser(user, notifyEvents, resultData); + } + return Result.TrueResult; + } catch (Exception ex) { + logger.error(ex, "Error notifying users"); + return new Result("Error notifying users [%s]", ex.getMessage()); + } + } + + private String notificationEventsToHtml(List<AtsNotificationEvent> notificationEvents) { + StringBuffer sb = new StringBuffer(); + sb.append(AHTML.beginMultiColumnTable(100, 1)); + sb.append(AHTML.addHeaderRowMultiColumnTable(new String[] {"Reason", "Description", "Id", "URL"})); + for (AtsNotificationEvent notificationEvent : notificationEvents) { + sb.append(AHTML.addRowMultiColumnTable(new String[] { + notificationEvent.getType(), + notificationEvent.getDescription(), + notificationEvent.getId(), + getHyperlink(notificationEvent)})); + } + sb.append(AHTML.endMultiColumnTable()); + return sb.toString().replaceAll("\n", ""); + } + + private String getHyperlink(AtsNotificationEvent notificationEvent) { + return Strings.isValid(notificationEvent.getUrl()) ? AHTML.getHyperlink(notificationEvent.getUrl(), "More Info") : ""; + } + + private void notifyUser(IAtsUser user, List<AtsNotificationEvent> notificationEvents, XResultData resultData) throws OseeCoreException { + if (user.getUserId().equals(SystemUser.OseeSystem.getUserId()) || user.getUserId().equals( + SystemUser.UnAssigned.getUserId()) || user.getUserId().equals(SystemUser.Anonymous.getUserId())) { + // do nothing + return; + } + if (!AtsUsersUtility.isEmailValid(user.getEmail())) { + // do nothing; can't send email from user with invalid email address + return; + } + String html = ""; + if (Strings.isValid(body)) { + html += "<pre>" + body + "</pre>"; + } + html += notificationEventsToHtml(notificationEvents); + String email = user.getEmail(); + if (!Strings.isValid(email)) { + // do nothing + return; + } else { + + String useEmail = isTesting() ? testingUserEmail : email; + + MailMessage msg = MailMessage.newBuilder() // + .from(fromUserEmail) // + .recipients(Arrays.asList(useEmail)) // + .subject(getNotificationEmailSubject(notificationEvents)) // + .addHtml(html)// + .build(); + + List<MailStatus> sendMessages = mailService.sendMessages(msg); + System.out.println(sendMessages); + } + } + + private boolean isTesting() { + return Strings.isValid(testingUserEmail); + } + + private String getNotificationEmailSubject(List<AtsNotificationEvent> notificationEvents) { + String result = subject; + if (!Strings.isValid(result)) { + if (notificationEvents.size() == 1) { + AtsNotificationEvent event = notificationEvents.iterator().next(); + result = + Strings.truncate("OSEE Notification" + " - " + event.getType() + " - " + event.getDescription(), 128); + } else { + result = "OSEE Notification"; + } + } + return result; + } +} 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 new file mode 100644 index 00000000000..af3aaf3b02d --- /dev/null +++ b/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/notify/WorkItemNotificationProcessor.java @@ -0,0 +1,288 @@ +/******************************************************************************* + * Copyright (c) 2004, 2007 Boeing. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.ats.rest.internal.notify; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.HashSet; +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.notify.AtsNotificationCollector; +import org.eclipse.osee.ats.api.notify.AtsNotificationEventFactory; +import org.eclipse.osee.ats.api.notify.AtsNotifyType; +import org.eclipse.osee.ats.api.notify.AtsWorkItemNotificationEvent; +import org.eclipse.osee.ats.api.review.IAtsAbstractReview; +import org.eclipse.osee.ats.api.review.Role; +import org.eclipse.osee.ats.api.review.UserRole; +import org.eclipse.osee.ats.api.team.IAtsTeamDefinition; +import org.eclipse.osee.ats.api.team.IAtsWorkItemFactory; +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.StateType; +import org.eclipse.osee.ats.api.workflow.IAtsTeamWorkflow; +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.jdk.core.type.OseeCoreException; +import org.eclipse.osee.framework.jdk.core.util.DateUtil; +import org.eclipse.osee.framework.jdk.core.util.EmailUtil; +import org.eclipse.osee.framework.jdk.core.util.Strings; +import org.eclipse.osee.logger.Log; + +/** + * @author Donald G. Dunne + */ +public class WorkItemNotificationProcessor { + + private final Log logger; + private final IAtsUserService userService; + private final IAttributeResolver attrResolver; + private final IAtsWorkItemFactory workItemFactory; + private final IAtsServer atsServer; + private static String actionUrl; + + public WorkItemNotificationProcessor(Log logger, IAtsServer atsServer, IAtsWorkItemFactory workItemFactory, IAtsUserService userService, IAttributeResolver attrResolver) throws OseeCoreException { + this.logger = logger; + this.atsServer = atsServer; + this.workItemFactory = workItemFactory; + this.userService = userService; + this.attrResolver = attrResolver; + } + + /** + * @param notifyUsers only valid for assignees notifyType. if null or any other type, the users will be computed + */ + public void run(AtsNotificationCollector notifications, AtsWorkItemNotificationEvent event) throws OseeCoreException { + Collection<AtsNotifyType> types = event.getNotifyTypes(); + List<IAtsUser> notifyUsers = new ArrayList<>(); + IAtsUser fromUser = AtsCoreUsers.SYSTEM_USER; + if (Strings.isValid(event.getFromUserId())) { + fromUser = userService.getUserById(event.getFromUserId()); + } + for (String userId : event.getUserIds()) { + notifyUsers.add(userService.getUserById(userId)); + } + for (String atsId : event.getAtsIds()) { + IAtsWorkItem workItem = workItemFactory.getWorkItemByAtsId(atsId); + + if (types.contains(AtsNotifyType.Originator)) { + try { + IAtsUser originator = workItem.getCreatedBy(); + if (originator.isActive()) { + if (!EmailUtil.isEmailValid(originator.getEmail()) && !AtsCoreUsers.isAtsCoreUser(originator)) { + logger.info("Email [%s] invalid for user [%s]", originator.getEmail(), originator.getName()); + } else if (!fromUser.equals(originator)) { + notifications.addNotificationEvent(AtsNotificationEventFactory.getNotificationEvent( + getFromUser(event), + Arrays.asList(originator), + getIdString(workItem), + AtsNotifyType.Originator.name(), + getUrl(workItem), + String.format("You have been set as the originator of [%s] state [%s] titled [%s]", + workItem.getArtifactTypeName(), workItem.getStateMgr().getCurrentStateName(), + workItem.getName()))); + } + } + } catch (OseeCoreException ex) { + logger.error(ex, "Error processing Originator for workItem [%s] and event [%s]", + workItem.toStringWithId(), event.toString()); + } + } + if (types.contains(AtsNotifyType.Assigned)) { + try { + Collection<IAtsUser> assignees = new HashSet<>(); + if (!notifyUsers.isEmpty()) { + assignees.addAll(notifyUsers); + } else { + assignees.addAll(workItem.getStateMgr().getAssignees()); + } + assignees.remove(fromUser); + assignees = AtsUsersUtility.getValidEmailUsers(assignees); + assignees = AtsUsersUtility.getActiveEmailUsers(assignees); + if (assignees.size() > 0) { + notifications.addNotificationEvent(AtsNotificationEventFactory.getNotificationEvent( + getFromUser(event), + assignees, + getIdString(workItem), + AtsNotifyType.Assigned.name(), + getUrl(workItem), + String.format("You have been set as the assignee of [%s] in state [%s] titled [%s]", + workItem.getArtifactTypeName(), workItem.getStateMgr().getCurrentStateName(), + workItem.getName()))); + } + } catch (OseeCoreException ex) { + logger.error(ex, "Error processing Assigned for workItem [%s] and event [%s]", + workItem.toStringWithId(), event.toString()); + } + } + if (types.contains(AtsNotifyType.Subscribed)) { + try { + Collection<IAtsUser> subscribed = new HashSet<>(); + subscribed.addAll(userService.getSubscribed(workItem)); + subscribed = AtsUsersUtility.getValidEmailUsers(subscribed); + subscribed = AtsUsersUtility.getActiveEmailUsers(subscribed); + if (subscribed.size() > 0) { + notifications.addNotificationEvent(AtsNotificationEventFactory.getNotificationEvent( + getFromUser(event), subscribed, getIdString(workItem), AtsNotifyType.Subscribed.name(), + getUrl(workItem), String.format( + "[%s] titled [%s] transitioned to [%s] and you subscribed for notification.", + workItem.getArtifactTypeName(), workItem.getName(), + workItem.getStateMgr().getCurrentStateName()))); + } + } catch (OseeCoreException ex) { + logger.error(ex, "Error processing Subscribed for workItem [%s] and event [%s]", + workItem.toStringWithId(), event.toString()); + } + } + try { + IAtsStateDefinition stateDefinition = workItem.getStateDefinition(); + StateType stateType = stateDefinition.getStateType(); + boolean notificationTypeIsCompletedOrCancelled = + types.contains(AtsNotifyType.Cancelled) || types.contains(AtsNotifyType.Completed); + boolean stateTypeIsCompletedOrCancelled = stateType.isCompleted() || stateType.isCancelled(); + if (notificationTypeIsCompletedOrCancelled && !workItem.isTask() && stateTypeIsCompletedOrCancelled) { + IAtsUser originator = workItem.getCreatedBy(); + if (originator.isActive()) { + if (!EmailUtil.isEmailValid(originator.getEmail())) { + logger.info("Email [%s] invalid for user [%s]", originator.getEmail(), originator.getName()); + } else if (isOriginatorDifferentThanCancelledOrCompletedBy(workItem, fromUser, originator)) { + if (stateType.isCompleted()) { + notifications.addNotificationEvent(AtsNotificationEventFactory.getNotificationEvent( + getFromUser(event), Arrays.asList(originator), getIdString(workItem), + workItem.getStateMgr().getCurrentStateName(), getUrl(workItem), String.format( + "[%s] titled [%s] is [%s]", workItem.getArtifactTypeName(), workItem.getName(), + workItem.getStateMgr().getCurrentStateName()))); + } + if (stateType.isCancelled()) { + notifications.addNotificationEvent(AtsNotificationEventFactory.getNotificationEvent( + getFromUser(event), Arrays.asList(originator), getIdString(workItem), + workItem.getStateMgr().getCurrentStateName(), getUrl(workItem), String.format( + "[%s] titled [%s] was [%s] from the [%s] state on [%s].<br>Reason: [%s]", + workItem.getArtifactTypeName(), workItem.getName(), + workItem.getStateMgr().getCurrentStateName(), workItem.getCancelledFromState(), + DateUtil.getMMDDYYHHMM(workItem.getCancelledDate()), workItem.getCancelledReason()))); + } + } + } + } + } catch (Exception ex) { + logger.error(ex, "Error processing Completed or Cancelled for workItem [%s] and event [%s]", + workItem.toStringWithId(), event.toString()); + } + if (types.contains(AtsNotifyType.Peer_Reviewers_Completed) && workItem instanceof IAtsAbstractReview) { + try { + UserRoleManager roleMgr = new UserRoleManager(attrResolver, userService, workItem); + Collection<IAtsUser> authorModerator = new ArrayList<>(); + for (UserRole role : roleMgr.getUserRoles()) { + if (role.getRole() == Role.Author || role.getRole() == Role.Moderator) { + authorModerator.add(userService.getUserById(role.getUserId())); + } + } + authorModerator = AtsUsersUtility.getValidEmailUsers(authorModerator); + authorModerator = AtsUsersUtility.getActiveEmailUsers(authorModerator); + if (authorModerator.size() > 0) { + notifications.addNotificationEvent(AtsNotificationEventFactory.getNotificationEvent( + getFromUser(event), authorModerator, getIdString(workItem), + AtsNotifyType.Peer_Reviewers_Completed.name(), String.format( + "You are Author/Moderator of [%s] titled [%s] which has been reviewed by all reviewers", + workItem.getArtifactTypeName(), workItem.getName()))); + } + } catch (OseeCoreException ex) { + logger.error(ex, "Error processing Peer_Reviewers_Completed for workItem [%s] and event [%s]", + workItem.toStringWithId(), event.toString()); + } + } + if (types.contains(AtsNotifyType.SubscribedTeamOrAi)) { + if (workItem.isTeamWorkflow()) { + IAtsTeamWorkflow teamWf = (IAtsTeamWorkflow) workItem; + try { + Collection<IAtsUser> subscribedUsers = new HashSet<>(); + // Handle Team Definitions + IAtsTeamDefinition teamDef = teamWf.getTeamDefinition(); + subscribedUsers.addAll(teamDef.getSubscribed()); + if (subscribedUsers.size() > 0) { + notifications.addNotificationEvent(AtsNotificationEventFactory.getNotificationEvent( + AtsCoreUsers.SYSTEM_USER, + subscribedUsers, + getIdString(teamWf), + "Workflow Creation", + getUrl(workItem), + "You have subscribed for email notification for Team \"" + teamWf.getTeamDefinition().getName() + "\"; New Team Workflow created with title \"" + teamWf.getName() + "\"")); + } + + // Handle Actionable Items + for (IAtsActionableItem aia : teamWf.getActionableItems()) { + subscribedUsers = aia.getSubscribed(); + if (subscribedUsers.size() > 0) { + notifications.addNotificationEvent(AtsNotificationEventFactory.getNotificationEvent( + AtsCoreUsers.SYSTEM_USER, + subscribedUsers, + getIdString(teamWf), + "Workflow Creation", + getUrl(workItem), + "You have subscribed for email notification for Actionable Item \"" + teamWf.getTeamDefinition().getName() + "\"; New Team Workflow created with title \"" + teamWf.getName() + "\"")); + } + } + } catch (OseeCoreException ex) { + logger.error(ex, "Error processing SubscribedTeamOrAi for workItem [%s] and event [%s]", + workItem.toStringWithId(), event.toString()); + } + } + } + } + } + + private boolean isOriginatorDifferentThanCancelledOrCompletedBy(IAtsWorkItem workItem, IAtsUser fromUser, IAtsUser originator) { + boolean different = true; + if (fromUser.equals(originator)) { + different = false; + } else if (workItem.getCancelledBy() != null && originator.equals(workItem.getCancelledBy())) { + different = false; + } else if (workItem.getCompletedBy() != null && originator.equals(workItem.getCompletedBy())) { + different = false; + } + return different; + } + + private String getUrl(IAtsWorkItem workItem) { + if (actionUrl == null) { + actionUrl = atsServer.getConfigValue("ActionUrl"); + } + return actionUrl.replaceFirst("UUID", String.valueOf(workItem.getUuid())); + } + + private IAtsUser getFromUser(AtsWorkItemNotificationEvent event) { + IAtsUser fromUser = AtsCoreUsers.SYSTEM_USER; + if (Strings.isValid(event.getFromUserId())) { + fromUser = userService.getUserById(event.getFromUserId()); + } + return fromUser; + } + + private String getIdString(IAtsWorkItem workItem) { + try { + String legacyPcrId = attrResolver.getSoleAttributeValue(workItem, AtsAttributeTypes.LegacyPcrId, ""); + if (!legacyPcrId.equals("")) { + return "ID: " + workItem.getAtsId() + " / LegacyId: " + legacyPcrId; + } + } catch (Exception ex) { + logger.error(ex, "Error getting legacyId pcr for workItem [%s]", workItem); + } + return "ID: " + workItem.getAtsId(); + } + +} diff --git a/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/query/AtsQueryImpl.java b/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/query/AtsQueryImpl.java new file mode 100644 index 00000000000..f768228d4d5 --- /dev/null +++ b/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/query/AtsQueryImpl.java @@ -0,0 +1,157 @@ +/******************************************************************************* + * Copyright (c) 2015 Boeing. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.ats.rest.internal.query; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.Iterator; +import java.util.LinkedList; +import java.util.List; +import org.eclipse.osee.ats.api.data.AtsArtifactTypes; +import org.eclipse.osee.ats.api.data.AtsAttributeTypes; +import org.eclipse.osee.ats.core.query.AbstractAtsQueryImpl; +import org.eclipse.osee.ats.core.query.AtsAttributeQuery; +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.IArtifactType; +import org.eclipse.osee.framework.core.data.IAttributeType; +import org.eclipse.osee.framework.core.data.IRelationTypeSide; +import org.eclipse.osee.framework.core.enums.QueryOption; +import org.eclipse.osee.orcs.data.ArtifactReadable; +import org.eclipse.osee.orcs.search.QueryBuilder; + +/** + * @author Donald G. Dunne + */ +public class AtsQueryImpl extends AbstractAtsQueryImpl { + + private final IAtsServer atsServer; + private QueryBuilder query; + + public AtsQueryImpl(IAtsServer atsServer) { + super(atsServer.getServices()); + this.atsServer = atsServer; + } + + @Override + public Collection<ArtifactId> runQuery() { + List<ArtifactId> results = new ArrayList<ArtifactId>(); + Iterator<ArtifactReadable> iterator = query.getResults().iterator(); + while (iterator.hasNext()) { + results.add(iterator.next()); + } + return results; + } + + @Override + public void createQueryBuilder() { + query = atsServer.getOrcsApi().getQueryFactory().fromBranch(AtsUtilCore.getAtsBranch()); + } + + @Override + public void queryAnd(IAttributeType attrType, Collection<String> values) { + query.and(attrType, values); + } + + @Override + public void queryAndIsOfType(IArtifactType artifactType) { + query.andIsOfType(artifactType); + } + + @Override + public List<Integer> queryGetIds() { + List<Integer> results = new LinkedList<>(); + Iterator<HasLocalId<Integer>> iterator = query.getResultsAsLocalIds().iterator(); + while (iterator.hasNext()) { + results.add(iterator.next().getLocalId()); + } + return results; + } + + @Override + public void queryAndIsOfType(List<IArtifactType> artTypes) { + query.andIsOfType(artTypes); + } + + @Override + public void queryAnd(IAttributeType attrType, String value) { + query.and(attrType, value); + } + + @Override + public void queryAndRelatedToLocalIds(IRelationTypeSide relationTypeSide, int artId) { + query.andRelatedToLocalIds(relationTypeSide, artId); + } + + @Override + public void queryAnd(IAttributeType attrType, Collection<String> values, QueryOption[] queryOption) { + query.and(attrType, values, queryOption); + } + + @Override + public void queryAndRelatedToLocalIds(IRelationTypeSide relationTypeSide, List<Integer> artIds) { + query.andRelatedToLocalIds(relationTypeSide, artIds); + } + + @Override + public void queryAnd(IAttributeType attrType, String value, QueryOption[] queryOption) { + query.and(attrType, value, queryOption); + } + + @Override + public void queryAndLocalIds(List<Integer> artIds) { + List<Long> results = new LinkedList<>(); + for (Integer artId : artIds) { + results.add(new Long(artId)); + } + query.andUuids(results); + } + + @Override + public void queryAndNotExists(IRelationTypeSide relationTypeSide) { + query.andNotExists(relationTypeSide); + } + + @Override + public void queryAndExists(IRelationTypeSide relationTypeSide) { + query.andExists(relationTypeSide); + } + + @Override + public List<String> getWorkPackagesForColorTeam(String colorTeam) { + List<String> workPackageGuids = new LinkedList<>(); + for (ArtifactReadable workPackageArt : atsServer.getOrcsApi().getQueryFactory().fromBranch( + AtsUtilCore.getAtsBranch()).andIsOfType(AtsArtifactTypes.WorkPackage).and(AtsAttributeTypes.ColorTeam, + colorTeam).getResults()) { + workPackageGuids.add(workPackageArt.getGuid()); + } + return workPackageGuids; + } + + @Override + public List<Integer> getRelatedTeamWorkflowUuidsBasedOnTeamDefsAisAndVersions(List<AtsAttributeQuery> teamWorkflowAttr) { + AtsQueryImpl search = new AtsQueryImpl(atsServer); + search.isOfType(AtsArtifactTypes.TeamWorkflow); + if (teamDefUuids != null && !teamDefUuids.isEmpty()) { + search.andTeam(new ArrayList<Long>(teamDefUuids)); + } + if (aiUuids != null && !aiUuids.isEmpty()) { + search.andActionableItem(new ArrayList<Long>(aiUuids)); + } + if (versionUuid != null && versionUuid > 0) { + search.andVersion(versionUuid); + } + return new ArrayList<>(search.getItemIds()); + } + +}
\ No newline at end of file diff --git a/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/query/AtsQueryServiceIimpl.java b/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/query/AtsQueryServiceIimpl.java new file mode 100644 index 00000000000..951fbb7fc33 --- /dev/null +++ b/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/query/AtsQueryServiceIimpl.java @@ -0,0 +1,82 @@ +/******************************************************************************* + * Copyright (c) 2015 Boeing. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.ats.rest.internal.query; + +import java.util.Collection; +import java.util.ArrayList; +import java.util.List; +import org.eclipse.osee.ats.api.IAtsWorkItem; +import org.eclipse.osee.ats.api.query.AtsSearchData; +import org.eclipse.osee.ats.api.query.IAtsQuery; +import org.eclipse.osee.ats.api.query.IAtsQueryService; +import org.eclipse.osee.ats.api.query.IAtsWorkItemFilter; +import org.eclipse.osee.ats.api.user.IAtsUser; +import org.eclipse.osee.ats.api.workflow.WorkItemType; +import org.eclipse.osee.ats.core.query.AtsWorkItemFilter; +import org.eclipse.osee.ats.rest.IAtsServer; + +/** + * @author Donald G. Dunne + */ +public class AtsQueryServiceIimpl implements IAtsQueryService { + + private final IAtsServer atsServer; + + public AtsQueryServiceIimpl(IAtsServer atsServer) { + this.atsServer = atsServer; + } + + @Override + public IAtsQuery createQuery(WorkItemType workItemType, WorkItemType... workItemTypes) { + AtsQueryImpl query = new AtsQueryImpl(atsServer); + query.isOfType(workItemType); + for (WorkItemType type : workItemTypes) { + query.isOfType(type); + } + return query; + } + + @Override + public IAtsWorkItemFilter createFilter(Collection<? extends IAtsWorkItem> workItems) { + return new AtsWorkItemFilter(workItems, atsServer.getServices()); + } + + @Override + public ArrayList<AtsSearchData> getSavedSearches(IAtsUser atsUser, String namespace) { + throw new UnsupportedOperationException("Unsupported on the server"); + } + + @Override + public void saveSearch(IAtsUser atsUser, AtsSearchData data) { + throw new UnsupportedOperationException("Unsupported on the server"); + } + + @Override + public void removeSearch(IAtsUser atsUser, AtsSearchData data) { + throw new UnsupportedOperationException("Unsupported on the server"); + } + + @Override + public AtsSearchData getSearch(IAtsUser atsUser, Long uuid) { + throw new UnsupportedOperationException("Unsupported on the server"); + } + + @Override + public AtsSearchData getSearch(String jsonStr) { + throw new UnsupportedOperationException("Unsupported on the server"); + } + + @Override + public AtsSearchData createSearchData(String namespace, String searchName) { + throw new UnsupportedOperationException("Unsupported on the server"); + } + +} 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 new file mode 100644 index 00000000000..d4ffab8f92c --- /dev/null +++ b/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/user/AtsUser.java @@ -0,0 +1,139 @@ +/******************************************************************************* + * 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 new file mode 100644 index 00000000000..955bd949fc2 --- /dev/null +++ b/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/user/AtsUserServiceImpl.java @@ -0,0 +1,161 @@ +/******************************************************************************* + * 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; + } + +} diff --git a/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/util/ActionPage.java b/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/util/ActionPage.java index 09121d8235a..a846af0425c 100644 --- a/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/util/ActionPage.java +++ b/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/util/ActionPage.java @@ -26,7 +26,7 @@ import org.eclipse.osee.ats.api.workdef.IAtsWidgetDefinition; import org.eclipse.osee.ats.api.workdef.IAtsWorkDefinition; import org.eclipse.osee.ats.api.workflow.IAtsTeamWorkflow; import org.eclipse.osee.ats.api.workflow.state.IAtsStateManager; -import org.eclipse.osee.ats.impl.IAtsServer; +import org.eclipse.osee.ats.rest.IAtsServer; import org.eclipse.osee.framework.core.data.IAttributeType; import org.eclipse.osee.framework.core.data.IOseeBranch; import org.eclipse.osee.framework.core.exception.OseeWrappedException; diff --git a/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/util/ArtifactResolverImpl.java b/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/util/ArtifactResolverImpl.java new file mode 100644 index 00000000000..cdcb36b8404 --- /dev/null +++ b/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/util/ArtifactResolverImpl.java @@ -0,0 +1,107 @@ +/******************************************************************************* + * Copyright (c) 2012 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.util; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; +import org.eclipse.core.runtime.Assert; +import org.eclipse.osee.ats.api.IAtsObject; +import org.eclipse.osee.ats.api.IAtsServices; +import org.eclipse.osee.ats.api.IAtsWorkItem; +import org.eclipse.osee.ats.api.util.IArtifactResolver; +import org.eclipse.osee.ats.core.util.AtsUtilCore; +import org.eclipse.osee.framework.core.data.ArtifactId; +import org.eclipse.osee.framework.core.data.IArtifactType; +import org.eclipse.osee.framework.jdk.core.type.OseeCoreException; +import org.eclipse.osee.orcs.OrcsApi; +import org.eclipse.osee.orcs.data.ArtifactReadable; + +/** + * @author Donald G. Dunne + */ +public class ArtifactResolverImpl implements IArtifactResolver { + + private final IAtsServices services; + private final OrcsApi orcsApi; + + public ArtifactResolverImpl(IAtsServices services, OrcsApi orcsApi) { + this.services = services; + this.orcsApi = orcsApi; + } + + @Override + public ArtifactId get(IAtsObject atsObject) throws OseeCoreException { + if (atsObject instanceof ArtifactReadable) { + return (ArtifactReadable) atsObject; + } + ArtifactReadable artifact = orcsApi.getQueryFactory().fromBranch(AtsUtilCore.getAtsBranch()).andUuid( + atsObject.getUuid()).getResults().getAtMostOneOrNull(); + return artifact; + } + + @Override + @SuppressWarnings("unchecked") + public <A extends ArtifactId> A get(IAtsWorkItem workItem, Class<?> clazz) throws OseeCoreException { + Assert.isNotNull(workItem, "Work Item can not be null"); + ArtifactId artifact = get(workItem); + if (clazz.isInstance(artifact)) { + return (A) artifact; + } + return null; + } + + @Override + @SuppressWarnings("unchecked") + public <A extends ArtifactId> List<A> get(Collection<? extends IAtsWorkItem> workItems, Class<?> clazz) throws OseeCoreException { + Assert.isNotNull(workItems, "Work Items can not be null"); + List<A> arts = new ArrayList<>(); + for (IAtsWorkItem workItem : workItems) { + ArtifactReadable artifact = get(workItem, clazz); + if (artifact != null) { + arts.add((A) artifact); + } + } + return arts; + } + + @Override + public IArtifactType getArtifactType(IAtsWorkItem workItem) { + Assert.isNotNull(workItem, "Work Item can not be null"); + return ((ArtifactReadable) workItem.getStoreObject()).getArtifactType(); + } + + @Override + public boolean isOfType(ArtifactId artifact, IArtifactType artifactType) { + Assert.isNotNull(artifact, "Artifact can not be null"); + Assert.isNotNull(artifactType, "Artifact Type can not be null"); + return ((ArtifactReadable) services.getArtifact(artifact)).isOfType(artifactType); + } + + @Override + public int getTransactionNumber(ArtifactId artifact) { + Assert.isNotNull(artifact, "Artifact can not be null"); + return ((ArtifactReadable) services.getArtifact(artifact)).getTransaction(); + } + + @Override + public boolean isOfType(IAtsObject atsObject, IArtifactType artifactType) { + Assert.isNotNull(atsObject, "ATS Object can not be null"); + Assert.isNotNull(artifactType, "Artifact Type can not be null"); + return isOfType(atsObject.getStoreObject(), artifactType); + } + + @Override + public boolean inheritsFrom(IArtifactType artType, IArtifactType parentArtType) { + return orcsApi.getOrcsTypes().getArtifactTypes().inheritsFrom(artType, parentArtType); + } + +} diff --git a/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/util/AtsArtifactConfigCache.java b/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/util/AtsArtifactConfigCache.java new file mode 100644 index 00000000000..f513deb7465 --- /dev/null +++ b/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/util/AtsArtifactConfigCache.java @@ -0,0 +1,106 @@ +/******************************************************************************* + * 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.util; + +import java.util.List; +import java.util.concurrent.Callable; +import java.util.concurrent.TimeUnit; +import org.eclipse.osee.ats.api.IAtsConfigObject; +import org.eclipse.osee.ats.api.team.IAtsConfigItemFactory; +import org.eclipse.osee.ats.core.config.IAtsConfig; +import org.eclipse.osee.ats.core.util.AtsUtilCore; +import org.eclipse.osee.framework.core.exception.OseeWrappedException; +import org.eclipse.osee.framework.core.util.XResultData; +import org.eclipse.osee.framework.jdk.core.type.OseeCoreException; +import org.eclipse.osee.framework.jdk.core.type.OseeStateException; +import org.eclipse.osee.orcs.OrcsApi; +import org.eclipse.osee.orcs.data.ArtifactReadable; +import com.google.common.cache.Cache; +import com.google.common.cache.CacheBuilder; + +/** + * @author Donald G. Dunne + */ +public class AtsArtifactConfigCache implements IAtsConfig { + + private final IAtsConfigItemFactory configItemFactory; + private final OrcsApi orcsApi; + private final Cache<Long, IAtsConfigObject> uuidCache = + CacheBuilder.newBuilder().expireAfterAccess(5, TimeUnit.MINUTES).build(); + + public AtsArtifactConfigCache(IAtsConfigItemFactory configItemFactory, OrcsApi orcsApi) { + this.configItemFactory = configItemFactory; + this.orcsApi = orcsApi; + } + + @Override + public <A extends IAtsConfigObject> List<A> getByTag(String tag, Class<A> clazz) throws OseeCoreException { + throw new UnsupportedOperationException("AtsArtifactConfigCache.getByTag not supported on server"); + } + + @Override + public <A extends IAtsConfigObject> A getSoleByTag(String tag, Class<A> clazz) throws OseeCoreException { + throw new UnsupportedOperationException("AtsArtifactConfigCache.getSoleByTag not supported on server"); + } + + @Override + public <A extends IAtsConfigObject> List<A> get(Class<A> clazz) throws OseeCoreException { + throw new UnsupportedOperationException("AtsArtifactConfigCache.get not supported on server"); + } + + @Override + public void getReport(XResultData rd) throws OseeCoreException { + throw new OseeStateException("Not Implemented"); + } + + @Override + public void invalidate(IAtsConfigObject configObject) throws OseeCoreException { + uuidCache.invalidate(configObject.getUuid()); + } + + @Override + public final <A extends IAtsConfigObject> List<A> getById(long id, Class<A> clazz) { + throw new UnsupportedOperationException("AtsArtifactConfigCache.getById not supported on server"); + } + + @SuppressWarnings("unchecked") + @Override + public <A extends IAtsConfigObject> A getSoleByUuid(final long uuid, Class<A> clazz) throws OseeCoreException { + IAtsConfigObject atsConfigObject = null; + try { + atsConfigObject = uuidCache.get(uuid, new Callable<IAtsConfigObject>() { + + @Override + public IAtsConfigObject call() throws Exception { + ArtifactReadable artifact = orcsApi.getQueryFactory().fromBranch(AtsUtilCore.getAtsBranch()).andUuid( + uuid).getResults().getOneOrNull(); + if (artifact == null) { + throw new OseeStateException("Artifact of %d of class %s is not found", uuid, clazz.getTypeName()); + } + IAtsConfigObject atsConfigObject = configItemFactory.getConfigObject(artifact); + if (atsConfigObject == null) { + throw new OseeStateException("Artifact of %d is not of class %s", uuid, clazz.getTypeName()); + } + return atsConfigObject; + } + }); + } catch (Exception ex) { + throw new OseeWrappedException(ex); + } + return atsConfigObject != null ? (A) atsConfigObject : null; + } + + @Override + public IAtsConfigObject getSoleByUuid(long uuid) throws OseeCoreException { + return getSoleByUuid(uuid, IAtsConfigObject.class); + } + +} diff --git a/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/util/AtsAttributeResolverServiceImpl.java b/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/util/AtsAttributeResolverServiceImpl.java new file mode 100644 index 00000000000..63c7cd6b5e2 --- /dev/null +++ b/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/util/AtsAttributeResolverServiceImpl.java @@ -0,0 +1,227 @@ +/******************************************************************************* + * 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.util; + +import java.util.ArrayList; +import java.util.Collection; +import org.eclipse.osee.ats.api.IAtsObject; +import org.eclipse.osee.ats.api.IAtsWorkItem; +import org.eclipse.osee.ats.api.util.IAtsChangeSet; +import org.eclipse.osee.ats.api.workdef.IAtsWidgetDefinition; +import org.eclipse.osee.ats.api.workdef.IAttributeResolver; +import org.eclipse.osee.ats.api.workflow.IAttribute; +import org.eclipse.osee.framework.core.data.ArtifactId; +import org.eclipse.osee.framework.core.data.IAttributeType; +import org.eclipse.osee.framework.jdk.core.type.OseeCoreException; +import org.eclipse.osee.framework.jdk.core.type.OseeStateException; +import org.eclipse.osee.framework.jdk.core.util.Conditions; +import org.eclipse.osee.framework.jdk.core.util.Strings; +import org.eclipse.osee.logger.Log; +import org.eclipse.osee.orcs.OrcsApi; +import org.eclipse.osee.orcs.data.ArtifactReadable; +import org.eclipse.osee.orcs.data.AttributeReadable; + +/** + * @author Donald G. Dunne + */ +public class AtsAttributeResolverServiceImpl implements IAttributeResolver { + + private OrcsApi orcsApi; + private Log logger; + + public void setLogger(Log logger) { + this.logger = logger; + } + + public void setOrcsApi(OrcsApi orcsApi) { + this.orcsApi = orcsApi; + } + + private ArtifactReadable getArtifact(IAtsObject atsObject) { + return (ArtifactReadable) atsObject.getStoreObject(); + } + + private ArtifactReadable getArtifact(ArtifactId artifact) { + return (ArtifactReadable) artifact; + } + + public void start() throws OseeCoreException { + Conditions.checkNotNull(orcsApi, "OrcsApi"); + logger.info("AtsAttributeResolverServiceImpl started"); + } + + public void stop() { + // + } + + @Override + public boolean isAttributeNamed(String attributeName) { + return getAttributeType(attributeName) != null; + } + + @Override + public String getUnqualifiedName(String attributeName) { + return getAttributeType(attributeName).getUnqualifiedName(); + } + + @Override + public void setXWidgetNameBasedOnAttributeName(String attributeName, IAtsWidgetDefinition widgetDef) { + try { + if (!Strings.isValid(widgetDef.getXWidgetName())) { + widgetDef.setXWidgetName( + AttributeTypeToXWidgetName.getXWidgetName(orcsApi, getAttributeType(attributeName))); + } + } catch (OseeCoreException ex) { + logger.error(ex, "Error setXWidgetNameBasedOnAttributeName - attributeName [%s] widgetDef[%s]", attributeName, + widgetDef); + } + } + + @Override + public String getDescription(String attributeName) { + return getAttributeType(attributeName).getDescription(); + } + + @Override + public IAttributeType getAttributeType(String attributeName) { + IAttributeType attrType = null; + try { + for (IAttributeType type : orcsApi.getOrcsTypes().getAttributeTypes().getAll()) { + if (type.getName().equals(attributeName)) { + attrType = type; + } + } + } catch (OseeCoreException ex) { + logger.error(ex, "Error getting attribute type with name [%s]", attributeName); + } + return attrType; + } + + @Override + public <T> T getSoleAttributeValue(IAtsObject atsObject, IAttributeType attributeType, T defaultReturnValue) throws OseeCoreException { + return getArtifact(atsObject).getSoleAttributeValue(attributeType, defaultReturnValue); + + } + + @Override + public Collection<String> getAttributesToStringList(IAtsObject atsObject, IAttributeType attributeType) throws OseeCoreException { + return getArtifact(atsObject).getAttributeValues(attributeType); + } + + @Override + public boolean isAttributeTypeValid(IAtsWorkItem workItem, IAttributeType attributeType) throws OseeCoreException { + return getArtifact(workItem).isAttributeTypeValid(attributeType); + } + + @Override + public String getSoleAttributeValueAsString(IAtsObject atsObject, IAttributeType attributeType, String defaultValue) throws OseeCoreException { + return getArtifact(atsObject).getSoleAttributeValue(attributeType, defaultValue); + } + + @Override + public void setSoleAttributeValue(IAtsObject atsObject, IAttributeType attributeType, Object value) throws OseeCoreException { + // Sets on Server need to be through transaction + throw new OseeStateException( + "Invalid: Must use setSoleAttributeValue(IAtsWorkItem workItem, IAttributeType attributeType, Object value, IAtsChangeSet changes)"); + } + + @Override + public int getAttributeCount(IAtsWorkItem workItem, IAttributeType attributeType) throws OseeCoreException { + return getArtifact(workItem).getAttributeCount(attributeType); + } + + @Override + public void addAttribute(IAtsWorkItem workItem, IAttributeType attributeType, Object value) throws OseeCoreException { + // Sets on Server need to be through transaction + throw new OseeStateException("Not Implemented"); + } + + @SuppressWarnings("unchecked") + @Override + public <T> Collection<IAttribute<T>> getAttributes(IAtsWorkItem workItem, IAttributeType attributeType) throws OseeCoreException { + Collection<IAttribute<T>> attrs = new ArrayList<>(); + for (AttributeReadable<Object> attr : getArtifact(workItem).getAttributes(attributeType)) { + attrs.add(new AttributeWrapper<T>((AttributeReadable<T>) attr)); + } + return attrs; + } + + @Override + public void deleteSoleAttribute(IAtsWorkItem workItem, IAttributeType attributeType) throws OseeCoreException { + // Sets on Server need to be through transaction + throw new OseeStateException( + "Invalid: Must use deleteSoleAttribute(IAtsWorkItem workItem, IAttributeType attributeType, IAtsChangeSet changes)"); + } + + @Override + public void deleteSoleAttribute(IAtsWorkItem workItem, IAttributeType attributeType, IAtsChangeSet changes) throws OseeCoreException { + changes.deleteSoleAttribute(workItem, attributeType); + } + + @Override + public void setSoleAttributeValue(IAtsObject atsObject, IAttributeType attributeType, Object value, IAtsChangeSet changes) throws OseeCoreException { + changes.setSoleAttributeValue(atsObject, attributeType, value); + } + + @Override + public void addAttribute(IAtsWorkItem workItem, IAttributeType attributeType, Object value, IAtsChangeSet changes) throws OseeCoreException { + changes.addAttribute(workItem, attributeType, value); + } + + @Override + public void deleteSoleAttribute(IAtsWorkItem workItem, IAttributeType attributeType, Object value, IAtsChangeSet changes) throws OseeCoreException { + changes.deleteAttribute(workItem, attributeType, value); + } + + @Override + public <T> void setValue(IAtsWorkItem workItem, IAttribute<String> attr, IAttributeType attributeType, T value, IAtsChangeSet changes) throws OseeCoreException { + changes.setValue(workItem, attr, attributeType, value); + } + + @Override + public <T> void deleteAttribute(IAtsWorkItem workItem, IAttribute<T> attr, IAtsChangeSet changes) throws OseeCoreException { + changes.deleteAttribute(workItem, attr); + } + + @Override + public <T> void deleteAttribute(IAtsWorkItem workItem, IAttribute<T> attr) throws OseeCoreException { // Sets on Server need to be through transaction + throw new OseeStateException( + "Invalid: Must use deleteSoleAttribute(IAtsWorkItem workItem, IAttributeType attributeType, IAtsChangeSet changes)"); + } + + @Override + public <T> void setValue(IAtsWorkItem workItem, IAttribute<String> attr, IAttributeType attributeType, T value) throws OseeCoreException { + // Sets on Server need to be through transaction + throw new OseeStateException( + "Invalid: Must use deleteSoleAttribute(IAtsWorkItem workItem, IAttributeType attributeType, IAtsChangeSet changes)"); + } + + @Override + public <T> T getSoleAttributeValue(ArtifactId artifact, IAttributeType attributeType, T defaultValue) { + return getArtifact(artifact).getSoleAttributeValue(attributeType, defaultValue); + } + + @Override + public <T> Collection<T> getAttributeValues(ArtifactId artifact, IAttributeType attributeType) { + return getArtifact(artifact).getAttributeValues(attributeType); + } + + @Override + public Collection<Object> getAttributeValues(IAtsObject atsObject, IAttributeType attributeType) { + return getAttributeValues(atsObject.getStoreObject(), attributeType); + } + + @Override + public <T> Collection<IAttribute<T>> getAttributes(ArtifactId artifact, IAttributeType attributeType) throws OseeCoreException { + return getArtifact(artifact).getAttributeValues(attributeType); + } + +} diff --git a/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/util/AtsBranchServiceImpl.java b/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/util/AtsBranchServiceImpl.java new file mode 100644 index 00000000000..7bb709db67d --- /dev/null +++ b/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/util/AtsBranchServiceImpl.java @@ -0,0 +1,163 @@ +/******************************************************************************* + * 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.util; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.Date; +import java.util.HashMap; +import java.util.LinkedList; +import java.util.List; +import org.eclipse.osee.ats.api.IAtsServices; +import org.eclipse.osee.ats.api.workflow.IAtsTeamWorkflow; +import org.eclipse.osee.ats.core.util.AbstractAtsBranchService; +import org.eclipse.osee.ats.core.workflow.ITeamWorkflowProvidersLazy; +import org.eclipse.osee.framework.core.data.IOseeBranch; +import org.eclipse.osee.framework.core.data.ITransaction; +import org.eclipse.osee.framework.core.enums.BranchArchivedState; +import org.eclipse.osee.framework.core.enums.BranchState; +import org.eclipse.osee.framework.core.enums.BranchType; +import org.eclipse.osee.framework.core.enums.TransactionDetailsType; +import org.eclipse.osee.framework.core.model.TransactionRecord; +import org.eclipse.osee.framework.jdk.core.type.OseeCoreException; +import org.eclipse.osee.orcs.OrcsApi; +import org.eclipse.osee.orcs.data.ArtifactReadable; +import org.eclipse.osee.orcs.data.BranchReadable; +import org.eclipse.osee.orcs.data.TransactionReadable; +import org.eclipse.osee.orcs.search.BranchQuery; +import org.eclipse.osee.orcs.search.TransactionQuery; + +/** + * @author Donald G. Dunne + */ +public class AtsBranchServiceImpl extends AbstractAtsBranchService { + + private final OrcsApi orcsApi; + private static final HashMap<Integer, List<ITransaction>> commitArtifactIdMap = + new HashMap<Integer, List<ITransaction>>(); + + public AtsBranchServiceImpl(IAtsServices atsServices, OrcsApi orcsApi, ITeamWorkflowProvidersLazy teamWorkflowProvidersLazy) { + super(atsServices, teamWorkflowProvidersLazy); + this.orcsApi = orcsApi; + } + + @Override + public IOseeBranch getCommittedWorkingBranch(IAtsTeamWorkflow teamWf) { + int assocArtId = ((ArtifactReadable) teamWf.getStoreObject()).getLocalId(); + BranchQuery query = orcsApi.getQueryFactory().branchQuery(); + query = + query.andIsOfType(BranchType.WORKING).andStateIs(BranchState.COMMITTED).excludeArchived().andAssociatedArtId( + assocArtId); + return query.getResults().getOneOrNull(); + } + + @Override + public IOseeBranch getWorkingBranchExcludeStates(IAtsTeamWorkflow teamWf, BranchState... negatedBranchStates) { + BranchQuery branchQuery = orcsApi.getQueryFactory().branchQuery(); + if (negatedBranchStates.length > 0) { + Collection<BranchState> statesToSearch = new LinkedList<>(Arrays.asList(BranchState.values())); + statesToSearch.removeAll(Arrays.asList(negatedBranchStates)); + branchQuery.andStateIs(statesToSearch.toArray(new BranchState[statesToSearch.size()])); + } + branchQuery.andIsOfType(BranchType.WORKING); + branchQuery.andAssociatedArtId(((ArtifactReadable) teamWf.getStoreObject()).getLocalId()); + return branchQuery.getResultsAsId().getOneOrNull(); + } + + @Override + public BranchType getBranchType(IOseeBranch branch) { + BranchReadable fullBranch = getBranchByUuid(branch.getUuid()); + return fullBranch.getBranchType(); + } + + @Override + public BranchState getBranchState(IOseeBranch branch) { + BranchQuery query = orcsApi.getQueryFactory().branchQuery(); + BranchReadable fullBranch = query.andUuids(branch.getUuid()).getResults().getExactlyOne(); + return fullBranch.getBranchState(); + } + + /** + * Return true if merge branch exists in DB (whether archived or not) + */ + @Override + public boolean isMergeBranchExists(IAtsTeamWorkflow teamWf, IOseeBranch destinationBranch) throws OseeCoreException { + return isMergeBranchExists(teamWf, getWorkingBranch(teamWf), destinationBranch); + } + + /** + * Method available for optimized checking of merge branches so don't have to re-acquire working branch if already + * have + */ + @Override + public boolean isMergeBranchExists(IAtsTeamWorkflow teamWf, IOseeBranch workingBranch, IOseeBranch destinationBranch) throws OseeCoreException { + if (workingBranch == null) { + return false; + } + BranchQuery query = orcsApi.getQueryFactory().branchQuery(); + query = query.andIsMergeFor(workingBranch.getUuid(), destinationBranch.getUuid()); + return query.getCount() > 0; + } + + @Override + public BranchReadable getBranchByUuid(long branchUuid) { + return orcsApi.getQueryFactory().branchQuery().andUuids(branchUuid).getResults().getExactlyOne(); + } + + @Override + public boolean branchExists(long branchUuid) { + BranchQuery query = orcsApi.getQueryFactory().branchQuery(); + return query.andUuids(branchUuid).getCount() > 0; + } + + @Override + public BranchArchivedState getArchiveState(IOseeBranch branch) { + BranchReadable fullBranch = getBranchByUuid(branch.getUuid()); + return fullBranch.getArchiveState(); + } + + @Override + public Date getTimeStamp(ITransaction transaction) { + return ((TransactionRecord) transaction).getTimeStamp(); + } + + @Override + public Collection<ITransaction> getCommittedArtifactTransactionIds(IAtsTeamWorkflow teamWf) { + ArtifactReadable artifactReadable = (ArtifactReadable) teamWf.getStoreObject(); + List<ITransaction> transactionIds = commitArtifactIdMap.get(artifactReadable.getUuid()); + // Cache the transactionIds first time through. Other commits will be added to cache as they + // happen in this client or as remote commit events come through + if (transactionIds == null) { + transactionIds = new ArrayList<>(5); + TransactionQuery txQuery = orcsApi.getQueryFactory().transactionQuery(); + txQuery.andCommitIds(artifactReadable.getLocalId()); + for (TransactionReadable tx : txQuery.getResults()) { + transactionIds.add(tx); + } + commitArtifactIdMap.put(artifactReadable.getLocalId(), transactionIds); + } + return transactionIds; + } + + @Override + public IOseeBranch getParentBranch(IOseeBranch branch) { + BranchQuery query = orcsApi.getQueryFactory().branchQuery(); + BranchReadable fullBranch = query.andUuids(branch.getUuid()).getResults().getExactlyOne(); + return getBranchByUuid(fullBranch.getParentBranch()); + } + + @Override + public ITransaction getBaseTransaction(IOseeBranch branch) { + TransactionQuery txQuery = orcsApi.getQueryFactory().transactionQuery(); + return txQuery.andBranch(branch).andIs(TransactionDetailsType.Baselined).getResults().getExactlyOne(); + } +} diff --git a/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/util/AtsChangeSet.java b/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/util/AtsChangeSet.java new file mode 100644 index 00000000000..81d224afea9 --- /dev/null +++ b/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/util/AtsChangeSet.java @@ -0,0 +1,314 @@ +/******************************************************************************* + * 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.util; + +import java.util.Collection; +import java.util.HashSet; +import java.util.List; +import java.util.Set; +import org.eclipse.osee.ats.api.IAtsObject; +import org.eclipse.osee.ats.api.IAtsWorkItem; +import org.eclipse.osee.ats.api.notify.IAtsNotifier; +import org.eclipse.osee.ats.api.user.IAtsUser; +import org.eclipse.osee.ats.api.util.IExecuteListener; +import org.eclipse.osee.ats.api.workdef.IAttributeResolver; +import org.eclipse.osee.ats.api.workdef.RuleEventType; +import org.eclipse.osee.ats.api.workflow.IAttribute; +import org.eclipse.osee.ats.api.workflow.log.IAtsLogFactory; +import org.eclipse.osee.ats.api.workflow.state.IAtsStateFactory; +import org.eclipse.osee.ats.api.workflow.state.IAtsStateManager; +import org.eclipse.osee.ats.core.util.AbstractAtsChangeSet; +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.AttributeId; +import org.eclipse.osee.framework.core.data.IArtifactType; +import org.eclipse.osee.framework.core.data.IAttributeType; +import org.eclipse.osee.framework.core.data.IRelationTypeSide; +import org.eclipse.osee.framework.core.data.ITransaction; +import org.eclipse.osee.framework.jdk.core.type.OseeArgumentException; +import org.eclipse.osee.framework.jdk.core.type.OseeCoreException; +import org.eclipse.osee.framework.jdk.core.type.OseeStateException; +import org.eclipse.osee.framework.jdk.core.util.Conditions; +import org.eclipse.osee.orcs.OrcsApi; +import org.eclipse.osee.orcs.data.ArtifactReadable; +import org.eclipse.osee.orcs.data.AttributeReadable; +import org.eclipse.osee.orcs.data.TransactionReadable; +import org.eclipse.osee.orcs.transaction.TransactionBuilder; + +/** + * @author Donald G. Dunne + */ +public class AtsChangeSet extends AbstractAtsChangeSet { + + private TransactionBuilder transaction; + + private final IAttributeResolver attributeResolver; + private final OrcsApi orcsApi; + private final IAtsStateFactory stateFactory; + private final IAtsLogFactory logFactory; + private final IAtsNotifier notifier; + + private final IAtsServer atsServer; + + public AtsChangeSet(IAtsServer atsServer, IAttributeResolver attributeResolver, OrcsApi orcsApi, IAtsStateFactory stateFactory, IAtsLogFactory logFactory, String comment, IAtsUser user, IAtsNotifier notifier) { + super(comment, user); + this.atsServer = atsServer; + this.attributeResolver = attributeResolver; + this.orcsApi = orcsApi; + this.stateFactory = stateFactory; + this.logFactory = logFactory; + this.notifier = notifier; + } + + public TransactionBuilder getTransaction() throws OseeCoreException { + if (transaction == null) { + transaction = + orcsApi.getTransactionFactory().createTransaction(AtsUtilCore.getAtsBranch(), getUser(user), comment); + } + return transaction; + } + + private ArtifactReadable getUser(IAtsUser user) { + if (user.getStoreObject() instanceof ArtifactReadable) { + return (ArtifactReadable) user.getStoreObject(); + } + return orcsApi.getQueryFactory().fromBranch(AtsUtilCore.getAtsBranch()).andUuid( + user.getUuid()).getResults().getExactlyOne(); + } + + @Override + public ITransaction execute() throws OseeCoreException { + Conditions.checkNotNull(comment, "comment"); + if (objects.isEmpty() && deleteObjects.isEmpty()) { + throw new OseeArgumentException("objects/deleteObjects cannot be empty"); + } + for (Object obj : objects) { + if (obj instanceof IAtsWorkItem) { + IAtsWorkItem workItem = (IAtsWorkItem) obj; + IAtsStateManager stateMgr = workItem.getStateMgr(); + if (stateMgr.isDirty()) { + stateFactory.writeToStore(user, workItem, this); + } + if (workItem.getLog().isDirty()) { + logFactory.writeToStore(workItem, attributeResolver, this); + } + } + } + for (Object obj : deleteObjects) { + if (obj instanceof IAtsWorkItem) { + ArtifactReadable artifact = getArtifact(obj); + getTransaction().deleteArtifact(artifact); + } else { + throw new OseeArgumentException("AtsChangeSet: Unhandled deleteObject type: " + obj); + } + } + TransactionReadable transactionReadable = getTransaction().commit(); + for (IExecuteListener listener : listeners) { + listener.changesStored(this); + } + notifier.sendNotifications(getNotifications()); + + if (!workItemsCreated.isEmpty()) { + WorkflowRuleRunner runner = new WorkflowRuleRunner(RuleEventType.CreateWorkflow, workItemsCreated, atsServer); + runner.run(); + } + return transactionReadable; + } + + @Override + public void deleteSoleAttribute(IAtsWorkItem workItem, IAttributeType attributeType) throws OseeCoreException { + getTransaction().deleteSoleAttribute(getArtifact(workItem), attributeType); + add(workItem); + } + + @Override + public void setSoleAttributeValue(IAtsWorkItem workItem, IAttributeType attributeType, String value) throws OseeCoreException { + ArtifactReadable artifact = getArtifact(workItem); + if (!artifact.getSoleAttributeValue(attributeType, "").equals(value)) { + getTransaction().setSoleAttributeValue(artifact, attributeType, value); + add(workItem); + } + } + + @Override + public void setSoleAttributeValue(IAtsObject atsObject, IAttributeType attributeType, Object value) throws OseeCoreException { + getTransaction().setSoleAttributeValue(getArtifact(atsObject), attributeType, value); + add(atsObject); + } + + @Override + public void deleteAttribute(IAtsObject atsObject, IAttributeType attributeType, Object value) throws OseeCoreException { + getTransaction().deleteAttributesWithValue(getArtifact(atsObject), attributeType, value); + add(atsObject); + } + + @Override + public <T> void setValue(IAtsWorkItem workItem, IAttribute<String> attr, IAttributeType attributeType, T value) throws OseeCoreException { + ArtifactId artifactId = getArtifact(workItem); + getTransaction().setAttributeById(artifactId, new AttributeIdWrapper(attr), value); + add(workItem); + } + + @Override + public <T> void deleteAttribute(IAtsWorkItem workItem, IAttribute<T> attr) throws OseeCoreException { + getTransaction().deleteByAttributeId(getArtifact(workItem), new AttributeIdWrapper(attr)); + add(workItem); + } + + @Override + public boolean isAttributeTypeValid(IAtsWorkItem workItem, IAttributeType attributeType) { + ArtifactReadable artifact = getArtifact(workItem); + return artifact.getValidAttributeTypes().contains(attributeType); + } + + @Override + public void addAttribute(IAtsObject atsObject, IAttributeType attributeType, Object value) throws OseeCoreException { + ArtifactReadable artifact = getArtifact(atsObject); + getTransaction().createAttributeFromString(artifact, attributeType, String.valueOf(value)); + add(atsObject); + } + + @Override + public ArtifactId createArtifact(IArtifactType artifactType, String name) { + ArtifactId artifact = getTransaction().createArtifact(artifactType, name); + add(artifact); + return artifact; + } + + @Override + public void deleteAttributes(IAtsObject atsObject, IAttributeType attributeType) { + ArtifactReadable artifact = getArtifact(atsObject); + getTransaction().deleteAttributes(artifact, attributeType); + add(atsObject); + } + + @Override + public ArtifactId createArtifact(IArtifactType artifactType, String name, String guid) { + ArtifactId artifact = getTransaction().createArtifact(artifactType, name, guid); + add(artifact); + return artifact; + } + + @Override + public ArtifactId createArtifact(IArtifactType artifactType, String name, String guid, Long uuid) { + ArtifactId artifact = getTransaction().createArtifact(artifactType, name, guid, uuid); + add(artifact); + return artifact; + } + + @Override + public void relate(Object object1, IRelationTypeSide relationSide, Object object2) { + getTransaction().relate(getArtifact(object1), relationSide, getArtifact(object2)); + add(object1); + } + + private ArtifactReadable getArtifact(Object object) { + ArtifactReadable artifact = null; + if (object instanceof ArtifactReadable) { + artifact = (ArtifactReadable) object; + } else if (object instanceof IAtsObject) { + artifact = (ArtifactReadable) ((IAtsObject) object).getStoreObject(); + } + return artifact; + } + + @Override + public void unrelateAll(Object object, IRelationTypeSide relationType) { + ArtifactReadable artifact = getArtifact(object); + getTransaction().unrelateFromAll(relationType, artifact); + add(object); + } + + @Override + public void setRelation(Object object1, IRelationTypeSide relationType, Object object2) { + unrelateAll(object1, relationType); + relate(object1, relationType, object2); + add(object1); + } + + @Override + public void setRelations(Object object, IRelationTypeSide relationSide, Collection<? extends Object> objects) { + if (!relationSide.getSide().isSideA()) { + throw new UnsupportedOperationException("Can only set relations from A to B side"); + } + ArtifactReadable artifact = getArtifact(object); + Set<ArtifactReadable> artifacts = new HashSet<>(objects.size()); + for (Object obj : objects) { + ArtifactReadable art = getArtifact(obj); + if (art != null) { + artifacts.add(art); + } + } + if (!relationSide.getSide().isSideA()) { + getTransaction().setRelations(artifact, relationSide, artifacts); + } + add(object); + } + + public void unrelate(Object object1, IRelationTypeSide relationType, Object object2) { + getTransaction().unrelate(getArtifact(object1), relationType, getArtifact(object2)); + add(object1); + } + + @Override + public <T> void setAttribute(IAtsWorkItem workItem, int attributeId, T value) { + ArtifactReadable artifact = getArtifact(workItem); + boolean found = false; + for (AttributeReadable<Object> attribute : artifact.getAttributes()) { + if (attribute.getGammaId() == attributeId) { + getTransaction().setAttributeById(artifact, attribute, value); + found = true; + break; + } + } + if (!found) { + throw new OseeStateException("Attribute Id %d does not exist on Artifact %s", attributeId, workItem); + } + add(workItem); + } + + @Override + public void deleteArtifact(ArtifactId artifact) { + getTransaction().deleteArtifact(artifact); + add(artifact); + } + + @Override + public void setValues(IAtsObject atsObject, IAttributeType attrType, List<String> values) { + ArtifactReadable artifact = getArtifact(atsObject); + getTransaction().setAttributesFromStrings(artifact, attrType, values); + add(artifact); + } + + @Override + public <T> void setAttribute(ArtifactId artifact, int attrId, T value) { + for (AttributeReadable<?> attribute : getArtifact(artifact).getAttributes()) { + if (attribute.getLocalId() == attrId) { + getTransaction().setAttributeById(getArtifact(artifact), attribute, value); + } + } + } + + @Override + public void setSoleAttributeValue(ArtifactId artifact, IAttributeType attrType, String value) { + ArtifactReadable art = getArtifact(artifact); + getTransaction().setSoleAttributeValue(art, attrType, value); + add(art); + } + + @Override + public void deleteAttribute(ArtifactId artifact, IAttribute<?> attr) { + AttributeId attribute = ((ArtifactReadable) artifact).getAttributeById(attr.getId()); + getTransaction().deleteByAttributeId(artifact, attribute); + add(artifact); + } +} diff --git a/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/util/AtsRelationResolverServiceImpl.java b/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/util/AtsRelationResolverServiceImpl.java new file mode 100644 index 00000000000..99c230b8b5b --- /dev/null +++ b/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/util/AtsRelationResolverServiceImpl.java @@ -0,0 +1,156 @@ +/******************************************************************************* + * 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.util; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; +import org.eclipse.osee.ats.api.IAtsObject; +import org.eclipse.osee.ats.api.IAtsWorkItem; +import org.eclipse.osee.ats.api.data.AtsArtifactTypes; +import org.eclipse.osee.ats.api.workdef.IRelationResolver; +import org.eclipse.osee.ats.rest.IAtsServer; +import org.eclipse.osee.framework.core.data.ArtifactId; +import org.eclipse.osee.framework.core.data.IRelationTypeSide; +import org.eclipse.osee.framework.core.exception.ArtifactDoesNotExist; +import org.eclipse.osee.orcs.data.ArtifactReadable; + +/** + * @author Donald G. Dunne + */ +public class AtsRelationResolverServiceImpl implements IRelationResolver { + + private final IAtsServer atsServer; + + public AtsRelationResolverServiceImpl(IAtsServer atsServer) { + this.atsServer = atsServer; + } + + @Override + public Collection<ArtifactId> getRelated(ArtifactId artifact, IRelationTypeSide relationType) { + List<ArtifactId> results = new ArrayList<>(); + if (artifact instanceof ArtifactReadable) { + for (ArtifactReadable art : ((ArtifactReadable) artifact).getRelated(relationType)) { + results.add(art); + } + } else if (artifact instanceof IAtsObject) { + IAtsObject iAtsObject = (IAtsObject) artifact; + for (ArtifactReadable art : ((ArtifactReadable) iAtsObject.getStoreObject()).getRelated(relationType)) { + results.add(art); + } + } + return results; + } + + @SuppressWarnings("unchecked") + @Override + public <T extends IAtsObject> Collection<T> getRelated(IAtsObject atsObject, IRelationTypeSide relationType, Class<T> clazz) { + List<T> results = new ArrayList<>(); + ArtifactReadable useArt = getArtifact(atsObject); + if (useArt != null) { + for (ArtifactReadable art : useArt.getRelated(relationType)) { + IAtsObject object = getAtsObject(art); + if (object != null) { + results.add((T) object); + } + } + } + return results; + } + + @Override + public boolean areRelated(ArtifactId artifact1, IRelationTypeSide relationType, ArtifactId artifact2) { + boolean related = false; + if ((artifact1 instanceof ArtifactReadable) && (artifact2 instanceof ArtifactReadable)) { + related = ((ArtifactReadable) artifact1).areRelated(relationType, (ArtifactReadable) artifact2); + } + return related; + } + + @Override + public ArtifactId getRelatedOrNull(ArtifactId artifact, IRelationTypeSide relationType) { + ArtifactId related = null; + try { + related = ((ArtifactReadable) artifact).getRelated(relationType).getAtMostOneOrNull(); + } catch (ArtifactDoesNotExist ex) { + // do nothing + } + return related; + } + + @Override + public boolean areRelated(IAtsObject atsObject1, IRelationTypeSide relationType, IAtsObject atsObject2) { + boolean related = false; + ArtifactReadable useArt1 = getArtifact(atsObject1); + ArtifactReadable useArt2 = getArtifact(atsObject2); + if (useArt1 != null && useArt2 != null) { + related = useArt1.areRelated(relationType, useArt2); + } + return related; + } + + @SuppressWarnings("unchecked") + @Override + public <T> T getRelatedOrNull(IAtsObject atsObject, IRelationTypeSide relationType, Class<T> clazz) { + T related = null; + ArtifactReadable art = getArtifact(atsObject); + if (art != null) { + try { + ArtifactReadable artifact = art.getRelated(relationType).getOneOrNull(); + if (artifact != null) { + IAtsObject object = getAtsObject(artifact); + if (object != null) { + related = (T) object; + } + } + } catch (ArtifactDoesNotExist ex) { + // do nothing + } + } + return related; + } + + private IAtsObject getAtsObject(ArtifactReadable artifact) { + IAtsObject result = null; + if (artifact.isOfType(AtsArtifactTypes.AbstractWorkflowArtifact)) { + result = atsServer.getWorkItemFactory().getWorkItem(artifact); + } else if (atsServer.getConfigItemFactory().isAtsConfigArtifact(artifact)) { + result = atsServer.getConfigItemFactory().getConfigObject(artifact); + } else if (artifact.isOfType(AtsArtifactTypes.Action)) { + result = atsServer.getWorkItemFactory().getAction(artifact); + } + return result; + } + + private ArtifactReadable getArtifact(Object object) { + ArtifactReadable useArt = null; + if (object instanceof ArtifactReadable) { + useArt = (ArtifactReadable) object; + } else if (object instanceof IAtsObject) { + IAtsObject atsObject = (IAtsObject) object; + if (atsObject.getStoreObject() instanceof ArtifactReadable) { + useArt = (ArtifactReadable) atsObject.getStoreObject(); + } + } + return useArt; + } + + @Override + public int getRelatedCount(IAtsWorkItem workItem, IRelationTypeSide relationType) { + ArtifactReadable artifact = getArtifact(workItem); + int count = 0; + if (artifact != null) { + count = artifact.getRelatedCount(relationType); + } + return count; + } + +} diff --git a/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/util/AtsReviewServiceImpl.java b/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/util/AtsReviewServiceImpl.java new file mode 100644 index 00000000000..d8116471b05 --- /dev/null +++ b/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/util/AtsReviewServiceImpl.java @@ -0,0 +1,93 @@ +/******************************************************************************* + * 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.util; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.Date; +import java.util.List; +import org.eclipse.osee.ats.api.IAtsWorkItem; +import org.eclipse.osee.ats.api.data.AtsAttributeTypes; +import org.eclipse.osee.ats.api.data.AtsRelationTypes; +import org.eclipse.osee.ats.api.review.IAtsAbstractReview; +import org.eclipse.osee.ats.api.review.IAtsDecisionReview; +import org.eclipse.osee.ats.api.review.IAtsReviewService; +import org.eclipse.osee.ats.api.user.IAtsUser; +import org.eclipse.osee.ats.api.util.IAtsChangeSet; +import org.eclipse.osee.ats.api.workdef.ReviewBlockType; +import org.eclipse.osee.ats.api.workflow.IAtsTeamWorkflow; +import org.eclipse.osee.ats.api.workflow.IAtsWorkItemService; +import org.eclipse.osee.ats.rest.IAtsServer; +import org.eclipse.osee.ats.rest.util.IArtifactProvider; +import org.eclipse.osee.framework.jdk.core.type.OseeCoreException; +import org.eclipse.osee.framework.jdk.core.type.OseeStateException; +import org.eclipse.osee.orcs.data.ArtifactReadable; + +/** + * @author Donald G. Dunne + */ +public class AtsReviewServiceImpl implements IAtsReviewService { + + private final IArtifactProvider artifactProvider; + private final IAtsWorkItemService workItemService; + private final IAtsServer atsServer; + + public AtsReviewServiceImpl(IAtsServer atsServer, IArtifactProvider artifactProvider, IAtsWorkItemService workItemService) { + this.atsServer = atsServer; + this.artifactProvider = artifactProvider; + this.workItemService = workItemService; + } + + @Override + public boolean isValidationReviewRequired(IAtsWorkItem workItem) throws OseeCoreException { + boolean required = false; + if (workItem.isTeamWorkflow()) { + required = + artifactProvider.getArtifact(workItem).getSoleAttributeValue(AtsAttributeTypes.ValidationRequired, false); + } + return required; + } + + @Override + public IAtsDecisionReview createValidateReview(IAtsTeamWorkflow teamWf, boolean force, Date transitionDate, IAtsUser transitionUser, IAtsChangeSet changes) throws OseeCoreException { + // TODO Implement this + throw new OseeStateException("Not Implemented Yet"); + } + + @Override + public Collection<IAtsAbstractReview> getReviewsFromCurrentState(IAtsTeamWorkflow teamWf) throws OseeCoreException { + return workItemService.getReviews(teamWf, teamWf.getStateMgr().getCurrentState()); + } + + @Override + public ReviewBlockType getReviewBlockType(IAtsAbstractReview review) throws OseeCoreException { + String blockStr = + artifactProvider.getArtifact(review).getSoleAttributeAsString(AtsAttributeTypes.ReviewBlocks, + ReviewBlockType.None.name()); + return ReviewBlockType.valueOf(blockStr); + } + + @Override + public boolean isStandAloneReview(IAtsAbstractReview review) { + return artifactProvider.getArtifact(review).getAttributeCount(AtsAttributeTypes.ActionableItem) > 0; + } + + @Override + public Collection<IAtsAbstractReview> getReviews(IAtsTeamWorkflow teamWf) { + List<IAtsAbstractReview> reviews = new ArrayList<>(); + + for (ArtifactReadable reviewArt : ((ArtifactReadable) teamWf.getStoreObject()).getRelated(AtsRelationTypes.TeamWorkflowToReview_Review)) { + reviews.add(atsServer.getWorkItemFactory().getReview(reviewArt)); + } + return reviews; + } + +} diff --git a/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/util/AtsStoreServiceImpl.java b/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/util/AtsStoreServiceImpl.java new file mode 100644 index 00000000000..f69060db9ea --- /dev/null +++ b/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/util/AtsStoreServiceImpl.java @@ -0,0 +1,100 @@ +/******************************************************************************* + * 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.util; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import org.eclipse.osee.ats.api.IAtsObject; +import org.eclipse.osee.ats.api.IAtsWorkItem; +import org.eclipse.osee.ats.api.notify.IAtsNotifier; +import org.eclipse.osee.ats.api.user.IAtsUser; +import org.eclipse.osee.ats.api.util.IAtsChangeSet; +import org.eclipse.osee.ats.api.util.IAtsStoreService; +import org.eclipse.osee.ats.api.workdef.IAttributeResolver; +import org.eclipse.osee.ats.api.workflow.log.IAtsLogFactory; +import org.eclipse.osee.ats.api.workflow.state.IAtsStateFactory; +import org.eclipse.osee.ats.core.util.AtsObjects; +import org.eclipse.osee.ats.core.util.AtsUtilCore; +import org.eclipse.osee.ats.rest.IAtsServer; +import org.eclipse.osee.orcs.data.ArtifactReadable; + +/** + * @author Donald G. Dunne + */ +public class AtsStoreServiceImpl implements IAtsStoreService { + + private final IAttributeResolver attributeResolver; + private final IAtsStateFactory stateFactory; + private final IAtsLogFactory logFactory; + private final IAtsNotifier notifier; + private final IAtsServer atsServer; + private static Map<String, Long> guidToUuid; + + public AtsStoreServiceImpl(IAttributeResolver attributeResolver, IAtsServer atsServer, IAtsStateFactory stateFactory, IAtsLogFactory logFactory, IAtsNotifier notifier) { + this.atsServer = atsServer; + this.attributeResolver = attributeResolver; + this.logFactory = logFactory; + this.stateFactory = stateFactory; + this.notifier = notifier; + } + + @Override + public IAtsChangeSet createAtsChangeSet(String comment, IAtsUser user) { + return new AtsChangeSet(atsServer, attributeResolver, atsServer.getOrcsApi(), stateFactory, logFactory, comment, + user, notifier); + } + + @Override + public IAtsChangeSet createAtsChangeSet(String comment) { + return createAtsChangeSet(comment, atsServer.getUserService().getCurrentUser()); + } + + @Override + public List<IAtsWorkItem> reload(Collection<IAtsWorkItem> inWorkWorkflows) { + List<IAtsWorkItem> workItems = new ArrayList<>(inWorkWorkflows.size()); + List<String> guids = AtsObjects.toGuids(inWorkWorkflows); + Iterator<ArtifactReadable> arts = + atsServer.getOrcsApi().getQueryFactory().fromBranch(AtsUtilCore.getAtsBranch()).andGuids( + guids).getResults().iterator(); + while (arts.hasNext()) { + workItems.add(atsServer.getWorkItemFactory().getWorkItem(arts.next())); + } + return workItems; + } + + @Override + public boolean isDeleted(IAtsObject atsObject) { + return ((ArtifactReadable) atsObject.getStoreObject()).isDeleted(); + } + + @Override + public Long getUuidFromGuid(String guid) { + if (guidToUuid == null) { + guidToUuid = new HashMap<>(200); + } + Long result = null; + if (guidToUuid.containsKey(guid)) { + result = guidToUuid.get(guid); + } else { + ArtifactReadable art = atsServer.getArtifactByGuid(guid); + if (art != null) { + result = art.getUuid(); + guidToUuid.put(guid, result); + } + } + return result; + } + +} diff --git a/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/util/AtsWorkDefinitionCacheProvider.java b/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/util/AtsWorkDefinitionCacheProvider.java new file mode 100644 index 00000000000..56f99c24bda --- /dev/null +++ b/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/util/AtsWorkDefinitionCacheProvider.java @@ -0,0 +1,41 @@ +/******************************************************************************* + * 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.util; + +import java.util.concurrent.Callable; +import java.util.concurrent.FutureTask; +import org.eclipse.osee.ats.api.workdef.IAtsWorkDefinitionService; +import org.eclipse.osee.ats.core.util.CacheProvider; +import org.eclipse.osee.ats.core.workdef.AtsWorkDefinitionCache; +import org.eclipse.osee.framework.jdk.core.type.LazyObject; + +/** + * Thread safe loading of ATS Config Objects + * + * @author Donald G. Dunne + */ +public class AtsWorkDefinitionCacheProvider extends LazyObject<AtsWorkDefinitionCache> implements CacheProvider<AtsWorkDefinitionCache> { + + private final IAtsWorkDefinitionService workDefinitionService; + + public AtsWorkDefinitionCacheProvider(IAtsWorkDefinitionService workDefinitionService) { + super(); + this.workDefinitionService = workDefinitionService; + } + + @Override + protected FutureTask<AtsWorkDefinitionCache> createLoaderTask() { + Callable<AtsWorkDefinitionCache> newCallable = new LoadAtsWorkDefinitionCacheCallable(workDefinitionService); + FutureTask<AtsWorkDefinitionCache> newTask = new FutureTask<>(newCallable); + return newTask; + } + +} diff --git a/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/util/AttributeIdWrapper.java b/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/util/AttributeIdWrapper.java new file mode 100644 index 00000000000..d048808a949 --- /dev/null +++ b/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/util/AttributeIdWrapper.java @@ -0,0 +1,32 @@ +/******************************************************************************* + * 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.util; + +import org.eclipse.osee.ats.api.workflow.IAttribute; +import org.eclipse.osee.framework.core.data.AttributeId; + +/** + * @author Donald G Dunne + */ +public class AttributeIdWrapper implements AttributeId { + + private final IAttribute<?> attribute; + + public AttributeIdWrapper(IAttribute<?> attribute) { + this.attribute = attribute; + } + + @Override + public Integer getLocalId() { + return attribute.getId(); + } + +} diff --git a/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/util/AttributeTypeToXWidgetName.java b/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/util/AttributeTypeToXWidgetName.java new file mode 100644 index 00000000000..bbc34a7c3d8 --- /dev/null +++ b/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/util/AttributeTypeToXWidgetName.java @@ -0,0 +1,73 @@ +package org.eclipse.osee.ats.rest.internal.util; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; +import org.eclipse.osee.framework.core.data.IAttributeType; +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.Collections; +import org.eclipse.osee.orcs.OrcsApi; +import org.eclipse.osee.orcs.data.EnumEntry; + +/** + * @author Donald G. Dunne + */ +public class AttributeTypeToXWidgetName { + + public static String getXWidgetName(OrcsApi orcsApi, IAttributeType attributeType) throws OseeCoreException { + int minOccurrence = orcsApi.getOrcsTypes().getAttributeTypes().getMinOccurrences(attributeType); + int maxOccurrence = orcsApi.getOrcsTypes().getAttributeTypes().getMaxOccurrences(attributeType); + String xWidgetName = ""; + String baseType = orcsApi.getOrcsTypes().getAttributeTypes().getBaseAttributeTypeId(attributeType); + if (baseType != null) { + baseType = baseType.toLowerCase(); + if (attributeType.equals(CoreAttributeTypes.AccessContextId)) { + xWidgetName = "XTextFlatDam"; + } else if (baseType.contains("enum")) { + if (maxOccurrence == 1) { + xWidgetName = + "XComboDam(" + Collections.toString(",", getEnumerationValues(orcsApi, attributeType)) + ")"; + } else { + xWidgetName = + "XSelectFromMultiChoiceDam(" + Collections.toString(",", getEnumerationValues(orcsApi, attributeType)) + ")"; + } + } else if (baseType.contains("boolean")) { + if (minOccurrence == 1) { + xWidgetName = "XCheckBoxDam"; + } else { + xWidgetName = "XComboBooleanDam"; + } + } else if (baseType.contains("date")) { + xWidgetName = "XDateDam"; + } else if (baseType.contains("integer")) { + xWidgetName = "XIntegerDam"; + } else if (baseType.contains("floating")) { + xWidgetName = "XFloatDam"; + } else if (baseType.contains("binary")) { + xWidgetName = "XLabelDam"; + } else if (baseType.contains("branchreference")) { + xWidgetName = "XBranchSelectWidget"; + } else if (baseType.contains("artifactreference")) { + xWidgetName = "XListDropViewWithSave"; + } else if (baseType.contains("string")) { + if (maxOccurrence == 1) { + xWidgetName = "XTextDam"; + } else { + xWidgetName = "XStackedDam"; + } + } else { + xWidgetName = "XStackedDam"; + } + } + return xWidgetName; + } + + private static Collection<String> getEnumerationValues(OrcsApi orcsApi, IAttributeType attributeType) { + List<String> values = new ArrayList<>(); + for (EnumEntry entry : orcsApi.getOrcsTypes().getAttributeTypes().getEnumType(attributeType).values()) { + values.add(entry.getName()); + } + return values; + } +} diff --git a/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/util/AttributeWrapper.java b/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/util/AttributeWrapper.java new file mode 100644 index 00000000000..29e214e817b --- /dev/null +++ b/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/util/AttributeWrapper.java @@ -0,0 +1,54 @@ +/******************************************************************************* + * 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.util; + +import org.eclipse.osee.ats.api.workflow.IAttribute; +import org.eclipse.osee.framework.jdk.core.type.OseeCoreException; +import org.eclipse.osee.framework.jdk.core.type.OseeStateException; +import org.eclipse.osee.orcs.data.AttributeReadable; + +/** + * @author Donald G. Dunne + */ +public class AttributeWrapper<T> implements IAttribute<T> { + + private final AttributeReadable<T> attr; + + public AttributeWrapper(AttributeReadable<T> attr) { + this.attr = attr; + } + + @Override + public T getValue() throws OseeCoreException { + return attr.getValue(); + } + + @Override + public Object getData() { + return attr; + } + + @Override + public void delete() throws OseeCoreException { + throw new OseeStateException("Not valid call for server"); + } + + @Override + public void setValue(T value) throws OseeCoreException { + throw new OseeStateException("Not valid call for server"); + } + + @Override + public int getId() { + return attr.getLocalId(); + } + +} diff --git a/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/util/ChangeTypeUtil.java b/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/util/ChangeTypeUtil.java new file mode 100644 index 00000000000..9ded7a27f2f --- /dev/null +++ b/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/util/ChangeTypeUtil.java @@ -0,0 +1,49 @@ +/******************************************************************************* + * Copyright (c) 2011 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.util; + +import org.eclipse.osee.ats.api.IAtsObject; +import org.eclipse.osee.ats.api.data.AtsAttributeTypes; +import org.eclipse.osee.ats.api.team.ChangeType; +import org.eclipse.osee.ats.api.util.IAtsChangeSet; +import org.eclipse.osee.framework.jdk.core.type.OseeCoreException; +import org.eclipse.osee.orcs.data.ArtifactReadable; + +/** + * @author Donald G. Dunne + */ +public class ChangeTypeUtil { + + public static String getChangeTypeStr(ArtifactReadable artifact) throws OseeCoreException { + ChangeType changeType = getChangeType(artifact); + if (changeType == ChangeType.None) { + return ""; + } + return changeType.name(); + } + + public static ChangeType getChangeType(ArtifactReadable artifact) throws OseeCoreException { + return ChangeType.getChangeType(artifact.getSoleAttributeValue(AtsAttributeTypes.ChangeType, "")); + } + + public static ChangeType getChangeType(IAtsObject atsObject) throws OseeCoreException { + return getChangeType((ArtifactReadable) atsObject.getStoreObject()); + } + + public static void setChangeType(IAtsObject artifact, ChangeType changeType, IAtsChangeSet changes) throws OseeCoreException { + if (changeType == ChangeType.None) { + changes.deleteAttributes(artifact, AtsAttributeTypes.ChangeType); + } else { + changes.setSoleAttributeValue(artifact, AtsAttributeTypes.ChangeType, changeType.name()); + } + } + +} diff --git a/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/util/LoadAtsWorkDefinitionCacheCallable.java b/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/util/LoadAtsWorkDefinitionCacheCallable.java new file mode 100644 index 00000000000..8b4d29ddd33 --- /dev/null +++ b/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/util/LoadAtsWorkDefinitionCacheCallable.java @@ -0,0 +1,32 @@ +/******************************************************************************* + * 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.util; + +import java.util.concurrent.Callable; +import org.eclipse.osee.ats.api.workdef.IAtsWorkDefinitionService; +import org.eclipse.osee.ats.core.workdef.AtsWorkDefinitionCache; + +/** + * @author Donald G. Dunne + */ +public class LoadAtsWorkDefinitionCacheCallable implements Callable<AtsWorkDefinitionCache> { + + public LoadAtsWorkDefinitionCacheCallable(IAtsWorkDefinitionService workDefinitionService) { + super(); + } + + @Override + public AtsWorkDefinitionCache call() throws Exception { + AtsWorkDefinitionCache cache = new AtsWorkDefinitionCache(); + return cache; + } + +}
\ No newline at end of file diff --git a/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/util/RestUtil.java b/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/util/RestUtil.java index bba383d73ca..26b2e8ff5d0 100644 --- a/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/util/RestUtil.java +++ b/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/util/RestUtil.java @@ -18,7 +18,7 @@ import javax.ws.rs.core.Response; import javax.ws.rs.core.Response.Status; import javax.ws.rs.core.UriBuilder; import org.eclipse.osee.ats.api.IAtsWorkItem; -import org.eclipse.osee.ats.impl.IAtsServer; +import org.eclipse.osee.ats.rest.IAtsServer; import org.eclipse.osee.ats.rest.internal.AtsApplication; import org.eclipse.osee.framework.jdk.core.type.ViewModel; import org.eclipse.osee.framework.jdk.core.util.Lib; diff --git a/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/util/WorkflowRuleRunner.java b/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/util/WorkflowRuleRunner.java new file mode 100644 index 00000000000..672e605f3ba --- /dev/null +++ b/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/util/WorkflowRuleRunner.java @@ -0,0 +1,123 @@ +/******************************************************************************* + * Copyright (c) 2015 Boeing. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.ats.rest.internal.util; + +import java.util.List; +import java.util.logging.Level; +import org.eclipse.osee.ats.api.IAtsWorkItem; +import org.eclipse.osee.ats.api.ai.IAtsActionableItem; +import org.eclipse.osee.ats.api.util.IAtsChangeSet; +import org.eclipse.osee.ats.api.workdef.IAtsRuleDefinition; +import org.eclipse.osee.ats.api.workdef.IAtsStateDefinition; +import org.eclipse.osee.ats.api.workdef.IAtsWorkDefinition; +import org.eclipse.osee.ats.api.workdef.IExecutableRule; +import org.eclipse.osee.ats.api.workdef.RuleEventType; +import org.eclipse.osee.ats.api.workdef.RunRuleResults; +import org.eclipse.osee.ats.core.users.AtsCoreUsers; +import org.eclipse.osee.ats.rest.IAtsServer; +import org.eclipse.osee.framework.logging.OseeLog; + +/** + * @author Mark Joy + */ +public class WorkflowRuleRunner { + + private final RuleEventType eventType; + private final IAtsServer atsServer; + private final List<IAtsWorkItem> workflowsCreated; + private final RunRuleResults ruleResults; + + public WorkflowRuleRunner(RuleEventType eventType, List<IAtsWorkItem> workflowsCreated, IAtsServer atsServer) { + this(eventType, workflowsCreated, atsServer, new RunRuleResults()); + } + + public WorkflowRuleRunner(RuleEventType eventType, List<IAtsWorkItem> workflowsCreated, IAtsServer atsServer, RunRuleResults ruleResults) { + this.eventType = eventType; + this.workflowsCreated = workflowsCreated; + this.atsServer = atsServer; + this.ruleResults = ruleResults; + } + + public RunRuleResults run() { + IAtsChangeSet changes = + atsServer.getStoreService().createAtsChangeSet("ATS Rule Runner", AtsCoreUsers.SYSTEM_USER); + if (eventType == RuleEventType.CreateWorkflow) { + for (IAtsWorkItem workItem : workflowsCreated) { + if (workItem.isTeamWorkflow()) { + + try { + // check team definition + if ((workItem.getParentTeamWorkflow() != null) && (workItem.getParentTeamWorkflow().getTeamDefinition() != null)) { + for (String teamDefRule : workItem.getParentTeamWorkflow().getTeamDefinition().getRules()) { + IAtsRuleDefinition ruleDefinition = atsServer.getWorkDefAdmin().getRuleDefinition(teamDefRule); + + if ((ruleDefinition != null) && (ruleDefinition.getRuleEvents().contains( + eventType) && ruleDefinition instanceof IExecutableRule)) { + ((IExecutableRule) ruleDefinition).execute(workItem, atsServer.getServices(), changes, + ruleResults); + } + } + } + } catch (Exception ex) { + OseeLog.log(WorkflowRuleRunner.class, Level.SEVERE, ex); + } + + try { + // check actionable items + if ((workItem.getParentTeamWorkflow() != null) && (workItem.getParentTeamWorkflow().getTeamDefinition() != null)) { + for (IAtsActionableItem ai : workItem.getParentTeamWorkflow().getActionableItems()) { + for (String aiRule : ai.getRules()) { + IAtsRuleDefinition ruleDefinition = atsServer.getWorkDefAdmin().getRuleDefinition(aiRule); + + if ((ruleDefinition != null) && (ruleDefinition.getRuleEvents().contains( + eventType) && ruleDefinition instanceof IExecutableRule)) { + ((IExecutableRule) ruleDefinition).execute(workItem, atsServer.getServices(), changes, + ruleResults); + } + } + } + } + } catch (Exception ex) { + OseeLog.log(WorkflowRuleRunner.class, Level.SEVERE, ex); + } + + // check state definition + try { + IAtsWorkDefinition workDef = workItem.getWorkDefinition(); + if (workDef != null) { + IAtsStateDefinition stateDef = + workDef.getStateByName(workItem.getStateMgr().getCurrentStateName()); + for (String teamDefRule : stateDef.getRules()) { + IAtsRuleDefinition ruleDefinition = atsServer.getWorkDefAdmin().getRuleDefinition(teamDefRule); + if (ruleDefinition.getRuleEvents().contains( + eventType) && ruleDefinition instanceof IExecutableRule) { + ((IExecutableRule) ruleDefinition).execute(workItem, atsServer.getServices(), changes, + ruleResults); + } + } + } + } catch (Exception ex) { + OseeLog.log(WorkflowRuleRunner.class, Level.SEVERE, ex); + } + } + } + } + if (!changes.isEmpty()) { + changes.execute(); + } + return ruleResults; + } + + public RunRuleResults getRuleResults() { + return ruleResults; + } + +} diff --git a/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/workdef/AtsWorkDefinitionStoreImpl.java b/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/workdef/AtsWorkDefinitionStoreImpl.java new file mode 100644 index 00000000000..09d744389ba --- /dev/null +++ b/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/workdef/AtsWorkDefinitionStoreImpl.java @@ -0,0 +1,92 @@ +/******************************************************************************* + * 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.workdef; + +import java.util.ArrayList; +import java.util.List; +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.workdef.IAtsWorkDefinitionStore; +import org.eclipse.osee.ats.core.util.AtsUtilCore; +import org.eclipse.osee.framework.core.enums.CoreAttributeTypes; +import org.eclipse.osee.framework.core.enums.QueryOption; +import org.eclipse.osee.framework.jdk.core.type.OseeCoreException; +import org.eclipse.osee.framework.jdk.core.type.Pair; +import org.eclipse.osee.framework.jdk.core.util.Conditions; +import org.eclipse.osee.orcs.OrcsApi; +import org.eclipse.osee.orcs.data.ArtifactReadable; + +/** + * @author Donald G. Dunne + */ +public class AtsWorkDefinitionStoreImpl implements IAtsWorkDefinitionStore { + + private static OrcsApi orcsApi; + + public static void setOrcsApi(OrcsApi orcsApi) { + AtsWorkDefinitionStoreImpl.orcsApi = orcsApi; + } + + public void start() throws OseeCoreException { + Conditions.checkNotNull(orcsApi, "OrcsApi"); + System.out.println("ATS - AtsWorkDefinitionStoreImpl started"); + } + + @Override + public List<Pair<String, String>> getWorkDefinitionStrings() throws OseeCoreException { + List<Pair<String, String>> nameToWorkDefStr = new ArrayList<>(15); + for (ArtifactReadable workDefArt : orcsApi.getQueryFactory().fromBranch(AtsUtilCore.getAtsBranch()).andTypeEquals( + AtsArtifactTypes.WorkDefinition).getResults()) { + nameToWorkDefStr.add( + new Pair<String, String>(workDefArt.getName(), loadWorkDefinitionFromArtifact(workDefArt))); + } + return nameToWorkDefStr; + } + + @Override + public String loadWorkDefinitionString(String workDefId) throws OseeCoreException { + return loadWorkDefinitionFromArtifact(workDefId); + } + + @Override + public boolean isWorkDefinitionExists(String workDefId) throws OseeCoreException { + return loadWorkDefinitionString(workDefId) != null; + } + + private String loadWorkDefinitionFromArtifact(String name) throws OseeCoreException { + ArtifactReadable artifact = orcsApi.getQueryFactory().fromBranch(AtsUtilCore.getAtsBranch()).andTypeEquals( + AtsArtifactTypes.WorkDefinition).and(CoreAttributeTypes.Name, name, + QueryOption.EXACT_MATCH_OPTIONS).getResults().getExactlyOne(); + return loadWorkDefinitionFromArtifact(artifact); + } + + private String loadWorkDefinitionFromArtifact(ArtifactReadable artifact) throws OseeCoreException { + String modelText = null; + if (artifact != null) { + modelText = artifact.getSoleAttributeAsString(AtsAttributeTypes.DslSheet); + } + return modelText; + } + + @SuppressWarnings("unchecked") + @Override + public String loadRuleDefinitionString() throws OseeCoreException { + ArtifactReadable artifact = orcsApi.getQueryFactory().fromBranch(AtsUtilCore.getAtsBranch()).andIds( + AtsArtifactToken.RuleDefinitions).getResults().getOneOrNull(); + if (artifact != null) { + return artifact.getSoleAttributeValue(AtsAttributeTypes.DslSheet, null); + } else { + return null; + } + }; + +} diff --git a/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/workitem/ActionUiResource.java b/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/workitem/ActionUiResource.java index 945739fb4c8..b5cd1ae4633 100644 --- a/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/workitem/ActionUiResource.java +++ b/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/workitem/ActionUiResource.java @@ -21,7 +21,7 @@ import javax.ws.rs.Produces; import javax.ws.rs.core.MediaType; import org.eclipse.osee.ats.api.IAtsWorkItem; import org.eclipse.osee.ats.api.data.AtsArtifactTypes; -import org.eclipse.osee.ats.impl.IAtsServer; +import org.eclipse.osee.ats.rest.IAtsServer; import org.eclipse.osee.ats.rest.internal.util.ActionPage; import org.eclipse.osee.ats.rest.internal.util.RestUtil; import org.eclipse.osee.framework.jdk.core.type.OseeCoreException; diff --git a/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/workitem/AtsActionEndpointImpl.java b/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/workitem/AtsActionEndpointImpl.java index 80eaf5141d3..de0e1bd9b0a 100644 --- a/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/workitem/AtsActionEndpointImpl.java +++ b/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/workitem/AtsActionEndpointImpl.java @@ -36,7 +36,7 @@ import org.eclipse.osee.ats.api.util.IAtsChangeSet; import org.eclipse.osee.ats.api.workflow.AtsActionEndpointApi; import org.eclipse.osee.ats.api.workflow.IAtsAction; import org.eclipse.osee.ats.core.util.AtsUtilCore; -import org.eclipse.osee.ats.impl.IAtsServer; +import org.eclipse.osee.ats.rest.IAtsServer; import org.eclipse.osee.ats.rest.internal.util.RestUtil; import org.eclipse.osee.framework.core.data.IAttributeType; import org.eclipse.osee.framework.jdk.core.util.Strings; diff --git a/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/workitem/AtsProgramService.java b/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/workitem/AtsProgramService.java new file mode 100644 index 00000000000..2664e10ac48 --- /dev/null +++ b/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/workitem/AtsProgramService.java @@ -0,0 +1,198 @@ +/******************************************************************************* + * Copyright (c) 2014 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.workitem; + +import com.google.common.cache.Cache; +import com.google.common.cache.CacheBuilder; +import java.util.ArrayList; +import java.util.Collection; +import java.util.LinkedList; +import java.util.List; +import java.util.concurrent.TimeUnit; +import org.eclipse.osee.ats.api.IAtsWorkItem; +import org.eclipse.osee.ats.api.country.IAtsCountry; +import org.eclipse.osee.ats.api.data.AtsArtifactTypes; +import org.eclipse.osee.ats.api.data.AtsAttributeTypes; +import org.eclipse.osee.ats.api.data.AtsRelationTypes; +import org.eclipse.osee.ats.api.ev.IAtsWorkPackage; +import org.eclipse.osee.ats.api.insertion.IAtsInsertion; +import org.eclipse.osee.ats.api.insertion.IAtsInsertionActivity; +import org.eclipse.osee.ats.api.program.IAtsProgram; +import org.eclipse.osee.ats.api.program.IAtsProgramService; +import org.eclipse.osee.ats.api.team.IAtsTeamDefinition; +import org.eclipse.osee.ats.core.util.AtsUtilCore; +import org.eclipse.osee.ats.rest.IAtsServer; +import org.eclipse.osee.framework.jdk.core.type.ResultSet; +import org.eclipse.osee.framework.jdk.core.util.Strings; +import org.eclipse.osee.orcs.data.ArtifactReadable; +import org.eclipse.osee.orcs.search.QueryBuilder; + +/** + * @author Donald G. Dunne + */ +public class AtsProgramService implements IAtsProgramService { + + private final IAtsServer atsServer; + private final Cache<IAtsTeamDefinition, IAtsProgram> cache = + CacheBuilder.newBuilder().expireAfterAccess(1, TimeUnit.HOURS).build(); + + public AtsProgramService(IAtsServer atsServer) { + this.atsServer = atsServer; + } + + @Override + public IAtsTeamDefinition getTeamDefinition(IAtsProgram atsProgram) { + IAtsTeamDefinition teamDef = atsProgram.getTeamDefinition(); + if (teamDef == null) { + ArtifactReadable artifact = (ArtifactReadable) atsProgram.getStoreObject(); + String teamDefGuid = artifact.getSoleAttributeValue(AtsAttributeTypes.TeamDefinition, null); + if (Strings.isValid(teamDefGuid)) { + teamDef = (IAtsTeamDefinition) atsServer.getArtifactByGuid(teamDefGuid); + } + } + return teamDef; + } + + @Override + public IAtsProgram getProgram(IAtsWorkItem wi) { + IAtsTeamDefinition teamDefinition = wi.getParentTeamWorkflow().getTeamDefinition(); + IAtsProgram program = cache.getIfPresent(teamDefinition); + if (program == null) { + IAtsTeamDefinition topTeamDef = teamDefinition.getTeamDefinitionHoldingVersions(); + QueryBuilder query = atsServer.getQuery(); + query.and(AtsAttributeTypes.TeamDefinition, AtsUtilCore.getGuid(topTeamDef)).andIsOfType( + AtsArtifactTypes.Program); + ArtifactReadable programArt = query.getResults().getOneOrNull(); + program = atsServer.getConfigItemFactory().getProgram(programArt); + cache.put(teamDefinition, program); + } + return program; + } + + @Override + public IAtsProgram getProgramByGuid(String guid) { + ArtifactReadable prgArt = (ArtifactReadable) atsServer.getArtifactById(guid); + return atsServer.getConfigItemFactory().getProgram(prgArt); + } + + @Override + public IAtsCountry getCountry(IAtsProgram atsProgram) { + IAtsCountry country = null; + ArtifactReadable artifact = ((ArtifactReadable) atsProgram.getStoreObject()); + if (artifact != null) { + ArtifactReadable countryArt = + artifact.getRelated(AtsRelationTypes.CountryToProgram_Country).getAtMostOneOrNull(); + if (countryArt != null) { + country = atsServer.getConfigItemFactory().getCountry(countryArt); + } + } + return country; + } + + @Override + public List<IAtsProgram> getPrograms(IAtsCountry atsCountry) { + List<IAtsProgram> programs = new LinkedList<>(); + ArtifactReadable artifact = ((ArtifactReadable) atsCountry.getStoreObject()); + if (artifact != null) { + for (ArtifactReadable related : artifact.getRelated(AtsRelationTypes.CountryToProgram_Program)) { + programs.add(atsServer.getConfigItemFactory().getProgram(related)); + } + } + return programs; + } + + @Override + public IAtsProgram getProgram(Long programUuid) { + return atsServer.getConfigItemFactory().getProgram(atsServer.getArtifact(programUuid)); + } + + @Override + public Collection<IAtsProgram> getPrograms() { + List<IAtsProgram> programs = new ArrayList<>(); + for (ArtifactReadable artifact : atsServer.getOrcsApi().getQueryFactory().fromBranch( + AtsUtilCore.getAtsBranch()).andIsOfType(AtsArtifactTypes.Program).getResults()) { + programs.add(atsServer.getConfigItemFactory().getProgram(artifact)); + } + return programs; + } + + @Override + public Collection<IAtsInsertion> getInsertions(IAtsProgram program) { + List<IAtsInsertion> insertions = new ArrayList<>(); + for (ArtifactReadable artifact : atsServer.getArtifact(program.getUuid()).getRelated( + AtsRelationTypes.ProgramToInsertion_Insertion)) { + insertions.add(atsServer.getConfigItemFactory().getInsertion(artifact)); + } + return insertions; + } + + @Override + public IAtsInsertion getInsertion(Long insertionUuid) { + return atsServer.getConfigItemFactory().getInsertion(atsServer.getArtifact(insertionUuid)); + } + + @Override + public Collection<IAtsInsertionActivity> getInsertionActivities(IAtsInsertion insertion) { + List<IAtsInsertionActivity> insertionActivitys = new ArrayList<>(); + for (ArtifactReadable artifact : atsServer.getArtifact(insertion.getUuid()).getRelated( + AtsRelationTypes.InsertionToInsertionActivity_InsertionActivity)) { + insertionActivitys.add(atsServer.getConfigItemFactory().getInsertionActivity(artifact)); + } + return insertionActivitys; + } + + @Override + public IAtsInsertionActivity getInsertionActivity(Long insertionActivityUuid) { + return atsServer.getConfigItemFactory().getInsertionActivity(atsServer.getArtifact(insertionActivityUuid)); + } + + @Override + public IAtsWorkPackage getWorkPackage(Long workPackageUuid) { + throw new UnsupportedOperationException("getWorkPackage not supported on server"); + } + + @Override + public IAtsInsertionActivity getInsertionActivity(IAtsWorkPackage workPackage) { + ArtifactReadable wpArt = atsServer.getArtifact(workPackage.getUuid()); + ResultSet<ArtifactReadable> related = + wpArt.getRelated(AtsRelationTypes.InsertionActivityToWorkPackage_InsertionActivity); + if (related.size() > 0) { + return atsServer.getConfigItemFactory().getInsertionActivity(related.iterator().next()); + } + return null; + } + + @Override + public IAtsInsertion getInsertion(IAtsInsertionActivity activity) { + ResultSet<ArtifactReadable> related = ((ArtifactReadable) activity.getStoreObject()).getRelated( + AtsRelationTypes.InsertionToInsertionActivity_Insertion); + if (related.size() > 0) { + return atsServer.getConfigItemFactory().getInsertion(related.iterator().next()); + } + return null; + } + + @Override + public IAtsProgram getProgram(IAtsInsertion insertion) { + ResultSet<ArtifactReadable> related = + ((ArtifactReadable) insertion.getStoreObject()).getRelated(AtsRelationTypes.ProgramToInsertion_Program); + if (related.size() > 0) { + return atsServer.getConfigItemFactory().getProgram(related.iterator().next()); + } + return null; + } + + @Override + public void setWorkPackage(IAtsWorkPackage workPackage, List<IAtsWorkItem> workItems) { + throw new UnsupportedOperationException("setWorkPackage not supported on server"); + } + +} diff --git a/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/workitem/AtsRuleEndpointImpl.java b/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/workitem/AtsRuleEndpointImpl.java index 9f34299b7e4..a0c5add60ef 100644 --- a/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/workitem/AtsRuleEndpointImpl.java +++ b/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/workitem/AtsRuleEndpointImpl.java @@ -29,8 +29,8 @@ import org.eclipse.osee.ats.api.workdef.RunRuleData; import org.eclipse.osee.ats.api.workdef.RunRuleResults; import org.eclipse.osee.ats.api.workflow.AtsRuleEndpointApi; import org.eclipse.osee.ats.core.users.AtsCoreUsers; -import org.eclipse.osee.ats.impl.IAtsServer; -import org.eclipse.osee.ats.impl.util.WorkflowRuleRunner; +import org.eclipse.osee.ats.rest.IAtsServer; +import org.eclipse.osee.ats.rest.internal.util.WorkflowRuleRunner; import org.eclipse.osee.framework.jdk.core.type.OseeArgumentException; import org.eclipse.osee.orcs.data.ArtifactReadable; diff --git a/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/workitem/AtsTaskEndpointImpl.java b/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/workitem/AtsTaskEndpointImpl.java index c79091af1c9..b4ed84aa079 100644 --- a/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/workitem/AtsTaskEndpointImpl.java +++ b/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/workitem/AtsTaskEndpointImpl.java @@ -24,8 +24,7 @@ import org.eclipse.osee.ats.api.task.NewTaskDatas; import org.eclipse.osee.ats.api.util.IAtsChangeSet; import org.eclipse.osee.ats.api.workflow.WorkItemType; import org.eclipse.osee.ats.core.users.AtsCoreUsers; -import org.eclipse.osee.ats.impl.IAtsServer; -import org.eclipse.osee.ats.impl.workitem.CreateTasksOperation; +import org.eclipse.osee.ats.rest.IAtsServer; import org.eclipse.osee.framework.core.util.XResultData; import org.eclipse.osee.framework.jdk.core.type.OseeArgumentException; diff --git a/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/workitem/AtsTaskService.java b/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/workitem/AtsTaskService.java new file mode 100644 index 00000000000..7260849ac37 --- /dev/null +++ b/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/workitem/AtsTaskService.java @@ -0,0 +1,91 @@ +/******************************************************************************* + * Copyright (c) 2015 Boeing. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.ats.rest.internal.workitem; + +import java.util.Collection; +import java.util.Date; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; +import org.eclipse.osee.ats.api.task.AbstractAtsTaskService; +import org.eclipse.osee.ats.api.task.JaxAtsTask; +import org.eclipse.osee.ats.api.task.NewTaskData; +import org.eclipse.osee.ats.api.task.NewTaskDatas; +import org.eclipse.osee.ats.api.user.IAtsUser; +import org.eclipse.osee.ats.api.util.IAtsChangeSet; +import org.eclipse.osee.ats.api.workflow.IAtsTask; +import org.eclipse.osee.ats.api.workflow.IAtsTeamWorkflow; +import org.eclipse.osee.ats.core.users.AtsCoreUsers; +import org.eclipse.osee.ats.rest.IAtsServer; +import org.eclipse.osee.framework.core.util.XResultData; +import org.eclipse.osee.framework.jdk.core.type.OseeStateException; + +/** + * @author Donald G. Dunne + */ +public class AtsTaskService extends AbstractAtsTaskService { + + private final IAtsServer atsServer; + + public AtsTaskService(IAtsServer atsServer) { + super(atsServer.getServices()); + this.atsServer = atsServer; + } + + @Override + public Collection<IAtsTask> createTasks(NewTaskData newTaskData) { + IAtsChangeSet changes = + atsServer.getStoreService().createAtsChangeSet(newTaskData.getCommitComment(), AtsCoreUsers.SYSTEM_USER); + return createTasks(newTaskData, changes); + } + + @Override + public Collection<IAtsTask> createTasks(NewTaskData newTaskData, IAtsChangeSet changes) { + CreateTasksOperation operation = new CreateTasksOperation(newTaskData, atsServer, new XResultData()); + XResultData results = operation.validate(); + operation.run(changes); + if (results.isErrors()) { + throw new OseeStateException("Error creating tasks - " + results.toString()); + } + List<IAtsTask> tasks = new LinkedList<>(); + for (JaxAtsTask task : operation.getTasks()) { + tasks.add(atsServer.getWorkItemFactory().getTask(atsServer.getArtifact(task.getUuid()))); + } + return tasks; + } + + @Override + public Collection<IAtsTask> createTasks(NewTaskDatas newTaskDatas) { + CreateTasksOperation operation = new CreateTasksOperation(newTaskDatas, atsServer, new XResultData()); + XResultData results = operation.validate(); + + if (results.isErrors()) { + throw new OseeStateException("Error validating task creation - " + results.toString()); + } + operation.run(); + if (results.isErrors()) { + throw new OseeStateException("Error creating tasks - " + results.toString()); + } + List<IAtsTask> tasks = new LinkedList<>(); + for (JaxAtsTask task : operation.getTasks()) { + tasks.add(atsServer.getWorkItemFactory().getTask(atsServer.getArtifact(task.getUuid()))); + } + return tasks; + } + + @Override + public Collection<IAtsTask> createTasks(IAtsTeamWorkflow teamWf, List<String> titles, List<IAtsUser> assignees, Date createdDate, IAtsUser createdBy, String relatedToState, String taskWorkDef, Map<String, List<String>> attributes, IAtsChangeSet changes) { + NewTaskData tasks = atsServer.getTaskService().getNewTaskData(teamWf, titles, assignees, createdDate, createdBy, + relatedToState, taskWorkDef, attributes, changes.getComment()); + return createTasks(tasks, changes); + } + +} diff --git a/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/workitem/AtsTeamDefinitionService.java b/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/workitem/AtsTeamDefinitionService.java new file mode 100644 index 00000000000..018aef52de6 --- /dev/null +++ b/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/workitem/AtsTeamDefinitionService.java @@ -0,0 +1,51 @@ +/* + * Created on Nov 18, 2014 + * + * PLACE_YOUR_DISTRIBUTION_STATEMENT_RIGHT_HERE + */ +package org.eclipse.osee.ats.rest.internal.workitem; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; +import org.eclipse.osee.ats.api.IAtsWorkItem; +import org.eclipse.osee.ats.api.data.AtsAttributeTypes; +import org.eclipse.osee.ats.api.data.AtsRelationTypes; +import org.eclipse.osee.ats.api.team.IAtsTeamDefinition; +import org.eclipse.osee.ats.api.team.IAtsTeamDefinitionService; +import org.eclipse.osee.ats.api.version.IAtsVersion; +import org.eclipse.osee.ats.rest.internal.AtsServerImpl; +import org.eclipse.osee.framework.jdk.core.type.OseeCoreException; +import org.eclipse.osee.framework.jdk.core.util.Strings; +import org.eclipse.osee.orcs.data.ArtifactReadable; + +public class AtsTeamDefinitionService implements IAtsTeamDefinitionService { + + private final AtsServerImpl atsServer; + + public AtsTeamDefinitionService(AtsServerImpl atsServer) { + this.atsServer = atsServer; + } + + @Override + public IAtsTeamDefinition getTeamDefinition(IAtsWorkItem workItem) throws OseeCoreException { + IAtsTeamDefinition teamDef = null; + String teamDefGuid = + ((ArtifactReadable) workItem.getStoreObject()).getSoleAttributeAsString(AtsAttributeTypes.TeamDefinition, ""); + if (Strings.isValid(teamDefGuid)) { + Long uuid = atsServer.getStoreService().getUuidFromGuid(teamDefGuid); + teamDef = (IAtsTeamDefinition) atsServer.getConfig().getSoleByUuid(uuid); + } + return teamDef; + } + + @Override + public Collection<IAtsVersion> getVersions(IAtsTeamDefinition teamDef) { + List<IAtsVersion> versions = new ArrayList<>(); + for (ArtifactReadable verArt : ((ArtifactReadable) teamDef.getStoreObject()).getRelated(AtsRelationTypes.TeamDefinitionToVersion_Version)) { + versions.add(atsServer.getConfigItemFactory().getVersion(verArt)); + } + return versions; + } + +} diff --git a/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/workitem/AtsVersionServiceImpl.java b/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/workitem/AtsVersionServiceImpl.java new file mode 100644 index 00000000000..158cf755588 --- /dev/null +++ b/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/workitem/AtsVersionServiceImpl.java @@ -0,0 +1,25 @@ +/******************************************************************************* + * Copyright (c) 2015 Boeing. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.ats.rest.internal.workitem; + +import org.eclipse.osee.ats.api.IAtsServices; +import org.eclipse.osee.ats.core.version.AbstractAtsVersionServiceImpl; + +/** + * @author Donald G. Dunne + */ +public class AtsVersionServiceImpl extends AbstractAtsVersionServiceImpl { + + public AtsVersionServiceImpl(IAtsServices services) { + super(services); + } + +} diff --git a/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/workitem/AtsWorkPackageEndpointImpl.java b/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/workitem/AtsWorkPackageEndpointImpl.java index 4b4a6aed719..3f1ac67c788 100644 --- a/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/workitem/AtsWorkPackageEndpointImpl.java +++ b/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/workitem/AtsWorkPackageEndpointImpl.java @@ -32,7 +32,7 @@ import org.eclipse.osee.ats.api.util.ColorTeam; import org.eclipse.osee.ats.api.util.ColorTeams; import org.eclipse.osee.ats.api.util.IAtsChangeSet; import org.eclipse.osee.ats.api.workflow.WorkItemType; -import org.eclipse.osee.ats.impl.IAtsServer; +import org.eclipse.osee.ats.rest.IAtsServer; import org.eclipse.osee.framework.jdk.core.type.OseeArgumentException; import org.eclipse.osee.framework.jdk.core.util.Strings; import org.eclipse.osee.orcs.data.ArtifactReadable; diff --git a/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/workitem/ConfigItemFactory.java b/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/workitem/ConfigItemFactory.java new file mode 100644 index 00000000000..d6eb3d9dac5 --- /dev/null +++ b/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/workitem/ConfigItemFactory.java @@ -0,0 +1,317 @@ +/******************************************************************************* + * 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.workitem; + +import org.eclipse.osee.ats.api.IAtsConfigObject; +import org.eclipse.osee.ats.api.agile.IAgileFeatureGroup; +import org.eclipse.osee.ats.api.agile.IAgileTeam; +import org.eclipse.osee.ats.api.ai.IAtsActionableItem; +import org.eclipse.osee.ats.api.country.IAtsCountry; +import org.eclipse.osee.ats.api.data.AtsArtifactTypes; +import org.eclipse.osee.ats.api.data.AtsRelationTypes; +import org.eclipse.osee.ats.api.insertion.IAtsInsertion; +import org.eclipse.osee.ats.api.insertion.IAtsInsertionActivity; +import org.eclipse.osee.ats.api.insertion.JaxInsertion; +import org.eclipse.osee.ats.api.insertion.JaxInsertionActivity; +import org.eclipse.osee.ats.api.program.IAtsProgram; +import org.eclipse.osee.ats.api.team.IAtsTeamDefinition; +import org.eclipse.osee.ats.api.version.IAtsVersion; +import org.eclipse.osee.ats.core.config.AbstractConfigItemFactory; +import org.eclipse.osee.ats.core.config.Country; +import org.eclipse.osee.ats.core.config.Program; +import org.eclipse.osee.ats.core.insertion.Insertion; +import org.eclipse.osee.ats.core.insertion.InsertionActivity; +import org.eclipse.osee.ats.core.util.AtsUtilCore; +import org.eclipse.osee.ats.rest.IAtsServer; +import org.eclipse.osee.ats.rest.internal.util.AtsChangeSet; +import org.eclipse.osee.ats.rest.internal.workitem.model.ActionableItem; +import org.eclipse.osee.ats.rest.internal.workitem.model.TeamDefinition; +import org.eclipse.osee.ats.rest.internal.workitem.model.Version; +import org.eclipse.osee.framework.core.data.ArtifactId; +import org.eclipse.osee.framework.core.data.IArtifactType; +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.GUID; +import org.eclipse.osee.framework.jdk.core.util.Lib; +import org.eclipse.osee.logger.Log; +import org.eclipse.osee.orcs.data.ArtifactReadable; +import org.eclipse.osee.orcs.transaction.TransactionBuilder; + +/** + * @author Donald G. Dunne + * @author David W. Miller + */ +public class ConfigItemFactory extends AbstractConfigItemFactory { + + private final Log logger; + private final IAtsServer atsServer; + + public ConfigItemFactory(Log logger, IAtsServer atsServer) { + this.logger = logger; + this.atsServer = atsServer; + } + + @Override + public IAtsConfigObject getConfigObject(ArtifactId artifact) throws OseeCoreException { + IAtsConfigObject configObject = null; + try { + if (artifact instanceof ArtifactReadable) { + ArtifactReadable artRead = (ArtifactReadable) artifact; + if (artRead.isOfType(AtsArtifactTypes.Version)) { + configObject = getVersion(artifact); + } else if (artRead.isOfType(AtsArtifactTypes.TeamDefinition)) { + configObject = getTeamDef(artRead); + } else if (artRead.isOfType(AtsArtifactTypes.ActionableItem)) { + configObject = getActionableItem(artRead); + } else if (artRead.isOfType(AtsArtifactTypes.Program)) { + configObject = getProgram(artRead); + } else if (artRead.isOfType(AtsArtifactTypes.AgileTeam)) { + configObject = getAgileTeam(artRead); + } else if (artRead.isOfType(AtsArtifactTypes.AgileFeatureGroup)) { + configObject = getAgileFeatureGroup(artRead); + } else if (artRead.isOfType(AtsArtifactTypes.Insertion)) { + configObject = getInsertion(artRead); + } else if (artRead.isOfType(AtsArtifactTypes.InsertionActivity)) { + configObject = getInsertionActivity(artRead); + } else if (artRead.isOfType(AtsArtifactTypes.Country)) { + configObject = getCountry(artRead); + } + } + } catch (OseeCoreException ex) { + logger.error(ex, "Error getting config object for [%s]", artifact); + } + return configObject; + } + + @Override + public IAtsVersion getVersion(ArtifactId artifact) { + IAtsVersion version = null; + if (artifact instanceof ArtifactReadable) { + ArtifactReadable artRead = (ArtifactReadable) artifact; + if (artRead.isOfType(AtsArtifactTypes.Version)) { + version = new Version(logger, atsServer, artRead); + } + } + return version; + } + + @Override + public IAtsTeamDefinition getTeamDef(ArtifactId artifact) throws OseeCoreException { + IAtsTeamDefinition teamDef = null; + if (artifact instanceof ArtifactReadable) { + ArtifactReadable artRead = (ArtifactReadable) artifact; + if (artRead.isOfType(AtsArtifactTypes.TeamDefinition)) { + teamDef = new TeamDefinition(logger, atsServer, artRead); + } + } + return teamDef; + } + + @Override + public IAtsActionableItem getActionableItem(ArtifactId artifact) throws OseeCoreException { + IAtsActionableItem ai = null; + if (artifact instanceof ArtifactReadable) { + ArtifactReadable artRead = (ArtifactReadable) artifact; + if (artRead.isOfType(AtsArtifactTypes.ActionableItem)) { + ai = new ActionableItem(logger, atsServer, artRead); + } + } + return ai; + } + + @Override + public IAtsProgram getProgram(ArtifactId artifact) { + Program program = null; + if (artifact instanceof ArtifactReadable) { + ArtifactReadable artRead = (ArtifactReadable) artifact; + if (artRead.isOfType(AtsArtifactTypes.Program)) { + program = new Program(logger, atsServer, artRead); + } + } + return program; + } + + @Override + public IAgileTeam getAgileTeam(ArtifactId artifact) { + IAgileTeam agileTeam = null; + if (artifact instanceof ArtifactReadable) { + ArtifactReadable artRead = (ArtifactReadable) artifact; + if (artRead.isOfType(AtsArtifactTypes.AgileTeam)) { + agileTeam = atsServer.getAgileService().getAgileTeam(artRead); + } + } + return agileTeam; + } + + @Override + public IAgileFeatureGroup getAgileFeatureGroup(ArtifactId artifact) { + IAgileFeatureGroup agileTeam = null; + if (artifact instanceof ArtifactReadable) { + ArtifactReadable artRead = (ArtifactReadable) artifact; + if (artRead.isOfType(AtsArtifactTypes.AgileFeatureGroup)) { + agileTeam = atsServer.getAgileService().getAgileFeatureGroup(artRead); + } + } + return agileTeam; + } + + @Override + public IAtsInsertion getInsertion(ArtifactId artifact) { + Insertion insertion = null; + if (artifact instanceof ArtifactReadable) { + ArtifactReadable artRead = (ArtifactReadable) artifact; + if (artRead.isOfType(AtsArtifactTypes.Insertion)) { + insertion = new Insertion(logger, atsServer.getServices(), artRead); + ArtifactReadable programArt = + ((ArtifactReadable) artifact).getRelated(AtsRelationTypes.ProgramToInsertion_Program).getOneOrNull(); + if (programArt != null) { + insertion.setProgramUuid(programArt.getUuid()); + } + } else { + throw new OseeCoreException("Requested uuid not Insertion"); + } + } + return insertion; + } + + @Override + public IAtsInsertionActivity getInsertionActivity(ArtifactId artifact) { + InsertionActivity insertionActivity = null; + if (artifact instanceof ArtifactReadable) { + ArtifactReadable artRead = (ArtifactReadable) artifact; + if (artRead.isOfType(AtsArtifactTypes.InsertionActivity)) { + insertionActivity = new InsertionActivity(logger, atsServer.getServices(), artRead); + ArtifactReadable insertionArt = + ((ArtifactReadable) artifact).getRelated(AtsRelationTypes.InsertionToInsertionActivity_Insertion).getOneOrNull(); + if (insertionArt != null) { + insertionActivity.setInsertionUuid(insertionArt.getUuid()); + } + } else { + throw new OseeCoreException("Requested uuid not Insertion Activity"); + } + } + return insertionActivity; + } + + @Override + public IAtsInsertion createInsertion(ArtifactId programArtifact, JaxInsertion newInsertion) { + + Long uuid = newInsertion.getUuid(); + if (uuid == null || uuid <= 0) { + uuid = Lib.generateArtifactIdAsInt(); + } + AtsChangeSet changes = + (AtsChangeSet) atsServer.getStoreService().createAtsChangeSet("Create new Insertion", + atsServer.getUserService().getCurrentUser()); + ArtifactReadable insertionArt = + (ArtifactReadable) changes.createArtifact(AtsArtifactTypes.Insertion, newInsertion.getName(), GUID.create(), + uuid); + + changes.relate(programArtifact, AtsRelationTypes.ProgramToInsertion_Insertion, insertionArt); + changes.execute(); + return getInsertion(insertionArt); + } + + @Override + public IAtsInsertion updateInsertion(JaxInsertion updatedInsertion) { + AtsChangeSet changes = + (AtsChangeSet) atsServer.getStoreService().createAtsChangeSet("Update Insertion", + atsServer.getUserService().getCurrentUser()); + changes.setSoleAttributeValue(atsServer.getConfig().getSoleByUuid(updatedInsertion.getUuid()), + CoreAttributeTypes.Name, updatedInsertion.getName()); + changes.execute(); + return getInsertion(atsServer.getQuery().andUuid(updatedInsertion.getUuid()).getResults().getExactlyOne()); + } + + @Override + public void deleteInsertion(ArtifactId artifact) { + deleteConfigObject(artifact.getUuid(), "Delete Insertion", AtsArtifactTypes.Insertion); + } + + @Override + public IAtsInsertionActivity createInsertionActivity(ArtifactId insertion, JaxInsertionActivity newActivity) { + Long uuid = newActivity.getUuid(); + if (uuid == null || uuid <= 0) { + uuid = Lib.generateArtifactIdAsInt(); + } + AtsChangeSet changes = + (AtsChangeSet) atsServer.getStoreService().createAtsChangeSet("Create new Insertion Activity", + atsServer.getUserService().getCurrentUser()); + ArtifactReadable insertionActivityArt = + (ArtifactReadable) changes.createArtifact(AtsArtifactTypes.InsertionActivity, newActivity.getName(), + GUID.create(), uuid); + + changes.relate(insertion, AtsRelationTypes.InsertionToInsertionActivity_InsertionActivity, insertionActivityArt); + changes.execute(); + return getInsertionActivity(insertionActivityArt); + } + + @Override + public IAtsInsertionActivity updateInsertionActivity(JaxInsertionActivity updatedActivity) { + AtsChangeSet changes = + (AtsChangeSet) atsServer.getStoreService().createAtsChangeSet("Update Insertion", + atsServer.getUserService().getCurrentUser()); + ArtifactReadable insertionActivityArt = + atsServer.getQuery().andUuid(updatedActivity.getUuid()).getResults().getExactlyOne(); + + changes.getTransaction().setSoleAttributeValue(insertionActivityArt, CoreAttributeTypes.Name, + updatedActivity.getName()); + changes.setSoleAttributeValue(atsServer.getConfig().getSoleByUuid(updatedActivity.getUuid()), + CoreAttributeTypes.Name, updatedActivity.getName()); + changes.execute(); + return getInsertionActivity(atsServer.getQuery().andUuid(updatedActivity.getUuid()).getResults().getExactlyOne()); + } + + @Override + public void deleteInsertionActivity(ArtifactId artifact) { + deleteConfigObject(artifact.getUuid(), "Delete Insertion Activity", AtsArtifactTypes.InsertionActivity); + } + + private void deleteConfigObject(long uuid, String comment, IArtifactType type) { + ArtifactReadable toDelete = atsServer.getArtifact(uuid); + if (toDelete == null) { + throw new OseeCoreException("No object found for uuid %d", uuid); + } + + if (!toDelete.getArtifactType().equals(type)) { + throw new OseeCoreException("Artifact type does not match for %s", comment); + } + TransactionBuilder transaction = + atsServer.getOrcsApi().getTransactionFactory().createTransaction(AtsUtilCore.getAtsBranch(), toDelete, comment); + transaction.deleteArtifact(toDelete); + transaction.commit(); + } + + @Override + public boolean isAtsConfigArtifact(ArtifactId artifact) { + return getAtsConfigArtifactTypes().contains(((ArtifactReadable) artifact).getArtifactType()); + } + + @Override + public IAtsCountry getCountry(ArtifactId artifact) { + IAtsCountry country = null; + if (artifact instanceof ArtifactReadable) { + ArtifactReadable artRead = (ArtifactReadable) artifact; + if (artRead.isOfType(AtsArtifactTypes.Country)) { + country = new Country(logger, atsServer.getServices(), artRead); + } else { + throw new OseeCoreException("Requested uuid not Country"); + } + } + return country; + } + + @Override + public IAtsCountry getCountry(long uuid) { + return getCountry(atsServer.getArtifact(uuid)); + } + +} 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 new file mode 100644 index 00000000000..1d785c4a95b --- /dev/null +++ b/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/workitem/CreateTasksOperation.java @@ -0,0 +1,352 @@ +/******************************************************************************* + * Copyright (c) 2015 Boeing. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.ats.rest.internal.workitem; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.Date; +import java.util.HashMap; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; +import org.eclipse.osee.ats.api.IAtsWorkItem; +import org.eclipse.osee.ats.api.data.AtsArtifactTypes; +import org.eclipse.osee.ats.api.data.AtsAttributeTypes; +import org.eclipse.osee.ats.api.data.AtsRelationTypes; +import org.eclipse.osee.ats.api.task.JaxAtsTask; +import org.eclipse.osee.ats.api.task.JaxAttribute; +import org.eclipse.osee.ats.api.task.JaxRelation; +import org.eclipse.osee.ats.api.task.NewTaskData; +import org.eclipse.osee.ats.api.task.NewTaskDatas; +import org.eclipse.osee.ats.api.user.IAtsUser; +import org.eclipse.osee.ats.api.util.IAtsChangeSet; +import org.eclipse.osee.ats.api.workdef.IAtsWorkDefinition; +import org.eclipse.osee.ats.api.workflow.IAtsTask; +import org.eclipse.osee.ats.api.workflow.IAtsTeamWorkflow; +import org.eclipse.osee.ats.api.workflow.WorkItemType; +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.IAttributeType; +import org.eclipse.osee.framework.core.data.IRelationType; +import org.eclipse.osee.framework.core.data.IRelationTypeSide; +import org.eclipse.osee.framework.core.enums.RelationSide; +import org.eclipse.osee.framework.core.model.RelationTypeSide; +import org.eclipse.osee.framework.core.util.XResultData; +import org.eclipse.osee.framework.jdk.core.type.OseeArgumentException; +import org.eclipse.osee.framework.jdk.core.type.OseeStateException; +import org.eclipse.osee.framework.jdk.core.util.GUID; +import org.eclipse.osee.framework.jdk.core.util.Lib; +import org.eclipse.osee.framework.jdk.core.util.Strings; +import org.eclipse.osee.orcs.data.ArtifactReadable; + +/** + * @author Donald G. Dunne + */ +public class CreateTasksOperation { + + private XResultData resultData; + private final NewTaskDatas newTaskDatas; + private final IAtsServer atsServer; + private IAtsUser asUser; + private final List<JaxAtsTask> tasks = new ArrayList<>(); + private Date createdByDate; + private Map<Long, IAtsTeamWorkflow> uuidToTeamWf; + + public CreateTasksOperation(NewTaskData newTaskData, IAtsServer atsServer, XResultData resultData) { + newTaskDatas = new NewTaskDatas(); + newTaskDatas.add(newTaskData); + this.atsServer = atsServer; + this.resultData = resultData; + } + + public CreateTasksOperation(NewTaskDatas newTaskDatas, IAtsServer atsServer, XResultData resultData) { + this.newTaskDatas = newTaskDatas; + this.atsServer = atsServer; + this.resultData = resultData; + } + + public XResultData validate() { + if (resultData == null) { + resultData = new XResultData(false); + } + uuidToTeamWf = new HashMap<>(); + for (NewTaskData newTaskData : newTaskDatas.getTaskDatas()) { + Long teamWfUuid = newTaskData.getTeamWfUuid(); + if (teamWfUuid == null) { + resultData.error("Team Workflow uuid not specified"); + continue; + } + ArtifactReadable teamWfArt = atsServer.getArtifact(teamWfUuid); + if (teamWfArt == null) { + resultData.errorf("Team Workflow uuid %d does not exist", teamWfUuid); + } + IAtsTeamWorkflow teamWf = uuidToTeamWf.get(teamWfUuid); + if (teamWf == null) { + teamWf = atsServer.getWorkItemFactory().getTeamWf(teamWfArt); + uuidToTeamWf.put(teamWfUuid, teamWf); + } + String asUserId = newTaskData.getAsUserId(); + if (asUserId == null) { + resultData.error("As User Id uuid not specified"); + } + asUser = atsServer.getUserService().getUserById(asUserId); + if (asUser == null) { + resultData.errorf("As User Id uuid %d does not exist", asUserId); + } + if (!Strings.isValid(newTaskData.getCommitComment())) { + resultData.errorf("Inavlidate Commit Comment [%s]", newTaskData.getCommitComment()); + } + + for (JaxAtsTask task : newTaskData.getNewTasks()) { + Long taskUuid = task.getUuid(); + if (taskUuid > 0L) { + ArtifactReadable taskArt = atsServer.getArtifact(taskUuid); + if (taskArt != null) { + resultData.errorf("Task with uuid %d already exists for %s", taskUuid, task); + } + } + if (!Strings.isValid(task.getName())) { + resultData.errorf("Task name [%s] is invalid for %s", task.getName(), task); + } + IAtsUser createdBy = atsServer.getUserService().getUserById(task.getCreatedByUserId()); + if (createdBy == null) { + resultData.errorf("Task Created By user id %d does not exist in %s", createdBy, task); + } + createdByDate = task.getCreatedDate(); + if (createdByDate == null) { + resultData.errorf("Task Created By Date %s does not exist in %s", createdByDate, task); + } + IAtsTeamWorkflow teamWorkflow = atsServer.getWorkItemFactory().getTeamWf(teamWfArt); + String relatedToState = task.getRelatedToState(); + if (Strings.isValid(relatedToState)) { + if (teamWorkflow.getWorkDefinition().getStateByName(relatedToState) == null) { + resultData.errorf("Task Related To State %s invalid for Team Workflow %d", relatedToState, + teamWfUuid); + } + } + + List<String> assigneeUserIds = task.getAssigneeUserIds(); + if (!assigneeUserIds.isEmpty()) { + Collection<IAtsUser> assignees = atsServer.getUserService().getUsersByUserIds(assigneeUserIds); + if (assigneeUserIds.size() != assignees.size()) { + resultData.errorf("Task Assignees [%s] not all valid in %s", String.valueOf(assigneeUserIds), task); + } + } + + IAtsWorkDefinition workDefinition = null; + if (Strings.isValid(task.getTaskWorkDef())) { + try { + XResultData rd = new XResultData(); + workDefinition = atsServer.getWorkDefService().getWorkDef(task.getTaskWorkDef(), rd); + if (rd.isErrors()) { + resultData.errorf("Error finding Task Work Def [%s]. Exception: %s", task.getTaskWorkDef(), + rd.toString()); + } + } catch (Exception ex) { + resultData.errorf("Exception finding Task Work Def [%s]. Exception: %s", task.getTaskWorkDef(), + ex.getMessage()); + } + if (workDefinition == null) { + resultData.errorf("Task Work Def [%s] does not exist", task.getTaskWorkDef()); + } + } + + for (JaxAttribute attribute : task.getAttributes()) { + IAttributeType attrType = getAttributeType(atsServer, attribute.getAttrTypeName()); + if (attrType == null) { + resultData.errorf("Attribute Type [%s] not valid for Task creation in %s", + attribute.getAttrTypeName(), task); + } + } + + for (JaxRelation relation : task.getRelations()) { + IRelationType relationType = getRelationType(atsServer, relation.getRelationTypeName()); + if (relationType == null) { + resultData.errorf("Relation Type [%s] not valid for Task creation in %s", + relation.getRelationTypeName(), task); + } + if (relation.getRelatedUuids().isEmpty()) { + resultData.errorf("Relation [%s] Uuids must be suplied Task creation in %s", + relation.getRelationTypeName(), task); + } + Collection<Integer> foundUuids = atsServer.getQueryService().createQuery(WorkItemType.WorkItem).andUuids( + relation.getRelatedUuids().toArray(new Long[relation.getRelatedUuids().size()])).getItemIds(); + List<Long> notFoundUuids = relation.getRelatedUuids(); + notFoundUuids.removeAll(foundUuids); + if (foundUuids.size() != relation.getRelatedUuids().size()) { + resultData.errorf("Relation [%s] Uuids [%s] do not match Work Items in task %s", + relation.getRelationTypeName(), notFoundUuids, task); + } + } + } + } + return resultData; + } + + private IRelationType getRelationType(IAtsServer atsServer, String relationTypeName) { + for (IRelationType relation : atsServer.getOrcsApi().getOrcsTypes().getRelationTypes().getAll()) { + if (relation.getName().equals(relation.getName())) { + return relation; + } + } + return null; + } + + private static IAttributeType getAttributeType(IAtsServer atsServer, String attrTypeName) { + for (IAttributeType attrType : atsServer.getOrcsApi().getOrcsTypes().getArtifactTypes().getAttributeTypes( + AtsArtifactTypes.Task, AtsUtilCore.getAtsBranch())) { + if (attrType.getName().equals(attrTypeName)) { + return attrType; + } + } + return null; + } + + public List<JaxAtsTask> getTasks() { + return tasks; + } + + public void run() { + XResultData results = validate(); + if (results.isErrors()) { + throw new OseeArgumentException(results.toString()); + } + + IAtsChangeSet changes = atsServer.getStoreService().createAtsChangeSet( + newTaskDatas.getTaskDatas().iterator().next().getCommitComment(), asUser); + run(changes); + changes.execute(); + + for (NewTaskData newTaskData : newTaskDatas.getTaskDatas()) { + for (JaxAtsTask jaxTask : newTaskData.getNewTasks()) { + JaxAtsTask newJaxTask = createNewJaxTask(jaxTask.getUuid(), atsServer); + if (newJaxTask == null) { + throw new OseeStateException("Unable to create return New Task for uuid " + jaxTask.getUuid()); + } + this.tasks.add(newJaxTask); + } + } + } + + public void run(IAtsChangeSet changes) { + createTasks(changes); + if (changes.isEmpty()) { + throw new OseeStateException(getClass().getSimpleName() + " Error - No Tasks to Create"); + } + } + + private void createTasks(IAtsChangeSet changes) { + for (NewTaskData newTaskData : newTaskDatas.getTaskDatas()) { + for (JaxAtsTask jaxTask : newTaskData.getNewTasks()) { + + Long uuid = jaxTask.getUuid(); + if (uuid <= 0L) { + uuid = Lib.generateArtifactIdAsInt(); + jaxTask.setUuid(uuid); + } + ArtifactId taskArt = changes.createArtifact(AtsArtifactTypes.Task, jaxTask.getName(), GUID.create(), uuid); + IAtsTask task = atsServer.getWorkItemFactory().getTask(taskArt); + + IAtsTeamWorkflow teamWf = uuidToTeamWf.get(newTaskData.getTeamWfUuid()); + atsServer.getUtilService().setAtsId(atsServer.getSequenceProvider(), task, teamWf.getTeamDefinition(), + changes); + changes.relate(teamWf, AtsRelationTypes.TeamWfToTask_Task, taskArt); + + List<IAtsUser> assignees = new ArrayList<>(); + if (jaxTask.getAssigneeUserIds() != null) { + assignees.addAll(atsServer.getUserService().getUsersByUserIds(jaxTask.getAssigneeUserIds())); + } + if (assignees.isEmpty()) { + assignees.add(AtsCoreUsers.UNASSIGNED_USER); + } + + IAtsWorkDefinition workDefinition = null; + if (Strings.isValid(jaxTask.getTaskWorkDef())) { + try { + workDefinition = + atsServer.getWorkDefService().getWorkDef(jaxTask.getTaskWorkDef(), new XResultData()); + } catch (Exception ex) { + throw new OseeArgumentException("Exception finding Task Work Def [%s]", jaxTask.getTaskWorkDef(), ex); + } + } + if (Strings.isValid(jaxTask.getDescription())) { + changes.setSoleAttributeValue(task, AtsAttributeTypes.Description, jaxTask.getDescription()); + } + atsServer.getActionFactory().initializeNewStateMachine(task, assignees, createdByDate, asUser, + workDefinition, changes); + + // Set parent state task is related to if set + if (Strings.isValid(jaxTask.getRelatedToState())) { + changes.setSoleAttributeValue(task, AtsAttributeTypes.RelatedToState, jaxTask.getRelatedToState()); + } + + for (JaxAttribute attribute : jaxTask.getAttributes()) { + IAttributeType attrType = getAttributeType(atsServer, attribute.getAttrTypeName()); + if (attrType == null) { + resultData.errorf("Attribute Type [%s] not valid for Task creation in %s", + attribute.getAttrTypeName(), task); + } + changes.setValues(task, attrType, attribute.getValues()); + } + + for (JaxRelation relation : jaxTask.getRelations()) { + IRelationType relationType = getRelationType(atsServer, relation.getRelationTypeName()); + if (relationType == null) { + resultData.errorf("Relation Type [%s] not valid for Task creation in %s", + relation.getRelationTypeName(), task); + } + Collection<IAtsWorkItem> items = atsServer.getQueryService().createQuery(WorkItemType.WorkItem).andUuids( + relation.getRelatedUuids().toArray(new Long[relation.getRelatedUuids().size()])).getItems(); + IRelationTypeSide side = null; + if (relation.isSideA()) { + side = new RelationTypeSide(relationType, RelationSide.SIDE_A); + } else { + side = new RelationTypeSide(relationType, RelationSide.SIDE_B); + } + changes.setRelations(task, side, items); + } + changes.add(taskArt); + } + } + + } + + public static JaxAtsTask createNewJaxTask(Long uuid, IAtsServer atsServer) { + ArtifactReadable taskArt = atsServer.getArtifact(uuid); + if (taskArt != null) { + JaxAtsTask newJaxTask = new JaxAtsTask(); + newJaxTask.setName(taskArt.getName()); + newJaxTask.setDescription(taskArt.getSoleAttributeValue(AtsAttributeTypes.Description, "")); + newJaxTask.setUuid(taskArt.getUuid()); + newJaxTask.setActive(true); + String createdByUserId = taskArt.getSoleAttributeValue(AtsAttributeTypes.CreatedBy, null); + newJaxTask.setCreatedByUserId(createdByUserId); + newJaxTask.setCreatedDate(taskArt.getSoleAttributeValue(AtsAttributeTypes.CreatedDate)); + newJaxTask.setRelatedToState(taskArt.getSoleAttributeValue(AtsAttributeTypes.RelatedToState, "")); + IAtsWorkItem workItem = atsServer.getWorkItemFactory().getWorkItem(taskArt); + for (IAtsUser user : workItem.getAssignees()) { + newJaxTask.getAssigneeUserIds().add(user.getUserId()); + } + for (IAttributeType type : taskArt.getExistingAttributeTypes()) { + List<String> attributeValues = new LinkedList<>(); + for (Object value : taskArt.getAttributeValues(type)) { + attributeValues.add(value.toString()); + } + newJaxTask.addAttributes(type.getName(), attributeValues); + } + return newJaxTask; + } + return null; + } + +} diff --git a/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/workitem/StateResource.java b/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/workitem/StateResource.java index 0e1a4fe875c..d894a817c40 100644 --- a/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/workitem/StateResource.java +++ b/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/workitem/StateResource.java @@ -25,7 +25,7 @@ import org.eclipse.osee.ats.api.workflow.transition.TransitionOption; import org.eclipse.osee.ats.api.workflow.transition.TransitionResults; import org.eclipse.osee.ats.core.workflow.transition.TransitionFactory; import org.eclipse.osee.ats.core.workflow.transition.TransitionHelper; -import org.eclipse.osee.ats.impl.IAtsServer; +import org.eclipse.osee.ats.rest.IAtsServer; import org.eclipse.osee.ats.rest.internal.util.RestUtil; import org.eclipse.osee.framework.core.data.ArtifactId; import org.eclipse.osee.framework.jdk.core.util.Strings; diff --git a/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/workitem/WorkItemFactory.java b/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/workitem/WorkItemFactory.java new file mode 100644 index 00000000000..adfb663f1c4 --- /dev/null +++ b/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/workitem/WorkItemFactory.java @@ -0,0 +1,181 @@ +/******************************************************************************* + * 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.workitem; + +import org.eclipse.osee.ats.api.IAtsWorkItem; +import org.eclipse.osee.ats.api.agile.IAgileBacklog; +import org.eclipse.osee.ats.api.agile.IAgileItem; +import org.eclipse.osee.ats.api.agile.IAgileSprint; +import org.eclipse.osee.ats.api.data.AtsArtifactTypes; +import org.eclipse.osee.ats.api.data.AtsAttributeTypes; +import org.eclipse.osee.ats.api.review.IAtsAbstractReview; +import org.eclipse.osee.ats.api.team.IAtsWorkItemFactory; +import org.eclipse.osee.ats.api.workflow.IAtsAction; +import org.eclipse.osee.ats.api.workflow.IAtsGoal; +import org.eclipse.osee.ats.api.workflow.IAtsTask; +import org.eclipse.osee.ats.api.workflow.IAtsTeamWorkflow; +import org.eclipse.osee.ats.rest.IAtsServer; +import org.eclipse.osee.ats.rest.internal.agile.model.AgileBacklog; +import org.eclipse.osee.ats.rest.internal.agile.model.AgileSprint; +import org.eclipse.osee.ats.rest.internal.workitem.model.Action; +import org.eclipse.osee.ats.rest.internal.workitem.model.DecisionReview; +import org.eclipse.osee.ats.rest.internal.workitem.model.Goal; +import org.eclipse.osee.ats.rest.internal.workitem.model.PeerToPeerReview; +import org.eclipse.osee.ats.rest.internal.workitem.model.Task; +import org.eclipse.osee.ats.rest.internal.workitem.model.TeamWorkflow; +import org.eclipse.osee.framework.core.data.ArtifactId; +import org.eclipse.osee.framework.jdk.core.type.OseeCoreException; +import org.eclipse.osee.logger.Log; +import org.eclipse.osee.orcs.data.ArtifactReadable; + +/** + * @author Donald G. Dunne + */ +public class WorkItemFactory implements IAtsWorkItemFactory { + + private final Log logger; + private final IAtsServer atsServer; + + public WorkItemFactory(Log logger, IAtsServer atsServer) { + this.logger = logger; + this.atsServer = atsServer; + } + + @Override + public IAtsTeamWorkflow getTeamWf(ArtifactId artifact) throws OseeCoreException { + IAtsTeamWorkflow team = null; + if (artifact instanceof ArtifactReadable) { + ArtifactReadable artRead = (ArtifactReadable) artifact; + if (artRead.isOfType(AtsArtifactTypes.TeamWorkflow)) { + team = new TeamWorkflow(logger, atsServer, (ArtifactReadable) artifact); + } + } + return team; + } + + @Override + public IAtsWorkItem getWorkItem(ArtifactId artifact) { + IAtsWorkItem workItem = null; + try { + if (artifact instanceof ArtifactReadable) { + ArtifactReadable artRead = (ArtifactReadable) artifact; + if (artRead.isOfType(AtsArtifactTypes.TeamWorkflow)) { + workItem = getTeamWf(artifact); + } else if (artRead.isOfType(AtsArtifactTypes.PeerToPeerReview) || artRead.isOfType(AtsArtifactTypes.DecisionReview)) { + workItem = getReview(artRead); + } else if (artRead.isOfType(AtsArtifactTypes.Task)) { + workItem = getTask(artRead); + } else if (artRead.isOfType(AtsArtifactTypes.Goal)) { + workItem = getGoal(artRead); + } else if (artRead.isOfType(AtsArtifactTypes.AgileSprint)) { + workItem = getAgileSprint(artRead); + } + } + } catch (OseeCoreException ex) { + logger.error(ex, "Error getting work item for [%s]", artifact); + } + return workItem; + } + + @Override + public IAtsGoal getGoal(ArtifactId artifact) throws OseeCoreException { + IAtsGoal goal = null; + if (artifact instanceof ArtifactReadable) { + ArtifactReadable artRead = (ArtifactReadable) artifact; + if (artRead.isOfType(AtsArtifactTypes.Goal)) { + goal = new Goal(logger, atsServer, (ArtifactReadable) artifact); + } + } + return goal; + } + + @Override + public IAgileSprint getAgileSprint(ArtifactId artifact) throws OseeCoreException { + IAgileSprint sprint = null; + if (artifact instanceof ArtifactReadable) { + ArtifactReadable artRead = (ArtifactReadable) artifact; + if (artRead.isOfType(AtsArtifactTypes.AgileSprint)) { + sprint = new AgileSprint(logger, atsServer, (ArtifactReadable) artifact); + } + } + return sprint; + } + + @Override + public IAgileItem getAgileItem(ArtifactId artifact) { + IAgileItem item = null; + if (artifact instanceof ArtifactReadable) { + ArtifactReadable artRead = (ArtifactReadable) artifact; + if (artRead.isOfType(AtsArtifactTypes.AbstractWorkflowArtifact)) { + item = + new org.eclipse.osee.ats.rest.internal.agile.model.AgileItem(logger, atsServer, (ArtifactReadable) artifact); + } + } + return item; + } + + @Override + public IAgileBacklog getAgileBacklog(ArtifactId artifact) throws OseeCoreException { + IAgileBacklog backlog = null; + if (artifact instanceof ArtifactReadable) { + ArtifactReadable artRead = (ArtifactReadable) artifact; + if (artRead.isOfType(AtsArtifactTypes.Goal)) { + backlog = new AgileBacklog(logger, atsServer, (ArtifactReadable) artifact); + } + } + return backlog; + } + + @Override + public IAtsTask getTask(ArtifactId artifact) throws OseeCoreException { + IAtsTask task = null; + if (artifact instanceof ArtifactReadable) { + ArtifactReadable artRead = (ArtifactReadable) artifact; + if (artRead.isOfType(AtsArtifactTypes.Task)) { + task = new Task(logger, atsServer, (ArtifactReadable) artifact); + } + } + return task; + } + + @Override + public IAtsAbstractReview getReview(ArtifactId artifact) throws OseeCoreException { + IAtsAbstractReview review = null; + if (artifact instanceof ArtifactReadable) { + ArtifactReadable artRead = (ArtifactReadable) artifact; + if (artRead.isOfType(AtsArtifactTypes.PeerToPeerReview)) { + review = new PeerToPeerReview(logger, atsServer, artRead); + } else { + review = new DecisionReview(logger, atsServer, artRead); + } + } + return review; + } + + @Override + public IAtsAction getAction(ArtifactId artifact) { + IAtsAction action = null; + if (artifact instanceof ArtifactReadable) { + ArtifactReadable artRead = (ArtifactReadable) artifact; + if (artRead.isOfType(AtsArtifactTypes.Action)) { + action = new Action(atsServer, artRead); + } + } + return action; + } + + @Override + public IAtsWorkItem getWorkItemByAtsId(String atsId) { + ArtifactReadable artifact = atsServer.getQuery().and(AtsAttributeTypes.AtsId, atsId).getResults().getOneOrNull(); + return getWorkItem(artifact); + } + +} diff --git a/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/workitem/WorkItemJsonWriter.java b/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/workitem/WorkItemJsonWriter.java index 1c222e88d20..c482b54afed 100644 --- a/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/workitem/WorkItemJsonWriter.java +++ b/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/workitem/WorkItemJsonWriter.java @@ -26,7 +26,7 @@ import org.codehaus.jackson.JsonProcessingException; import org.eclipse.osee.ats.api.IAtsWorkItem; import org.eclipse.osee.ats.api.data.AtsAttributeTypes; import org.eclipse.osee.ats.api.workflow.IAtsTeamWorkflow; -import org.eclipse.osee.ats.impl.IAtsServer; +import org.eclipse.osee.ats.rest.IAtsServer; import org.eclipse.osee.ats.rest.internal.config.ConfigJsonWriter; import org.eclipse.osee.ats.rest.internal.util.ActionPage; import org.eclipse.osee.ats.rest.internal.util.RestUtil; @@ -50,7 +50,7 @@ public class WorkItemJsonWriter implements MessageBodyWriter<IAtsWorkItem> { } public void start() { - jsonFactory = org.eclipse.osee.ats.impl.config.JsonFactory.create(); + jsonFactory = org.eclipse.osee.ats.rest.util.JsonFactory.create(); } public void stop() { diff --git a/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/workitem/WorkItemsJsonWriter.java b/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/workitem/WorkItemsJsonWriter.java index caea2438b05..afb4c74bdb5 100644 --- a/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/workitem/WorkItemsJsonWriter.java +++ b/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/workitem/WorkItemsJsonWriter.java @@ -23,7 +23,7 @@ import javax.ws.rs.ext.Provider; import org.codehaus.jackson.JsonFactory; import org.codehaus.jackson.JsonGenerator; import org.eclipse.osee.ats.api.IAtsWorkItem; -import org.eclipse.osee.ats.impl.IAtsServer; +import org.eclipse.osee.ats.rest.IAtsServer; import org.eclipse.osee.framework.jdk.core.util.Lib; import org.eclipse.osee.jaxrs.mvc.IdentityView; import org.eclipse.osee.orcs.data.AttributeTypes; @@ -43,7 +43,7 @@ public class WorkItemsJsonWriter implements MessageBodyWriter<Collection<IAtsWor } public void start() { - jsonFactory = org.eclipse.osee.ats.impl.config.JsonFactory.create(); + jsonFactory = org.eclipse.osee.ats.rest.util.JsonFactory.create(); } public void stop() { diff --git a/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/workitem/model/AbstractReview.java b/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/workitem/model/AbstractReview.java new file mode 100644 index 00000000000..bb64a555627 --- /dev/null +++ b/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/workitem/model/AbstractReview.java @@ -0,0 +1,44 @@ +/******************************************************************************* + * 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.workitem.model; + +import java.util.HashSet; +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.review.IAtsAbstractReview; +import org.eclipse.osee.ats.rest.IAtsServer; +import org.eclipse.osee.framework.jdk.core.type.OseeCoreException; +import org.eclipse.osee.logger.Log; +import org.eclipse.osee.orcs.data.ArtifactReadable; + +/** + * @author Donald G. Dunne + */ +public abstract class AbstractReview extends WorkItem implements IAtsAbstractReview { + + public AbstractReview(Log logger, IAtsServer atsServer, ArtifactReadable artifact) { + super(logger, atsServer, artifact); + } + + @Override + public Set<IAtsActionableItem> getActionableItems() throws OseeCoreException { + Set<IAtsActionableItem> ais = new HashSet<>(); + for (Object aiGuidObj : artifact.getAttributeValues(AtsAttributeTypes.ActionableItem)) { + String aiGuid = (String) aiGuidObj; + ArtifactReadable aiArt = getAtsServer().getArtifactByGuid(aiGuid); + IAtsActionableItem ai = getAtsServer().getConfigItemFactory().getActionableItem(aiArt); + ais.add(ai); + } + return ais; + } + +} diff --git a/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/workitem/model/Action.java b/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/workitem/model/Action.java new file mode 100644 index 00000000000..6c6c381d0bb --- /dev/null +++ b/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/workitem/model/Action.java @@ -0,0 +1,55 @@ +/******************************************************************************* + * 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.workitem.model; + +import java.util.Collection; +import org.eclipse.osee.ats.api.data.AtsAttributeTypes; +import org.eclipse.osee.ats.api.data.AtsRelationTypes; +import org.eclipse.osee.ats.api.workflow.IAtsAction; +import org.eclipse.osee.ats.api.workflow.IAtsTeamWorkflow; +import org.eclipse.osee.ats.core.model.impl.AtsObject; +import org.eclipse.osee.ats.rest.IAtsServer; +import org.eclipse.osee.framework.jdk.core.type.OseeCoreException; +import org.eclipse.osee.framework.jdk.core.type.OseeStateException; +import org.eclipse.osee.orcs.data.ArtifactReadable; + +public class Action extends AtsObject implements IAtsAction { + + private final IAtsServer atsServer; + + public Action(IAtsServer atsServer, ArtifactReadable artRead) { + super(artRead.getName(), artRead.getUuid()); + this.atsServer = atsServer; + setStoreObject(artRead); + } + + @Override + public Collection<IAtsTeamWorkflow> getTeamWorkflows() throws OseeCoreException { + return atsServer.getRelationResolver().getRelated(this, AtsRelationTypes.ActionToWorkflow_WorkFlow, + IAtsTeamWorkflow.class); + } + + @Override + public String getAtsId() { + try { + return ((ArtifactReadable) getStoreObject()).getSoleAttributeAsString(AtsAttributeTypes.AtsId, + String.valueOf(getUuid())); + } catch (OseeCoreException ex) { + return null; + } + } + + @Override + public void setAtsId(String atsId) throws OseeCoreException { + throw new OseeStateException("Not implemented"); + } + +} diff --git a/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/workitem/model/ActionableItem.java b/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/workitem/model/ActionableItem.java new file mode 100644 index 00000000000..80d8011b66e --- /dev/null +++ b/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/workitem/model/ActionableItem.java @@ -0,0 +1,158 @@ +/******************************************************************************* + * 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.workitem.model; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashSet; +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.team.IAtsTeamDefinition; +import org.eclipse.osee.ats.core.config.TeamDefinitions; +import org.eclipse.osee.ats.core.model.impl.AtsConfigObject; +import org.eclipse.osee.ats.rest.IAtsServer; +import org.eclipse.osee.framework.core.enums.CoreRelationTypes; +import org.eclipse.osee.framework.jdk.core.type.OseeCoreException; +import org.eclipse.osee.framework.jdk.core.type.ResultSet; +import org.eclipse.osee.logger.Log; +import org.eclipse.osee.orcs.data.ArtifactReadable; + +/** + * @author Donald G Dunne + */ +public class ActionableItem extends AtsConfigObject implements IAtsActionableItem { + + public ActionableItem(Log logger, IAtsServer atsServer, ArtifactReadable artifact) { + super(logger, atsServer, artifact); + } + + @Override + public Collection<IAtsActionableItem> getChildrenActionableItems() { + Set<IAtsActionableItem> children = new HashSet<>(); + try { + for (ArtifactReadable childArt : getArtifact().getRelated(CoreRelationTypes.Default_Hierarchical__Child)) { + IAtsActionableItem childTeamDef = atsServices.getConfigItemFactory().getActionableItem(childArt); + children.add(childTeamDef); + } + } catch (OseeCoreException ex) { + getLogger().error(ex, "Error getting Children Actionable Items"); + } + return children; + } + + private ArtifactReadable getArtifact() { + return (ArtifactReadable) artifact; + } + + @Override + public IAtsActionableItem getParentActionableItem() { + IAtsActionableItem parent = null; + try { + ResultSet<ArtifactReadable> related = getArtifact().getRelated(CoreRelationTypes.Default_Hierarchical__Parent); + if (!related.isEmpty()) { + parent = atsServices.getConfigItemFactory().getActionableItem(related.iterator().next()); + } + } catch (OseeCoreException ex) { + getLogger().error(ex, "Error getParentActionableItem"); + } + return parent; + } + + @Override + public IAtsTeamDefinition getTeamDefinition() { + IAtsTeamDefinition teamDef = null; + try { + ResultSet<ArtifactReadable> related = getArtifact().getRelated(AtsRelationTypes.TeamActionableItem_Team); + if (!related.isEmpty()) { + teamDef = atsServices.getConfigItemFactory().getTeamDef(related.iterator().next()); + } + } catch (OseeCoreException ex) { + getLogger().error(ex, "Error getTeamDefinition"); + } + return teamDef; + } + + @Override + public IAtsTeamDefinition getTeamDefinitionInherited() { + return TeamDefinitions.getImpactedTeamDef(this); + } + + @Override + public void setParentActionableItem(IAtsActionableItem parentActionableItem) { + throw new UnsupportedOperationException("Error ActionableItem.setParentActionableItem not implemented"); + } + + @Override + public void setTeamDefinition(IAtsTeamDefinition teamDef) { + throw new UnsupportedOperationException("Error ActionableItem.setTeamDefinition not implemented"); + } + + @Override + public void setActionable(boolean actionable) { + throw new UnsupportedOperationException("Error ActionableItem.setActionable not implemented"); + } + + @Override + public void setActive(boolean active) { + throw new UnsupportedOperationException("Error ActionableItem.setActive not implemented"); + } + + @Override + public String getTypeName() { + return "Actionable Item"; + } + + @Override + public boolean isAllowUserActionCreation() { + return getArtifact().getSoleAttributeValue(AtsAttributeTypes.AllowUserActionCreation, true); + } + + @Override + public void setAllowUserActionCreation(boolean allowUserActionCreation) { + throw new UnsupportedOperationException("Error ActionableItem.setAllowUserActionCreation not implemented"); + } + + @Override + public void addRule(String rule) { + throw new UnsupportedOperationException("ActionableItem.addRule not implemented"); + } + + @Override + public Collection<String> getRules() { + Collection<String> rules = new ArrayList<>(); + try { + rules = getArtifact().getAttributeValues(AtsAttributeTypes.RuleDefinition); + } catch (OseeCoreException ex) { + getLogger().error(ex, "Error getting rules"); + } + return rules; + } + + @Override + public boolean hasRule(String rule) { + boolean result = false; + for (String rule2 : getRules()) { + if (rule.equals(rule2)) { + result = true; + break; + } + } + return result; + } + + @Override + public void removeRule(String rule) { + throw new UnsupportedOperationException("ActionableItem.setActionable not implemented"); + } + +} diff --git a/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/workitem/model/DecisionReview.java b/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/workitem/model/DecisionReview.java new file mode 100644 index 00000000000..ae83f1169e1 --- /dev/null +++ b/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/workitem/model/DecisionReview.java @@ -0,0 +1,27 @@ +/******************************************************************************* + * 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.workitem.model; + +import org.eclipse.osee.ats.api.review.IAtsDecisionReview; +import org.eclipse.osee.ats.rest.IAtsServer; +import org.eclipse.osee.logger.Log; +import org.eclipse.osee.orcs.data.ArtifactReadable; + +/** + * @author Donald G. Dunne + */ +public class DecisionReview extends AbstractReview implements IAtsDecisionReview { + + public DecisionReview(Log logger, IAtsServer atsServer, ArtifactReadable artifact) { + super(logger, atsServer, artifact); + } + +} diff --git a/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/workitem/model/Goal.java b/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/workitem/model/Goal.java new file mode 100644 index 00000000000..3869a8e0657 --- /dev/null +++ b/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/workitem/model/Goal.java @@ -0,0 +1,27 @@ +/******************************************************************************* + * 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.workitem.model; + +import org.eclipse.osee.ats.api.workflow.IAtsGoal; +import org.eclipse.osee.ats.rest.IAtsServer; +import org.eclipse.osee.logger.Log; +import org.eclipse.osee.orcs.data.ArtifactReadable; + +/** + * @author Donald G. Dunne + */ +public class Goal extends WorkItem implements IAtsGoal { + + public Goal(Log logger, IAtsServer atsServer, ArtifactReadable artifact) { + super(logger, atsServer, artifact); + } + +} diff --git a/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/workitem/model/PeerToPeerReview.java b/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/workitem/model/PeerToPeerReview.java new file mode 100644 index 00000000000..b11e9920e51 --- /dev/null +++ b/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/workitem/model/PeerToPeerReview.java @@ -0,0 +1,27 @@ +/******************************************************************************* + * 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.workitem.model; + +import org.eclipse.osee.ats.api.review.IAtsPeerToPeerReview; +import org.eclipse.osee.ats.rest.IAtsServer; +import org.eclipse.osee.logger.Log; +import org.eclipse.osee.orcs.data.ArtifactReadable; + +/** + * @author Donald G Dunne + */ +public class PeerToPeerReview extends AbstractReview implements IAtsPeerToPeerReview { + + public PeerToPeerReview(Log logger, IAtsServer atsServer, ArtifactReadable artifact) { + super(logger, atsServer, artifact); + } + +} diff --git a/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/workitem/model/Task.java b/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/workitem/model/Task.java new file mode 100644 index 00000000000..190955b27a5 --- /dev/null +++ b/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/workitem/model/Task.java @@ -0,0 +1,27 @@ +/******************************************************************************* + * 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.workitem.model; + +import org.eclipse.osee.ats.api.workflow.IAtsTask; +import org.eclipse.osee.ats.rest.IAtsServer; +import org.eclipse.osee.logger.Log; +import org.eclipse.osee.orcs.data.ArtifactReadable; + +/** + * @author Donald G. Dunne + */ +public class Task extends WorkItem implements IAtsTask { + + public Task(Log logger, IAtsServer atsServer, ArtifactReadable artifact) { + super(logger, atsServer, artifact); + } + +} diff --git a/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/workitem/model/TeamDefinition.java b/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/workitem/model/TeamDefinition.java new file mode 100644 index 00000000000..5fb5bb1d87d --- /dev/null +++ b/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/workitem/model/TeamDefinition.java @@ -0,0 +1,398 @@ +/******************************************************************************* + * 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.workitem.model; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashSet; +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.team.IAtsTeamDefinition; +import org.eclipse.osee.ats.api.team.TeamDefinitionOptions; +import org.eclipse.osee.ats.api.user.IAtsUser; +import org.eclipse.osee.ats.api.version.IAtsVersion; +import org.eclipse.osee.ats.api.version.VersionLockedType; +import org.eclipse.osee.ats.api.version.VersionReleaseType; +import org.eclipse.osee.ats.core.model.impl.AtsConfigObject; +import org.eclipse.osee.ats.rest.IAtsServer; +import org.eclipse.osee.framework.core.enums.CoreRelationTypes; +import org.eclipse.osee.framework.core.util.Result; +import org.eclipse.osee.framework.jdk.core.type.OseeCoreException; +import org.eclipse.osee.framework.jdk.core.type.ResultSet; +import org.eclipse.osee.logger.Log; +import org.eclipse.osee.orcs.data.ArtifactReadable; + +/** + * @author Donald G Dunne + */ +public class TeamDefinition extends AtsConfigObject implements IAtsTeamDefinition { + + private final IAtsServer atsServer; + + public TeamDefinition(Log logger, IAtsServer atsServer, ArtifactReadable artifact) { + super(logger, atsServer, artifact); + this.atsServer = atsServer; + } + + @Override + public String getTypeName() { + return "Team Definition"; + } + + private ArtifactReadable getArtifact() { + return (ArtifactReadable) artifact; + } + + @Override + public Collection<IAtsActionableItem> getActionableItems() { + Set<IAtsActionableItem> ais = new HashSet<>(); + try { + for (ArtifactReadable aiArt : getArtifact().getRelated(AtsRelationTypes.TeamActionableItem_ActionableItem)) { + IAtsActionableItem ai = atsServices.getConfigItemFactory().getActionableItem(aiArt); + ais.add(ai); + } + } catch (OseeCoreException ex) { + getLogger().error(ex, "Error getActionableItems"); + } + return ais; + } + + @Override + public void setParentTeamDef(IAtsTeamDefinition parentTeamDef) { + getLogger().error("TeamDefinition.setParentTeamDef not implemented"); + } + + @Override + public IAtsTeamDefinition getParentTeamDef() { + IAtsTeamDefinition parent = null; + try { + ResultSet<ArtifactReadable> related = getArtifact().getRelated(CoreRelationTypes.Default_Hierarchical__Parent); + if (!related.isEmpty()) { + parent = atsServices.getConfigItemFactory().getTeamDef(related.iterator().next()); + } + } catch (OseeCoreException ex) { + getLogger().error(ex, "Error getParentTeamDef"); + } + return parent; + } + + @Override + public Collection<IAtsTeamDefinition> getChildrenTeamDefinitions() { + Set<IAtsTeamDefinition> children = new HashSet<>(); + try { + for (ArtifactReadable childArt : getArtifact().getRelated(CoreRelationTypes.Default_Hierarchical__Child)) { + IAtsTeamDefinition childTeamDef = atsServices.getConfigItemFactory().getTeamDef(childArt); + if (childTeamDef != null) { + children.add(childTeamDef); + } + } + } catch (OseeCoreException ex) { + getLogger().error(ex, "Error getChildrenTeamDefinitions"); + } + return children; + } + + @Override + public Collection<IAtsUser> getLeads(Collection<IAtsActionableItem> actionableItems) { + Set<IAtsUser> leads = new HashSet<>(); + 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()); + } else { + if (aia.getTeamDefinitionInherited() != null) { + leads.addAll(aia.getTeamDefinitionInherited().getLeads()); + } + } + } + } + if (leads.isEmpty()) { + leads.addAll(getLeads()); + } + return leads; + } + + @Override + public Collection<IAtsUser> getMembers() { + return getRelatedUsers(AtsRelationTypes.TeamMember_Member); + } + + @Override + public Collection<IAtsUser> getMembersAndLeads() { + Set<IAtsUser> results = new HashSet<>(); + results.addAll(getLeads()); + results.addAll(getMembers()); + return results; + } + + @Override + public Collection<IAtsUser> getPrivilegedMembers() { + return getRelatedUsers(AtsRelationTypes.PrivilegedMember_Member); + } + + @Override + public void setAllowCommitBranch(boolean allowCommitBranch) { + throw new UnsupportedOperationException("TeamDefinition.setAllowCommitBranch not implemented"); + } + + @Override + public boolean isAllowCommitBranch() { + boolean set = false; + try { + set = getArtifact().getSoleAttributeValue(AtsAttributeTypes.AllowCommitBranch, false); + } catch (OseeCoreException ex) { + getLogger().error(ex, "Error is allow commit branch"); + } + return set; + } + + @Override + public Result isAllowCommitBranchInherited() { + if (!isAllowCommitBranch()) { + return new Result(false, "Team Definition [" + this + "] not configured to allow branch commit."); + } + if (getBaselineBranchUuid() <= 0) { + return new Result(false, "Parent Branch not configured for Team Definition [" + this + "]"); + } + return Result.TrueResult; + } + + @Override + public void setAllowCreateBranch(boolean allowCreateBranch) { + throw new UnsupportedOperationException("TeamDefinition.setAllowCreateBranch not implemented"); + } + + @Override + public boolean isAllowCreateBranch() { + boolean set = false; + try { + set = getArtifact().getSoleAttributeValue(AtsAttributeTypes.AllowCreateBranch, false); + } catch (OseeCoreException ex) { + getLogger().error(ex, "Error get allow create branch"); + } + return set; + } + + @Override + public Result isAllowCreateBranchInherited() { + if (!isAllowCreateBranch()) { + return new Result(false, "Branch creation disabled for Team Definition [" + this + "]"); + } + if (getBaselineBranchUuid() <= 0) { + return new Result(false, "Parent Branch not configured for Team Definition [" + this + "]"); + } + return Result.TrueResult; + } + + @Override + public void setBaselineBranchUuid(long uuid) { + throw new UnsupportedOperationException("TeamDefinition.setBaselineBranchUuid not implemented"); + } + + @Override + public void setBaselineBranchUuid(String uuid) { + throw new UnsupportedOperationException("TeamDefinition.setBaselineBranchUuid not implemented"); + } + + @Override + public long getBaselineBranchUuid() { + return Long.valueOf((String) getAttributeValue(AtsAttributeTypes.BaselineBranchUuid, "0")); + } + + @Override + public long getTeamBranchUuid() { + long uuid = getBaselineBranchUuid(); + if (uuid > 0) { + return uuid; + } else { + IAtsTeamDefinition parentTeamDef = getParentTeamDef(); + if (parentTeamDef instanceof TeamDefinition) { + return parentTeamDef.getTeamBranchUuid(); + } + } + return 0; + } + + @Override + public String getCommitFullDisplayName() { + return getName(); + } + + @Override + public boolean isTeamUsesVersions() throws OseeCoreException { + return getTeamDefinitionHoldingVersions() != null; + } + + @Override + public IAtsVersion getNextReleaseVersion() { + IAtsVersion result = null; + for (IAtsVersion version : getVersions()) { + if (version.isNextVersion()) { + result = version; + break; + } + } + return result; + } + + @Override + public IAtsTeamDefinition getTeamDefinitionHoldingVersions() throws OseeCoreException { + IAtsTeamDefinition teamDef = null; + if (getVersions().size() > 0) { + teamDef = this; + } else { + IAtsTeamDefinition parentTda = getParentTeamDef(); + if (parentTda != null) { + teamDef = parentTda.getTeamDefinitionHoldingVersions(); + } + } + return teamDef; + } + + @Override + public IAtsVersion getVersion(String name) { + IAtsVersion result = null; + for (IAtsVersion version : getVersions()) { + if (version.getName().equals(name)) { + result = version; + break; + } + } + return result; + } + + @Override + public Collection<IAtsVersion> getVersions() { + Set<IAtsVersion> results = new HashSet<>(); + try { + for (ArtifactReadable verArt : getArtifact().getRelated(AtsRelationTypes.TeamDefinitionToVersion_Version)) { + IAtsVersion version = (IAtsVersion) atsServer.getConfig().getSoleByUuid(verArt.getUuid()); + results.add(version); + } + } catch (OseeCoreException ex) { + getLogger().error(ex, "Error getting versions"); + } + return results; + } + + @Override + public Collection<IAtsVersion> getVersions(VersionReleaseType releaseType, VersionLockedType lockedType) { + return org.eclipse.osee.framework.jdk.core.util.Collections.setIntersection(getVersionsReleased(releaseType), + getVersionsLocked(lockedType)); + } + + @Override + public Collection<IAtsVersion> getVersionsFromTeamDefHoldingVersions(VersionReleaseType releaseType, VersionLockedType lockedType) throws OseeCoreException { + IAtsTeamDefinition teamDef = getTeamDefinitionHoldingVersions(); + if (teamDef == null) { + return new ArrayList<IAtsVersion>(); + } + return teamDef.getVersions(releaseType, lockedType); + } + + @Override + public Collection<IAtsVersion> getVersionsLocked(VersionLockedType lockType) { + ArrayList<IAtsVersion> versions = new ArrayList<>(); + for (IAtsVersion version : getVersions()) { + if (version.isVersionLocked() && (lockType == VersionLockedType.Locked || lockType == VersionLockedType.Both)) { + versions.add(version); + } else if ((!version.isVersionLocked() && lockType == VersionLockedType.UnLocked) || lockType == VersionLockedType.Both) { + versions.add(version); + } + } + return versions; + } + + @Override + public Collection<IAtsVersion> getVersionsReleased(VersionReleaseType releaseType) { + ArrayList<IAtsVersion> versions = new ArrayList<>(); + for (IAtsVersion version : getVersions()) { + if (version.isReleased() && (releaseType == VersionReleaseType.Released || releaseType == VersionReleaseType.Both)) { + versions.add(version); + } else if ((!version.isReleased() && releaseType == VersionReleaseType.UnReleased) || releaseType == VersionReleaseType.Both) { + versions.add(version); + } + } + return versions; + } + + @Override + public void setWorkflowDefinition(String workflowDefinitionName) { + throw new UnsupportedOperationException("TeamDefinition.setWorkflowDefinition not implemented"); + } + + @Override + public String getWorkflowDefinition() { + return getAttributeValue(AtsAttributeTypes.WorkflowDefinition, ""); + } + + @Override + public String getRelatedTaskWorkDefinition() { + return getAttributeValue(AtsAttributeTypes.RelatedTaskWorkDefinition, ""); + } + + @Override + public void setRelatedTaskWorkDefinition(String name) { + throw new UnsupportedOperationException("TeamDefinition.setRelatedTaskWorkDefinition not implemented"); + } + + @Override + public void initialize(String fullname, String description, Collection<IAtsUser> leads, Collection<IAtsUser> members, Collection<IAtsActionableItem> actionableItems, TeamDefinitionOptions... teamDefinitionOptions) { + throw new UnsupportedOperationException("TeamDefinition.setActionable not implemented"); + } + + @Override + public String getRelatedPeerWorkDefinition() { + return getAttributeValue(AtsAttributeTypes.RelatedPeerWorkflowDefinition, ""); + } + + @Override + public void setRelatedPeerWorkDefinition(String relatedPeerWorkDefinition) { + throw new UnsupportedOperationException("TeamDefinition.setRelatedPeerWorkDefinition not implemented"); + } + + @Override + public void addRule(String rule) { + throw new UnsupportedOperationException("TeamDefinition.addRule not implemented"); + } + + @Override + public Collection<String> getRules() { + Collection<String> rules = new ArrayList<>(); + try { + rules = getArtifact().getAttributeValues(AtsAttributeTypes.RuleDefinition); + } catch (OseeCoreException ex) { + getLogger().error(ex, "Error getting rules"); + } + return rules; + } + + @Override + public boolean hasRule(String rule) { + boolean result = false; + for (String rule2 : getRules()) { + if (rule.equals(rule2)) { + result = true; + break; + } + } + return result; + } + + @Override + public void removeRule(String rule) { + throw new UnsupportedOperationException("TeamDefinition.setActionable not implemented"); + } + +} diff --git a/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/workitem/model/TeamWorkflow.java b/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/workitem/model/TeamWorkflow.java new file mode 100644 index 00000000000..a37b63a1422 --- /dev/null +++ b/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/workitem/model/TeamWorkflow.java @@ -0,0 +1,65 @@ +/******************************************************************************* + * 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.workitem.model; + +import java.util.HashSet; +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.team.IAtsTeamDefinition; +import org.eclipse.osee.ats.api.workflow.IAtsTeamWorkflow; +import org.eclipse.osee.ats.rest.IAtsServer; +import org.eclipse.osee.framework.jdk.core.type.OseeCoreException; +import org.eclipse.osee.logger.Log; +import org.eclipse.osee.orcs.data.ArtifactReadable; + +/** + * @author Donald G. Dunne + */ +public class TeamWorkflow extends WorkItem implements IAtsTeamWorkflow { + + public TeamWorkflow(Log logger, IAtsServer atsServer, ArtifactReadable artifact) { + super(logger, atsServer, artifact); + } + + @Override + public Set<IAtsActionableItem> getActionableItems() throws OseeCoreException { + Set<IAtsActionableItem> ais = new HashSet<>(); + for (Object aiGuidObj : artifact.getAttributeValues(AtsAttributeTypes.ActionableItem)) { + String aiGuid = (String) aiGuidObj; + Long uuid = getAtsServer().getStoreService().getUuidFromGuid(aiGuid); + if (uuid != null) { + IAtsActionableItem ai = getAtsServer().getConfig().getSoleByUuid(uuid, IAtsActionableItem.class); + if (ai == null) { + ArtifactReadable aiArt = getAtsServer().getArtifactByGuid(aiGuid); + ai = getAtsServer().getConfigItemFactory().getActionableItem(aiArt); + } + ais.add(ai); + } + } + return ais; + } + + @Override + public IAtsTeamDefinition getTeamDefinition() throws OseeCoreException { + IAtsTeamDefinition teamDef = null; + String teamDefGuid = artifact.getSoleAttributeValue(AtsAttributeTypes.TeamDefinition); + Long uuid = getAtsServer().getStoreService().getUuidFromGuid(teamDefGuid); + if (uuid != null) { + teamDef = getAtsServer().getConfig().getSoleByUuid(uuid, IAtsTeamDefinition.class); + if (teamDef == null) { + ArtifactReadable teamDefArt = getAtsServer().getArtifactByGuid(teamDefGuid); + teamDef = getAtsServer().getConfigItemFactory().getTeamDef(teamDefArt); + } + } + return teamDef; + } +} diff --git a/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/workitem/model/Version.java b/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/workitem/model/Version.java new file mode 100644 index 00000000000..0f68f9b6347 --- /dev/null +++ b/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/workitem/model/Version.java @@ -0,0 +1,227 @@ +/******************************************************************************* + * 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.workitem.model; + +import java.util.ArrayList; +import java.util.Date; +import java.util.List; +import java.util.Set; +import org.eclipse.osee.ats.api.commit.ICommitConfigItem; +import org.eclipse.osee.ats.api.data.AtsAttributeTypes; +import org.eclipse.osee.ats.api.data.AtsRelationTypes; +import org.eclipse.osee.ats.api.team.IAtsTeamDefinition; +import org.eclipse.osee.ats.api.version.IAtsVersion; +import org.eclipse.osee.ats.core.model.impl.AtsConfigObject; +import org.eclipse.osee.ats.rest.IAtsServer; +import org.eclipse.osee.framework.core.util.Result; +import org.eclipse.osee.framework.jdk.core.type.OseeCoreException; +import org.eclipse.osee.framework.jdk.core.util.Collections; +import org.eclipse.osee.framework.jdk.core.util.Strings; +import org.eclipse.osee.logger.Log; +import org.eclipse.osee.orcs.data.ArtifactReadable; + +/** + * @author Donald G. Dunne + */ +public class Version extends AtsConfigObject implements IAtsVersion { + + public Version(Log logger, IAtsServer atsServer, ArtifactReadable artifact) { + super(logger, atsServer, artifact); + } + + private ArtifactReadable getArtifact() { + return (ArtifactReadable) artifact; + } + + @Override + public List<IAtsVersion> getParallelVersions() { + List<IAtsVersion> parallelVersions = new ArrayList<>(); + for (ArtifactReadable parallelVerArt : getArtifact().getRelated(AtsRelationTypes.ParallelVersion_Child)) { + IAtsVersion parallelVer = atsServices.getConfigItemFactory().getVersion(parallelVerArt); + parallelVersions.add(parallelVer); + } + return parallelVersions; + } + + @Override + public void getParallelVersions(Set<ICommitConfigItem> configArts) { + configArts.add(this); + for (IAtsVersion childArt : getParallelVersions()) { + childArt.getParallelVersions(configArts); + } + } + + @Override + public void setParallelVersions(List<IAtsVersion> parallelVersions) { + throw new UnsupportedOperationException("Version.setParallelVersions not implemented"); + } + + @Override + public String getCommitFullDisplayName() { + List<String> strs = new ArrayList<>(); + strs.add(getName()); + String fullName = getArtifact().getSoleAttributeValue(AtsAttributeTypes.FullName, ""); + if (Strings.isValid(fullName)) { + strs.add(fullName); + } + String description = getArtifact().getSoleAttributeValue(AtsAttributeTypes.Description, ""); + if (Strings.isValid(description)) { + strs.add(description); + } + return Collections.toString(" - ", strs); + } + + @Override + public Result isAllowCreateBranchInherited() { + if (!isAllowCreateBranch()) { + return new Result(false, "Branch creation disabled for Version [" + this + "]"); + } + if (!atsServices.getBranchService().isBranchValid(this)) { + return new Result(false, "Parent Branch not configured for Version [" + this + "]"); + } + return Result.TrueResult; + } + + @Override + public boolean isAllowCreateBranch() { + return getArtifact().getSoleAttributeValue(AtsAttributeTypes.AllowCreateBranch, false); + } + + @Override + public void setAllowCreateBranch(boolean allow) { + throw new UnsupportedOperationException("Version.setAllowCreateBranch not implemented"); + } + + @Override + public boolean isAllowCommitBranch() { + return getArtifact().getSoleAttributeValue(AtsAttributeTypes.AllowCommitBranch, false); + } + + @Override + public void setAllowCommitBranch(boolean allow) { + throw new UnsupportedOperationException("Version.setAllowCommitBranch not implemented"); + } + + @Override + public Result isAllowCommitBranchInherited() { + if (!isAllowCommitBranch()) { + return new Result(false, "Version [" + this + "] not configured to allow branch commit."); + } + if (!atsServices.getBranchService().isBranchValid(this)) { + return new Result(false, "Parent Branch not configured for Version [" + this + "]"); + } + return Result.TrueResult; + } + + @Override + public Date getReleaseDate() { + return getArtifact().getSoleAttributeValue(AtsAttributeTypes.ReleaseDate, null); + } + + @Override + public void setReleaseDate(Date date) { + throw new UnsupportedOperationException("Version.setReleaseDate not implemented"); + } + + @Override + public void setReleasedDate(Date Date) { + throw new UnsupportedOperationException("Version.setReleasedDate not implemented"); + } + + @Override + public Boolean isReleased() { + return getArtifact().getSoleAttributeValue(AtsAttributeTypes.Released, false); + } + + @Override + public void setReleased(boolean released) { + throw new UnsupportedOperationException("Version.setReleased not implemented"); + } + + @Override + public Date getEstimatedReleaseDate() { + return getArtifact().getSoleAttributeValue(AtsAttributeTypes.EstimatedReleaseDate, (Date) null); + } + + @Override + public void setEstimatedReleasedDate(Date date) { + throw new UnsupportedOperationException("Version.setEstimatedReleasedDate not implemented"); + } + + @Override + public boolean isLocked() { + return getArtifact().getSoleAttributeValue(AtsAttributeTypes.VersionLocked, false); + } + + @Override + public Boolean isVersionLocked() { + return isLocked(); + } + + @Override + public void setLocked(boolean locked) { + throw new UnsupportedOperationException("Version.setLocked not implemented"); + } + + @Override + public void setVersionLocked(boolean locked) { + throw new UnsupportedOperationException("Version.setVersionLocked not implemented"); + } + + @Override + public Boolean isNextVersion() { + return getArtifact().getSoleAttributeValue(AtsAttributeTypes.NextVersion, false); + } + + @Override + public void setNextVersion(boolean nextVersion) { + throw new UnsupportedOperationException("Version.setNextVersion not implemented"); + } + + @Override + public String getTypeName() { + return "Version"; + } + + @Override + public long getBaselineBranchUuid() { + return Long.parseLong(getArtifact().getSoleAttributeAsString(AtsAttributeTypes.BaselineBranchUuid, "-1")); + } + + @Override + public long getBaselineBranchUuidInherited() { + if (getBaselineBranchUuid() > 0) { + return getBaselineBranchUuid(); + } else { + try { + IAtsTeamDefinition teamDef = atsServices.getVersionService().getTeamDefinition(this); + if (teamDef != null) { + return teamDef.getTeamBranchUuid(); + } else { + return 0; + } + } catch (OseeCoreException ex) { + return 0; + } + } + } + + @Override + public void setBaselineBranchUuid(long uuid) { + throw new UnsupportedOperationException("Version.setBaselineBranchUuid not implemented"); + } + + @Override + public void setBaselineBranchUuid(String uuid) { + throw new UnsupportedOperationException("Version.setBaselineBranchUuid not implemented"); + } + +} diff --git a/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/workitem/model/WorkItem.java b/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/workitem/model/WorkItem.java new file mode 100644 index 00000000000..038df26900b --- /dev/null +++ b/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/workitem/model/WorkItem.java @@ -0,0 +1,276 @@ +/******************************************************************************* + * 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.workitem.model; + +import java.util.Date; +import java.util.List; +import org.eclipse.osee.ats.api.IAtsWorkItem; +import org.eclipse.osee.ats.api.data.AtsAttributeTypes; +import org.eclipse.osee.ats.api.data.AtsRelationTypes; +import org.eclipse.osee.ats.api.review.IAtsAbstractReview; +import org.eclipse.osee.ats.api.user.IAtsUser; +import org.eclipse.osee.ats.api.util.IAtsChangeSet; +import org.eclipse.osee.ats.api.workdef.IAtsStateDefinition; +import org.eclipse.osee.ats.api.workdef.IAtsWorkDefinition; +import org.eclipse.osee.ats.api.workdef.IWorkDefinitionMatch; +import org.eclipse.osee.ats.api.workflow.IAtsAction; +import org.eclipse.osee.ats.api.workflow.IAtsGoal; +import org.eclipse.osee.ats.api.workflow.IAtsTask; +import org.eclipse.osee.ats.api.workflow.IAtsTeamWorkflow; +import org.eclipse.osee.ats.api.workflow.log.IAtsLog; +import org.eclipse.osee.ats.api.workflow.state.IAtsStateManager; +import org.eclipse.osee.ats.core.model.impl.AtsObject; +import org.eclipse.osee.ats.rest.IAtsServer; +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.OseeStateException; +import org.eclipse.osee.framework.jdk.core.type.ResultSet; +import org.eclipse.osee.logger.Log; +import org.eclipse.osee.orcs.data.ArtifactReadable; + +/** + * @author Donald G Dunne + */ +public class WorkItem extends AtsObject implements IAtsWorkItem { + + protected final ArtifactReadable artifact; + public static final int TRANSACTION_SENTINEL = -1; + private IAtsStateManager stateMgr; + private IAtsLog atsLog; + private IWorkDefinitionMatch match; + private final IAtsServer atsServer; + private final Log logger; + + public WorkItem(Log logger, IAtsServer atsServer, ArtifactReadable artifact) { + super(artifact.getName(), artifact.getUuid()); + this.logger = logger; + this.atsServer = atsServer; + this.artifact = artifact; + } + + protected IAtsServer getAtsServer() { + return atsServer; + } + + @Override + public String getDescription() { + try { + return artifact.getSoleAttributeAsString(AtsAttributeTypes.Description, ""); + } catch (OseeCoreException ex) { + logger.error(ex, "Error getting description for artifact[%s]", artifact); + return "exception: " + ex.getLocalizedMessage(); + } + } + + @Override + public List<IAtsUser> getAssignees() throws OseeCoreException { + return getStateMgr().getAssignees(); + } + + @Override + public List<IAtsUser> getImplementers() throws OseeCoreException { + throw new OseeStateException("Not implemented"); + } + + @Override + public String getAtsId() { + try { + return artifact.getSoleAttributeAsString(AtsAttributeTypes.AtsId, String.valueOf(getUuid())); + } catch (OseeCoreException ex) { + return null; + } + } + + @Override + public void setAtsId(String atsId, IAtsChangeSet changes) throws OseeCoreException { + throw new UnsupportedOperationException("Not implemented"); + } + + @Override + public IAtsTeamWorkflow getParentTeamWorkflow() throws OseeCoreException { + ArtifactReadable teamArt = null; + if (isTeamWorkflow()) { + teamArt = artifact; + } else if (isReview()) { + ResultSet<ArtifactReadable> results = artifact.getRelated(AtsRelationTypes.TeamWorkflowToReview_Team); + if (!results.isEmpty()) { + teamArt = results.iterator().next(); + } + } else if (isTask()) { + ResultSet<ArtifactReadable> results = artifact.getRelated(AtsRelationTypes.TeamWfToTask_TeamWf); + if (!results.isEmpty()) { + teamArt = results.iterator().next(); + } + } + return atsServer.getWorkItemFactory().getTeamWf(teamArt); + } + + @Override + public IAtsAction getParentAction() { + ArtifactReadable actionArt = null; + IAtsTeamWorkflow teamWf = getParentTeamWorkflow(); + if (teamWf != null) { + ResultSet<ArtifactReadable> results = + ((ArtifactReadable) teamWf.getStoreObject()).getRelated(AtsRelationTypes.ActionToWorkflow_Action); + if (!results.isEmpty()) { + actionArt = results.iterator().next(); + } + } + return atsServer.getWorkItemFactory().getAction(actionArt); + } + + @Override + public boolean isReview() { + return this instanceof IAtsAbstractReview; + } + + @Override + public boolean isGoal() { + return this instanceof IAtsGoal; + } + + @Override + public IAtsStateManager getStateMgr() { + if (stateMgr == null) { + try { + stateMgr = getAtsServer().getStateFactory().getStateManager(this, true); + } catch (OseeCoreException ex) { + logger.error(ex, "Error getting stateManager for artifact[%s]", artifact); + } + } + return stateMgr; + } + + @Override + public void setStateManager(IAtsStateManager stateMgr) { + this.stateMgr = stateMgr; + } + + @Override + public IAtsLog getLog() { + if (atsLog == null) { + try { + atsLog = getAtsServer().getLogFactory().getLogLoaded(this, atsServer.getAttributeResolver()); + } catch (OseeCoreException ex) { + logger.error(ex, "Error getting Log for artifact[%s]", artifact); + } + } + return atsLog; + } + + @Override + public IAtsWorkDefinition getWorkDefinition() { + if (match == null) { + match = getWorkDefinitionMatch(); + if (match == null) { + return null; + } + if (!match.isMatched()) { + logger.error("Error getting work definition for artifact[%s] - using match [%s]", artifact, match); + return null; + } + } + return match.getWorkDefinition(); + } + + public IWorkDefinitionMatch getWorkDefinitionMatch() { + if (match == null) { + try { + match = getAtsServer().getWorkDefAdmin().getWorkDefinition(this); + } catch (Exception ex) { + logger.error("Error getting work definition match for artifact[%s]: Exception %s", artifact, + ex.getLocalizedMessage()); + } + } + return match; + } + + @Override + public IAtsStateDefinition getStateDefinition() { + if (getStateMgr().getCurrentStateName() == null) { + return null; + } + return getWorkDefinition().getStateByName(getStateMgr().getCurrentStateName()); + } + + public IAtsStateDefinition getStateDefinitionByName(String name) { + return getWorkDefinition().getStateByName(name); + } + + @Override + public boolean isTask() { + return this instanceof IAtsTask; + } + + @Override + public boolean isTeamWorkflow() { + return this instanceof IAtsTeamWorkflow; + } + + @Override + public ArtifactId getStoreObject() { + return artifact; + } + + @Override + public IAtsUser getCreatedBy() { + String userId = artifact.getSoleAttributeValue(AtsAttributeTypes.CreatedBy, null); + return atsServer.getUserService().getUserById(userId); + } + + @Override + public Date getCreatedDate() { + return artifact.getSoleAttributeValue(AtsAttributeTypes.CreatedDate, null); + } + + @Override + public IAtsUser getCompletedBy() { + String userId = artifact.getSoleAttributeValue(AtsAttributeTypes.CompletedBy, null); + return atsServer.getUserService().getUserById(userId); + } + + @Override + public IAtsUser getCancelledBy() { + String userId = artifact.getSoleAttributeValue(AtsAttributeTypes.CancelledBy, null); + return atsServer.getUserService().getUserById(userId); + } + + @Override + public String getCompletedFromState() { + return artifact.getSoleAttributeValue(AtsAttributeTypes.CompletedFromState, null); + } + + @Override + public String getCancelledFromState() { + return artifact.getSoleAttributeValue(AtsAttributeTypes.CancelledFromState, null); + } + + @Override + public String getArtifactTypeName() { + return artifact.getArtifactType().getName(); + } + + @Override + public Date getCompletedDate() { + return artifact.getSoleAttributeValue(AtsAttributeTypes.CompletedDate, null); + } + + @Override + public Date getCancelledDate() { + return artifact.getSoleAttributeValue(AtsAttributeTypes.CancelledDate, null); + } + + @Override + public String getCancelledReason() { + return artifact.getSoleAttributeValue(AtsAttributeTypes.CancelledReason, null); + } + +} |