Skip to main content
summaryrefslogtreecommitdiffstats
blob: 966aed8b8a470d44b1f32dfe33c18002be8abe65 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
/*******************************************************************************
 * 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.io.File;
import java.io.FileInputStream;
import java.net.URI;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.LinkedList;
import java.util.List;
import javax.ws.rs.GET;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.Status;
import javax.ws.rs.core.UriBuilder;
import javax.ws.rs.core.UriInfo;
import org.codehaus.jackson.map.ObjectMapper;
import org.eclipse.nebula.widgets.xviewer.core.model.CustomizeData;
import org.eclipse.osee.ats.api.IAtsWorkItem;
import org.eclipse.osee.ats.api.agile.AgileBurndown;
import org.eclipse.osee.ats.api.agile.AgileEndpointApi;
import org.eclipse.osee.ats.api.agile.AgileItem;
import org.eclipse.osee.ats.api.agile.AgileUtil;
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.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.JaxAgileSprint;
import org.eclipse.osee.ats.api.agile.JaxAgileTeam;
import org.eclipse.osee.ats.api.agile.JaxBurndownExcel;
import org.eclipse.osee.ats.api.agile.JaxNewAgileBacklog;
import org.eclipse.osee.ats.api.agile.JaxNewAgileFeatureGroup;
import org.eclipse.osee.ats.api.agile.JaxNewAgileSprint;
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.api.util.IAtsChangeSet;
import org.eclipse.osee.ats.api.workflow.JaxAtsObjects;
import org.eclipse.osee.ats.core.users.AtsCoreUsers;
import org.eclipse.osee.ats.rest.IAtsServer;
import org.eclipse.osee.ats.rest.internal.util.RestUtil;
import org.eclipse.osee.ats.rest.internal.world.WorldResource;
import org.eclipse.osee.framework.core.data.ArtifactId;
import org.eclipse.osee.framework.core.data.AttributeTypeId;
import org.eclipse.osee.framework.core.enums.CoreArtifactTypes;
import org.eclipse.osee.framework.core.enums.CoreAttributeTypes;
import org.eclipse.osee.framework.core.enums.CoreBranches;
import org.eclipse.osee.framework.core.enums.CoreRelationTypes;
import org.eclipse.osee.framework.jdk.core.type.ClassBasedResourceToken;
import org.eclipse.osee.framework.jdk.core.type.IResourceRegistry;
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.Conditions;
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.jaxrs.OseeWebApplicationException;
import org.eclipse.osee.jdbc.JdbcService;
import org.eclipse.osee.orcs.data.ArtifactReadable;
import org.eclipse.osee.template.engine.PageCreator;
import org.eclipse.osee.template.engine.PageFactory;

/**
 * Donald G. Dunne
 */
public class AgileEndpointImpl implements AgileEndpointApi {

   @Context
   private UriInfo uriInfo;
   private final IAtsServer atsServer;
   private final IResourceRegistry resourceRegistry;
   private static ObjectMapper mapper;
   private final JdbcService jdbcService;

   public AgileEndpointImpl(IAtsServer atsServer, IResourceRegistry resourceRegistry, JdbcService jdbcService) {
      this.atsServer = atsServer;
      this.resourceRegistry = resourceRegistry;
      this.jdbcService = jdbcService;
   }

   public void setUriInfo(UriInfo uriInfo) {
      this.uriInfo = uriInfo;
   }

   /********************************
    ** Agile Team
    ***********************************/
   @Override
   public String get() {
      return "Agile Resource";
   }

   @Override
   public List<JaxAgileTeam> team() throws Exception {
      List<JaxAgileTeam> teams = new ArrayList<>();
      for (IAgileTeam team : atsServer.getAgileService().getTeams()) {
         teams.add(toJaxTeam(team));
      }
      return teams;
   }

   @Override
   public JaxAgileTeam getTeam(long teamUuid) {
      IAgileTeam team = atsServer.getAgileService().getAgileTeamById(teamUuid);
      return toJaxTeam(team);
   }

