Coveralls logob
Coveralls logo
  • Home
  • Features
  • Pricing
  • Docs
  • Sign In

DSpace / DSpace / 7170

21 Oct 2019 - 14:31 coverage increased (+1.1%) to 36.543%
7170

Pull #2529

travis-ci

9181eb84f9c35729a3bad740fb7f9d93?size=18&default=identiconweb-flow
Evaluated feedback on scripts and processes endpoints and model classes. Added javadoc, fixed tests and made improvements to various parts of the Scripts and processes feature
Pull Request #2529: Scripts and processes endpoint

439 of 666 new or added lines in 29 files covered. (65.92%)

888 existing lines in 25 files now uncovered.

28781 of 78760 relevant lines covered (36.54%)

0.37 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

82.5
/dspace-api/src/main/java/org/dspace/content/virtual/Related.java
1
/**
2
 * The contents of this file are subject to the license and copyright
3
 * detailed in the LICENSE and NOTICE files at the root of the source
4
 * tree and available online at
5
 *
6
 * http://www.dspace.org/license/
7
 */
8
package org.dspace.content.virtual;
9

10
import java.sql.SQLException;
11
import java.util.LinkedList;
12
import java.util.List;
13

14
import org.apache.commons.lang3.StringUtils;
15
import org.dspace.content.Entity;
16
import org.dspace.content.EntityType;
17
import org.dspace.content.Item;
18
import org.dspace.content.Relationship;
19
import org.dspace.content.RelationshipType;
20
import org.dspace.content.service.EntityService;
21
import org.dspace.content.service.EntityTypeService;
22
import org.dspace.content.service.RelationshipService;
23
import org.dspace.content.service.RelationshipTypeService;
24
import org.dspace.core.Context;
25
import org.springframework.beans.factory.annotation.Autowired;
26

27
/**
28
 * A bean implementing the {@link VirtualMetadataConfiguration} interface to achieve the generation of
29
 * Virtual metadata by traversing the path of relation specified in the config for this bean
30
 * The Related bean will find the relationshiptype defined in the relationshipTypeString property on
31
 * the current item and it'll use the related item from that relationship to pass it along to the
32
 * virtualMetadataConfiguration property which in turn refers to another VirtualBean instance and it continues
33
 * the chain until it reaches either a Concatenate or Collected bean to retrieve the values. It will then return
34
 * that value through the chain again and it'll fill the values into the virtual metadata fields that are defined
35
 * in the map for the first Related bean.
36
 */
