Skip to main content
summaryrefslogtreecommitdiffstats
blob: f1241cbd259ba4e8338c8db2912d41ec08478206 (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
/*******************************************************************************
 * 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.define.report.api;

import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;
import org.eclipse.osee.framework.jdk.core.util.Strings;

/**
 * @author Angel Avila
 */
@XmlRootElement
public class DataRightResult {

   @XmlTransient
   private List<DataRightAnchor> dataRightAnchors;

   @XmlTransient
   private List<DataRight> dataRights;

   private Map<DataRightId, DataRight> dataRightIdToDataRight;

   private Map<String, DataRightAnchor> guidToAnchor;

   @XmlElement
   public Collection<DataRightAnchor> getDataRightAnchors() {
      if (dataRightAnchors == null) {
         dataRightAnchors = new ArrayList<DataRightAnchor>();
      }
      return dataRightAnchors;
   }

   public void setDataRightAnchors(List<DataRightAnchor> dataRightAnchors) {
      this.dataRightAnchors = dataRightAnchors;
   }

   @XmlElement
   public Collection<DataRight> getDataRights() {
      if (dataRights == null) {
         dataRights = new ArrayList<DataRight>();
      }
      return dataRights;
   }

   public void setDataRights(List<DataRight> dataRights) {
      this.dataRights = dataRights;
   }

   public String getContent(String guid, PageOrientation orientation) {

      checkInitialized();
      String footer = null;

      // account for orientation
      String portrait = String.format(ReportConstants.PAGE_ADDS, ReportConstants.PORTRAIT_ORIENT);
      String landscape = String.format(ReportConstants.PAGE_ADDS, ReportConstants.LANDSCAPE_ORIENT);
      String page_adds = orientation.isLandscape() ? landscape : portrait;

      DataRightAnchor anchor = guidToAnchor.get(guid);
      if (anchor != null) {
         boolean isSetDataRightFooter = anchor.isSetDataRightFooter();
         boolean isContinuous = anchor.isContinuous();
         if (isSetDataRightFooter) {
            // set footer section since next footer differs
            DataRightId key = anchor.getDataRightId();
            if (key != null) {
               DataRight dataRight = dataRightIdToDataRight.get(key);
               if (dataRight != null) {
                  footer = normalize(dataRight.getContent());
                  footer = String.format(ReportConstants.NEW_PAGE_TEMPLATE, footer + page_adds);
               }
            }
         } else if (!isContinuous) {
            // set page break since next footer differs;
            footer = String.format(ReportConstants.NEW_PAGE_TEMPLATE, page_adds);
         }
      }
      return Strings.isValid(footer) ? footer : "";
   }

   private String normalize(String partialFooter) {
      String toReturn = partialFooter;
      if ("NO DATA RIGHTS ARTIFACT FOUND".equals(toReturn)) {
         toReturn = String.format("<w:p><w:r><w:t>%s</w:t></w:r></w:p>", toReturn);
      }
      return toReturn;
   }

   public void reset() {
      dataRightIdToDataRight = null;
      guidToAnchor = null;
   }

   private void checkInitialized() {
      if (dataRightIdToDataRight == null || guidToAnchor == null) {
         dataRightIdToDataRight = new HashMap<DataRightId, DataRight>();
         guidToAnchor = new HashMap<String, DataRightAnchor>();
         for (DataRightAnchor anchor : dataRightAnchors) {
            guidToAnchor.put(anchor.getId(), anchor);
         }

         for (DataRight dataRight : dataRights) {
            dataRightIdToDataRight.put(dataRight.getId(), dataRight);
         }
      }
   }
}

Back to the top