   @Override
   public Response createTeam(JaxNewAgileTeam newTeam) {
      // validate title
      if (!Strings.isValid(newTeam.getName())) {
         throw new OseeWebApplicationException(Status.BAD_REQUEST, "name is not valid");
      }

      Long uuid = newTeam.getUuid();
      if (uuid == null || uuid <= 0) {
         newTeam.setUuid(Lib.generateArtifactIdAsInt());
      }

      IAgileTeam updatedTeam = atsServer.getAgileService().createAgileTeam(newTeam);
      JaxAgileTeam created = toJaxTeam(updatedTeam);

      UriBuilder builder = uriInfo.getRequestUriBuilder();
      URI location = builder.path("teams").path(String.valueOf(created.getUuid())).build();
      Response response = Response.created(location).entity(created).build();
      return response;
   }

   @Override
   public Response updateTeam(JaxAgileTeam team) {
      IAgileTeam updatedTeam = atsServer.getAgileService().updateAgileTeam(team);
      JaxAgileTeam created = toJaxTeam(updatedTeam);

      UriBuilder builder = uriInfo.getRequestUriBuilder();
      URI location = builder.path("teams").path(String.valueOf(created.getUuid())).build();
      Response response = Response.created(location).entity(created).build();
      return response;
   }

   private JaxAgileTeam toJaxTeam(IAgileTeam updatedTeam) {
      JaxAgileTeam created = new JaxAgileTeam();
      created.setName(updatedTeam.getName());
      created.setUuid(updatedTeam.getId());
      created.setActive(updatedTeam.isActive());
      created.getAtsTeamUuids().addAll(updatedTeam.getAtsTeamUuids());
      created.setBacklogUuid(updatedTeam.getBacklogUuid());
      created.setDescription(updatedTeam.getDescription());
      return created;
   }

   @Override
   public Response deleteTeam(long teamUuid) {
      atsServer.getAgileService().deleteAgileTeam(teamUuid);
      return Response.ok().build();
   }

   /********************************
    ** Agile Team Feature
    ***********************************/

   @Override
   public List<JaxAgileFeatureGroup> getFeatureGroups(long teamUuid) {
      List<JaxAgileFeatureGroup> groups = new LinkedList<>();
      ArtifactReadable agileTeamArt = atsServer.getArtifact(teamUuid);
      for (ArtifactReadable child : agileTeamArt.getChildren()) {
         if (child.getName().equals(AgileUtil.FEATURE_GROUP_FOLDER_NAME)) {
            for (ArtifactReadable subChild : child.getChildren()) {
               if (subChild.isOfType(AtsArtifactTypes.AgileFeatureGroup)) {
                  IAgileFeatureGroup group = atsServer.getConfigItemFactory().getAgileFeatureGroup(subChild);
                  JaxAgileFeatureGroup newGroup = new JaxAgileFeatureGroup();
                  newGroup.setName(group.getName());
                  newGroup.setUuid(group.getId());
                  newGroup.setActive(group.isActive());
                  newGroup.setTeamUuid(group.getTeamUuid());
                  groups.add(newGroup);
               }
            }
         }
      }
      return groups;
   }