37
public class Related implements VirtualMetadataConfiguration {
1×
38

39
    @Autowired
40
    private RelationshipTypeService relationshipTypeService;
41

42
    @Autowired
43
    private RelationshipService relationshipService;
44

45
    @Autowired
46
    private EntityTypeService entityTypeService;
47

48
    @Autowired
49
    private EntityService entityService;
50

51
    /**
52
     * The String representing the relationshipType that needs to be used to find the next item
53
     */
54
    private String relationshipTypeString;
55
    /**
56
     * The left or right place that this relationship needs to have to retrieve the proper item
57
     */
58
    private Integer place;
59
    /**
60
     * The next bean to call its getValues() method on
61
     */
62
    private VirtualMetadataConfiguration virtualMetadataConfiguration;
63

64
    /**
65
     * The boolean value indicating whether this field should be used for place or not
66
     */
67
    private boolean useForPlace = false;
1×
68

69
    /**
70
     * Generic getter for the relationshipTypeString property of this class
71
     * @return  The relationshipTypeString property
72
     */
73
    public String getRelationshipTypeString() {
74
        return relationshipTypeString;
1×
75
    }
76

77
    /**
78
     * Generic setter for the relationshipTypeString property of this class
79
     * @param relationshipTypeString    The String to which the relationshipTypeString will be set to
80
     */
81
    public void setRelationshipTypeString(String relationshipTypeString) {
82
        this.relationshipTypeString = relationshipTypeString;
1×
83
    }
1×
84

85
    /**
86
     * Generic getter for the place property of this class
87
     * @return  The place property
88
     */
89
    public Integer getPlace() {
90
        return place;
1×
91
    }
92

93
    /**
94
     * Generic setter for the place property of this class
95
     * @param place The Integer to which the place property will be set to
96
     */
97
    public void setPlace(Integer place) {
98
        this.place = place;
1×
99
    }
1×
100

101
    /**
102
     * Generic getter for the virtualMetadataConfiguration property of this class
103
     * @return  The virtualMetadataConfiguration property
104
     */
105
    public VirtualMetadataConfiguration getVirtualMetadataConfiguration() {
106
        return virtualMetadataConfiguration;
1×
107
    }
108

109
    /**
110
     * Generic setter for the virtualMetadataConfiguration property of this class
111
     * @param virtualMetadataConfiguration   The VirtualBean to which the
112
     *                                             virtualMetadataConfiguration property will be set to
113
     */
114
    public void setVirtualMetadataConfiguration(VirtualMetadataConfiguration
115
                                                        virtualMetadataConfiguration) {
116
        this.virtualMetadataConfiguration = virtualMetadataConfiguration;
1×
117
    }
1×
118

119
    /**
120
     * Generic setter for the useForPlace property
121
     * @param useForPlace   The boolean value that the useForPlace property will be set to
122
     */
123
    @Override
124
    public void setUseForPlace(boolean useForPlace) {
125
        this.useForPlace = useForPlace;
1×
126
    }
1×
127

128
    /**
129
     * Generic getter for the useForPlace property
130
     * @return  The useForPlace to be used by this bean
131
     */
132
    @Override
133
    public boolean getUseForPlace() {
134
        return useForPlace;
1×
135
    }
136

137
    @Override
UNCOV
138
    public void setPopulateWithNameVariant(boolean populateWithNameVariant) { }
!
139

140
    @Override
141
    public boolean getPopulateWithNameVariant() {
UNCOV
142
        return false;
!
143
    }
144

145
    /**
146
     * This method will find the correct Relationship from the given item to retrieve the other item from it
147
     * and pass this along to the next VirtualBean that's stored in this class.
148
     * @param context   The relevant DSpace context
149
     * @param item      The item that will be used to find the related item through its relationships
150
     * @return          The String value of the metadata fields concatened with a seperator as defined
151
     *                  in the deepest Concatened bean in the chain
152
     *                  Will return an empty list if no relationships are found
153
     * @throws SQLException If something goes wrong
154
     */
155
    @Override
156
    public List<String> getValues(Context context, Item item) throws SQLException {
157
        Entity entity = entityService.findByItemId(context, item.getID());
1×
158
        EntityType entityType = entityService.getType(context, entity);
1×
159

160
        List<RelationshipType> relationshipTypes = entityService.getAllRelationshipTypes(context, entity);
1×
161
        List<RelationshipType> possibleRelationshipTypes = new LinkedList<>();
1×
162
        for (RelationshipType relationshipType : relationshipTypes) {
1×
163
            if (StringUtils.equals(relationshipType.getLeftwardType(), relationshipTypeString) || StringUtils
1×
UNCOV
164
                .equals(relationshipType.getRightwardType(), relationshipTypeString)) {
!
165
                possibleRelationshipTypes.add(relationshipType);
1×
166
            }
167
        }
1×
168

169
        List<Relationship> relationships = new LinkedList<>();
1×
170
        for (RelationshipType relationshipType : possibleRelationshipTypes) {
1×
171
            relationships.addAll(relationshipService.findByItemAndRelationshipType(context, item, relationshipType));
1×
172
        }
1×
173

174
        for (Relationship relationship : relationships) {
1×
175
            if (relationship.getRelationshipType().getLeftType() == entityType) {
1×
176
                if (relationship.getLeftPlace() == place) {
1×
177
                    Item otherItem = relationship.getRightItem();
1×
178
                    return virtualMetadataConfiguration.getValues(context, otherItem);
1×
179
                }
UNCOV
180
            } else if (relationship.getRelationshipType().getRightType() == entityType) {
!
UNCOV
181
                if (relationship.getRightPlace() == place) {
!
UNCOV
182
                    Item otherItem = relationship.getLeftItem();
!
UNCOV
183
                    return virtualMetadataConfiguration.getValues(context, otherItem);
!
184
                }
185
            }
186
        }
1×
187

188
        //Return an empty list if no relationships were found
189
        return new LinkedList<>();
1×
190
    }
191

192
}
Troubleshooting · Open an Issue · Sales · Support · ENTERPRISE · CAREERS · STATUS
BLOG · TWITTER · Legal & Privacy · Supported CI Services · What's a CI service? · Automated Testing

© 2019 Coveralls, LLC