   @Override
   public Response createFeatureGroup(long teamUuid, JaxNewAgileFeatureGroup newFeatureGroup) {
      // validate title
      if (!Strings.isValid(newFeatureGroup.getName())) {
         throw new OseeWebApplicationException(Status.BAD_REQUEST, "name is not valid");
      }
      if (newFeatureGroup.getTeamUuid() <= 0) {
         throw new OseeWebApplicationException(Status.BAD_REQUEST, "teamUuid is not valid");
      }

      String guid = GUID.create();
      Long uuid = newFeatureGroup.getUuid();
      if (uuid == null || uuid <= 0) {
         uuid = Lib.generateArtifactIdAsInt();
      }

      IAgileFeatureGroup team = atsServer.getAgileService().createAgileFeatureGroup(newFeatureGroup.getTeamUuid(),
         newFeatureGroup.getName(), guid, uuid);
      JaxAgileFeatureGroup newGroup = new JaxAgileFeatureGroup();
      newGroup.setName(team.getName());
      newGroup.setUuid(team.getId());
      newGroup.setActive(team.isActive());
      newGroup.setTeamUuid(team.getTeamUuid());

      UriBuilder builder = uriInfo.getRequestUriBuilder();
      URI location = builder.path("teams").path(String.valueOf(newGroup.getTeamUuid())).path("features").path(
         String.valueOf(newGroup.getUuid())).build();
      return Response.created(location).entity(newGroup).build();
   }

   @Override
   public JaxAgileFeatureGroup getFeatureGroup(long teamUuid, long featureUuid) {
      IAgileFeatureGroup feature =
         atsServer.getAgileService().getAgileFeatureGroups(Arrays.asList(featureUuid)).iterator().next();
      JaxAgileFeatureGroup created = new JaxAgileFeatureGroup();
      created.setName(feature.getName());
      created.setUuid(feature.getId());
      created.setTeamUuid(feature.getTeamUuid());
      created.setActive(feature.isActive());
      return created;
   }

   @Override
   public Response deleteFeatureGroup(long teamUuid, long featureUuid) {
      atsServer.getAgileService().deleteAgileFeatureGroup(featureUuid);
      return Response.ok().build();
   }

   /********************************
    ** Agile Sprint
    ***********************************/
   @Override
   public Response createSprint(long teamUuid, JaxNewAgileSprint newSprint) {
      // validate title
      if (!Strings.isValid(newSprint.getName())) {
         throw new OseeWebApplicationException(Status.BAD_REQUEST, "name is not valid");
      }
      if (newSprint.getTeamUuid() <= 0) {
         throw new OseeWebApplicationException(Status.BAD_REQUEST, "teamUuid is not valid");
      }

      String guid = GUID.create();
      Long uuid = newSprint.getUuid();
      if (uuid == null || uuid <= 0) {
         uuid = Lib.generateArtifactIdAsInt();
      }

      IAgileSprint sprint =
         atsServer.getAgileService().createAgileSprint(newSprint.getTeamUuid(), newSprint.getName(), guid, uuid);
      JaxAgileSprint created = toJaxSprint(sprint);

      UriBuilder builder = uriInfo.getRequestUriBuilder();
      URI location = builder.path("teams").path(String.valueOf(newSprint.getTeamUuid())).path("sprints").path(
         String.valueOf(sprint.getId())).build();
      return Response.created(location).entity(created).build();
   }

   private JaxAgileSprint toJaxSprint(IAgileSprint sprint) {
      JaxAgileSprint created = new JaxAgileSprint();
      created.setName(sprint.getName());
      created.setActive(sprint.isActive());
      created.setUuid(sprint.getId());
      created.setTeamUuid(sprint.getTeamUuid());
      return created;
   }

   @Override
   public List<JaxAgileSprint> getSprints(long teamUuid) {
      if (teamUuid <= 0) {
         throw new OseeWebApplicationException(Status.NOT_FOUND, "teamUuid is not valid");
      }
      List<JaxAgileSprint> sprints = new ArrayList<>();
      for (IAgileSprint sprint : atsServer.getAgileService().getSprintsForTeam(teamUuid)) {
         sprints.add(toJaxSprint(sprint));
      }
      return sprints;
   }

   @Override
   public Response getSprintSummary(long teamUuid, long sprintUuid) {

      if (teamUuid <= 0) {
         throw new OseeWebApplicationException(Status.NOT_FOUND, "teamUuid is not valid");
      }
      if (sprintUuid <= 0) {
         throw new OseeWebApplicationException(Status.NOT_FOUND, "sprintUuid is not valid");
      }

      ArtifactReadable sprint = getSprint(sprintUuid);
      SprintPageBuilder page = new SprintPageBuilder(sprint);
      PageCreator appPage = PageFactory.newPageCreator(resourceRegistry);
      String result =
         page.generatePage(appPage, new ClassBasedResourceToken("sprintTemplate.html", SprintPageBuilder.class));

      return Response.ok().entity(result).build();
   }

   @Override
   public Response getSprintBurndown(long teamUuid, long sprintUuid) {
      if (teamUuid <= 0) {
         throw new OseeWebApplicationException(Status.NOT_FOUND, "teamUuid is not valid");
      }
      if (sprintUuid <= 0) {
         throw new OseeWebApplicationException(Status.NOT_FOUND, "sprintUuid is not valid");
      }
      ArtifactReadable sprintArt = getSprint(sprintUuid);
      IAgileTeam agileTeam = atsServer.getAgileService().getAgileTeam(teamUuid);
      IAgileSprint sprint = atsServer.getAgileService().getAgileSprint(sprintArt);

      SprintBurndownDataBuilder builder = new SprintBurndownDataBuilder(agileTeam, sprint, atsServer, jdbcService);
      AgileBurndown burndown = builder.get();

      return Response.ok().entity(burndown).build();
   }

   @Override
   public Response getSprintBurndownUi(long teamUuid, long sprintUuid) {
      if (teamUuid <= 0) {
         throw new OseeWebApplicationException(Status.NOT_FOUND, "teamUuid is not valid");
      }
      if (sprintUuid <= 0) {
         throw new OseeWebApplicationException(Status.NOT_FOUND, "sprintUuid is not valid");
      }
      ArtifactReadable sprintArt = getSprint(sprintUuid);
      IAgileTeam agileTeam = atsServer.getAgileService().getAgileTeam(teamUuid);
      IAgileSprint sprint = atsServer.getAgileService().getAgileSprint(sprintArt);

      SprintBurndownDataBuilder builder = new SprintBurndownDataBuilder(agileTeam, sprint, atsServer, jdbcService);
      AgileBurndown burndown = builder.get();

      SprintBurndownPageBuilder pageBuilder = new SprintBurndownPageBuilder(burndown);
      String html = pageBuilder.getHtml();

      return Response.ok().entity(html).build();
   }

   private ArtifactReadable getSprint(long sprintUuid) {
      ArtifactReadable sprint = atsServer.getOrcsApi().getQueryFactory().fromBranch(CoreBranches.COMMON).andUuid(
         new Long(sprintUuid).intValue()).getResults().getAtMostOneOrNull();
      if (sprint == null) {
         throw new OseeCoreException("Sprint for id:%d not found", sprintUuid);
      }
      return sprint;
   }

   @Override
   public Response deleteSprint(long teamUuid, long sprintUuid) {
      atsServer.getAgileService().deleteSprint(sprintUuid);
      return Response.ok().build();
   }

   /********************************
    ** Agile Backlog
    ***********************************/
   @Override
   public Response createBacklog(long teamUuid, JaxNewAgileBacklog newBacklog) {
      // validate title
      if (!Strings.isValid(newBacklog.getName())) {
         throw new OseeWebApplicationException(Status.BAD_REQUEST, "name is not valid");
      }
      if (newBacklog.getTeamUuid() <= 0) {
         throw new OseeWebApplicationException(Status.BAD_REQUEST, "teamUuid is not valid");
      }

      // create new backlog
      IAgileBacklog backlog = null;
      if (!Strings.isValid(newBacklog.getName())) {
         new OseeWebApplicationException(Status.BAD_REQUEST, "name is not valid");
      }

      String guid = GUID.create();
      Long uuid = newBacklog.getUuid();
      if (uuid == null || uuid <= 0) {
         uuid = Lib.generateArtifactIdAsInt();
      }
      ArtifactReadable teamArt = atsServer.getArtifact(newBacklog.getTeamUuid());
      if (!teamArt.getRelated(AtsRelationTypes.AgileTeamToBacklog_Backlog).isEmpty()) {
         new OseeWebApplicationException(Status.BAD_REQUEST, "Backlog already set for team %s",
            teamArt.toStringWithId());
      }

      backlog =
         atsServer.getAgileService().createAgileBacklog(newBacklog.getTeamUuid(), newBacklog.getName(), guid, uuid);
      JaxAgileBacklog created = toJaxBacklog(backlog);
      UriBuilder builder = uriInfo.getRequestUriBuilder();
      URI location = builder.path("teams").path(String.valueOf(backlog.getTeamUuid())).path("backlog").build();
      return Response.created(location).entity(created).build();
   }

   @Override
   public Response updateBacklog(long teamUuid, JaxAgileBacklog newBacklog) {
      IAgileBacklog backlog = atsServer.getAgileService().updateAgileBacklog(newBacklog);

      JaxAgileBacklog created = toJaxBacklog(backlog);
      UriBuilder builder = uriInfo.getRequestUriBuilder();
      URI location = builder.path("teams").path(String.valueOf(created.getTeamUuid())).build();
      return Response.created(location).entity(created).build();
   }

   @Override
   public JaxAgileBacklog getBacklog(long teamUuid) {
      if (teamUuid <= 0) {
         throw new OseeWebApplicationException(Status.NOT_FOUND, "teamUuid is not valid");
      }
      IAgileBacklog backlog = atsServer.getAgileService().getBacklogForTeam(teamUuid);
      if (backlog != null) {
         return toJaxBacklog(backlog);
      }
      return null;
   }

   @Override
   public List<AgileItem> getBacklogItems(long teamUuid) {
      List<AgileItem> items = new LinkedList<>();
      IAgileTeam team = atsServer.getAgileService().getAgileTeam(teamUuid);
      IAgileBacklog backlog = atsServer.getAgileService().getAgileBacklog(team);
      if (backlog != null) {
         int x = 1;
         for (IAgileItem aItem : atsServer.getAgileService().getItems(backlog)) {
            AgileItem item = new AgileItem();
            item.setName(aItem.getName());
            item.setFeatureGroups(Collections.toString("; ", atsServer.getAgileService().getFeatureGroups(aItem)));
            item.setUuid(aItem.getId());
            item.setAssignees(Collections.toString("; ", aItem.getStateMgr().getAssigneesStr()));
            item.setAtsId(aItem.getAtsId());
            item.setState(aItem.getStateMgr().getCurrentStateName());
            item.setOrder(x++);
            IAgileSprint sprint = atsServer.getAgileService().getSprint(aItem);
            if (sprint != null) {
               item.setSprint(sprint.getName());
            }
            items.add(item);
         }
      }
      return items;
   }

   private JaxAgileBacklog toJaxBacklog(IAgileBacklog backlog) {
      JaxAgileBacklog result = new JaxAgileBacklog();
      result.setActive(backlog.isActive());
      result.setActive(backlog.isActive());
      result.setName(backlog.getName());
      result.setUuid(backlog.getId());
      result.setTeamUuid(backlog.getTeamUuid());
      return result;
   }

   /********************************
    ** Agile Item
    ***********************************/
   @Override
   public Response updateItem(long itemUuid, JaxAgileItem newItem) {
      // validate uuid
      if (newItem.getUuids().isEmpty()) {
         throw new OseeWebApplicationException(Status.NOT_FOUND, "itemUuid is not valid");
      }

      JaxAgileItem sprint = atsServer.getAgileService().updateItem(newItem);
      JaxAgileItem item = new JaxAgileItem();
      item.getUuids().addAll(sprint.getUuids());
      item.getFeatures().addAll(sprint.getFeatures());
      item.setSprintUuid(sprint.getSprintUuid());

      UriBuilder builder = uriInfo.getRequestUriBuilder();
      URI location = builder.path("team").path(String.valueOf(item.getSprintUuid())).build();
      return Response.created(location).entity(item).build();
   }

   @Override
   public Response updateItems(JaxAgileItem newItem) {
      JaxAgileItem sprint = atsServer.getAgileService().updateItem(newItem);
      JaxAgileItem item = new JaxAgileItem();
      item.getUuids().addAll(sprint.getUuids());
      item.getFeatures().addAll(sprint.getFeatures());
      item.setSprintUuid(sprint.getSprintUuid());

      UriBuilder builder = uriInfo.getRequestUriBuilder();
      URI location = builder.path("team").path(String.valueOf(item.getSprintUuid())).build();
      return Response.created(location).entity(item).build();
   }

   /********************************
    ** Sprint Reporting
    ***********************************/
   @Override
   public JaxAtsObjects getSprintItemsAsJax(long teamUuid, long sprintUuid) {
      ArtifactReadable sprintArt = atsServer.getArtifact(sprintUuid);
      JaxAtsObjects objs = new JaxAtsObjects();
      for (IAtsWorkItem workItem : atsServer.getWorkItemFactory().getWorkItems(
         sprintArt.getRelated(AtsRelationTypes.AgileSprintToItem_AtsItem).getList())) {
         objs.getAtsObjects().add(JaxAtsObjects.create(workItem));
      }
      return objs;
   }

   public Collection<IAtsWorkItem> getSprintItems(long teamUuid, long sprintUuid) {
      ArtifactReadable sprintArt = atsServer.getArtifact(sprintUuid);
      return atsServer.getWorkItemFactory().getWorkItems(
         sprintArt.getRelated(AtsRelationTypes.AgileSprintToItem_AtsItem).getList());
   }

   @Override
   public Response getSprintItemsUI(long teamUuid, long sprintUuid) {
      ArtifactReadable sprintArt = atsServer.getArtifact(sprintUuid);
      Conditions.assertNotNull(sprintArt, "Sprint not found with id %s", sprintUuid);
      Collection<IAtsWorkItem> myWorldItems = getSprintItems(teamUuid, sprintUuid);
      CustomizeData custData = getDefaultAgileCustData();
      Conditions.assertNotNull(custData, "Can't retrieve default customization");
      String table =
         WorldResource.getCustomizedTable(atsServer, "Sprint - " + sprintArt.getName(), custData, myWorldItems);
      return Response.ok().entity(table).build();
   }

   private CustomizeData getDefaultAgileCustData() {
      CustomizeData result = null;
      try {
         String custDataStr = RestUtil.getResource("support/DefaultAgileCustomization.json");
         if (Strings.isValid(custDataStr)) {
            result = getMapper().readValue(custDataStr, CustomizeData.class);
         }
      } catch (Exception ex) {
         ex.printStackTrace();
      }
      return result;
   }

   @Override
   public Response getSprintItemsUICustomized(long teamUuid, long sprintUuid, String customizeGuid) {
      ArtifactReadable sprintArt = atsServer.getArtifact(sprintUuid);
      Conditions.assertNotNull(sprintArt, "Sprint not found with id %s", sprintUuid);
      Collection<IAtsWorkItem> myWorldItems = getSprintItems(teamUuid, sprintUuid);
      CustomizeData custData = atsServer.getCustomizationByGuid(customizeGuid);
      Conditions.assertNotNull(custData, "Can't retrieve customization with id %s", customizeGuid);
      String table =
         WorldResource.getCustomizedTable(atsServer, "Sprint - " + sprintArt.getName(), custData, myWorldItems);
      return Response.ok().entity(table).build();
   }

   public static ObjectMapper getMapper() {
      if (mapper == null) {
         mapper = new ObjectMapper();
         mapper.setDateFormat(new SimpleDateFormat("MMM d, yyyy h:mm:ss aa"));
      }
      return mapper;
   }

   @Override
   @PUT
   @Path("item/{itemId}/feature")
   public Response addFeatureGroup(@PathParam("itemId") long itemId, String featureGroupName) {
      ArtifactReadable itemArt = atsServer.getArtifact(itemId);
      Conditions.assertNotNull(itemArt, "Work Item not found with id %s", itemId);
      IAgileItem item = atsServer.getWorkItemFactory().getAgileItem(itemArt);
      boolean found = false;
      // check to make sure item is not already related
      for (IAgileFeatureGroup feature : atsServer.getAgileService().getFeatureGroups(item)) {
         if (feature.getName().equals(featureGroupName)) {
            found = true;
            break;
         }
      }
      if (!found) {
         IAgileTeam team = atsServer.getAgileService().getAgileTeam(item);
         for (ArtifactReadable featureArt : ((ArtifactReadable) team.getStoreObject()).getRelated(
            AtsRelationTypes.AgileTeamToFeatureGroup_FeatureGroup)) {
            if (featureArt.getName().equals(featureGroupName)) {
               IAtsChangeSet changes =
                  atsServer.createChangeSet("Add Feature Group to WorkItem", AtsCoreUsers.SYSTEM_USER);
               changes.relate(featureArt, AtsRelationTypes.AgileFeatureToItem_AtsItem, item);
               changes.execute();
               return Response.ok().build();
            }
         }
      }
      return Response.notModified().build();
   }

   @Override
   @PUT
   @Path("item/{itemId}/unplanned")
   public Response setUnPlanned(@PathParam("itemId") long itemId, boolean unPlanned) {
      ArtifactReadable itemArt = atsServer.getArtifact(itemId);
      Conditions.assertNotNull(itemArt, "Work Item not found with id %s", itemId);
      IAgileItem item = atsServer.getWorkItemFactory().getAgileItem(itemArt);
      IAtsChangeSet changes = atsServer.createChangeSet("Set Agile UnPlanned", AtsCoreUsers.SYSTEM_USER);
      changes.setSoleAttributeValue(item, AtsAttributeTypes.UnPlannedWork, unPlanned);
      changes.execute();
      return Response.ok().build();
   }

   @Override
   @PUT
   @Path("item/{itemId}/points")
   public Response setPoints(@PathParam("itemId") long itemId, String points) {
      ArtifactReadable itemArt = atsServer.getArtifact(itemId);
      Conditions.assertNotNull(itemArt, "Work Item not found with id %s", itemId);
      IAgileItem item = atsServer.getWorkItemFactory().getAgileItem(itemArt);
      IAgileTeam team = atsServer.getAgileService().getAgileTeam(item);
      AttributeTypeId agileTeamPointsAttributeType = atsServer.getAgileService().getAgileTeamPointsAttributeType(team);
      IAtsChangeSet changes = atsServer.createChangeSet("Set Points", AtsCoreUsers.SYSTEM_USER);
      changes.setSoleAttributeValue(item, agileTeamPointsAttributeType, points);
      changes.execute();
      return Response.ok().build();
   }

   @Override
   @GET
   @Path("team/{teamUuid}/sprint/{sprintUuid}/burndownExcel")
   @Produces(MediaType.APPLICATION_JSON)
   public Response getSprintBurndownExcel(@PathParam("teamUuid") long teamUuid, @PathParam("sprintUuid") long sprintUuid) {
      JaxBurndownExcel report = new JaxBurndownExcel();
      ArtifactReadable sprintArt = atsServer.getArtifact(sprintUuid);
      IAgileSprint sprint = atsServer.getWorkItemFactory().getAgileSprint(sprintArt);
      Conditions.assertNotNull(sprintArt, "Sprint not found with id %s", sprintUuid);
      ArtifactReadable burndownExcel = null, burndownQuery = null;
      for (ArtifactReadable art : sprintArt.getChildren()) {
         if (art.getName().equals(
            "OSEE_Sprint_Burndown") && art.getSoleAttributeValue(CoreAttributeTypes.Extension, "").equals("xls")) {
            burndownExcel = art;
         } else if (art.getName().equals(
            "OSEE_Sprint_Burndown") && art.getSoleAttributeValue(CoreAttributeTypes.Extension, "").equals("iqy")) {
            burndownQuery = art;
         }
      }
      if ((burndownExcel != null && burndownQuery == null) || (burndownExcel == null && burndownQuery != null)) {
         report.setError(
            "Either OSEE_Sprint_Burndown.xls or OSEE_Sprint_Burndown.iqy was found.  Both need to be found or none.  Names must match exactly.");
         return Response.ok(report).build();
      }
      try {
         // If not found, create and save artifacts related to this burndown
         if (burndownExcel == null) {
            IAtsChangeSet changes = atsServer.createChangeSet("Create Burndown Artifacts", AtsCoreUsers.SYSTEM_USER);

            // Store xls file to OSEE databasePlugin
            File burndownXls = RestUtil.getResourceAsFile("support/OSEE_Sprint_Burndown.xls");
            FileInputStream burndownFileInputStream = new FileInputStream(burndownXls);

            ArtifactId burndownExcelArt =
               changes.createArtifact(CoreArtifactTypes.GeneralDocument, "OSEE_Sprint_Burndown");
            changes.setSoleAttributeValue(burndownExcelArt, CoreAttributeTypes.Extension, "xls");
            changes.setSoleAttributeFromStream(burndownExcelArt, CoreAttributeTypes.NativeContent,
               burndownFileInputStream);
            changes.relate(sprint, CoreRelationTypes.Default_Hierarchical__Child, burndownExcelArt);
            report.setExcelSheetUuid(burndownExcelArt.getUuid());

            // Store query file to OSEE database
            String burndownqry = RestUtil.getResource("support/OSEE_Sprint_Burndown.iqy");
            burndownqry = burndownqry.replace("BASE_URI", uriInfo.getBaseUri().toString());
            IAgileTeam team =
               atsServer.getConfigItemFactory().getAgileTeam(atsServer.getArtifact(sprint.getTeamUuid()));
            burndownqry = burndownqry.replace("TEAM_ID", team.getId().toString());
            burndownqry = burndownqry.replace("SPRINT_ID", sprintArt.getId().toString());
            ArtifactId burndownQryArt =
               changes.createArtifact(CoreArtifactTypes.GeneralDocument, "OSEE_Sprint_Burndown");
            changes.setSoleAttributeValue(burndownQryArt, CoreAttributeTypes.Extension, "iqy");
            changes.setSoleAttributeFromStream(burndownQryArt, CoreAttributeTypes.NativeContent,
               Lib.stringToInputStream(burndownqry));
            changes.relate(sprint, CoreRelationTypes.Default_Hierarchical__Child, burndownQryArt);
            report.setExcelQueryUuid(burndownQryArt.getUuid());

            changes.execute();
         }
         // Else if found
         else {
            ArtifactReadable excelArt = null, queryArt = null;
            for (ArtifactReadable child : sprintArt.getChildren()) {
               if (child.getSoleAttributeValue(CoreAttributeTypes.Extension, "").equals("xls")) {
                  excelArt = child;
                  report.setExcelSheetUuid(excelArt.getUuid());
               } else if (child.getSoleAttributeValue(CoreAttributeTypes.Extension, "").equals("iqy")) {
                  queryArt = child;
                  report.setExcelQueryUuid(queryArt.getUuid());
               }
            }
            if (excelArt == null) {
               report.setError("Could not access Excel burndown artifact.");
            }
            if (queryArt == null) {
               report.setError(report.getError() + "\nCould not access Excel Query burndown artifact.");
            }
         }
      } catch (Exception ex) {
         throw new OseeWebApplicationException(ex, Status.INTERNAL_SERVER_ERROR);
      }
      return Response.ok(report).build();
   }

}

Back to the top