• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

openmrs / openmrs-core / 41717832711

30 Oct 2026 04:16PM UTC coverage: 66.75% (+0.003%) from 66.747%
41717832711

push

github

ibacher
TRUNK-6863: Remove the generation token before clearing a node's cache locally (#6791)

1 of 1 new or added line in 1 file covered. (100.0%)

419 existing lines in 31 files now uncovered.

26279 of 39369 relevant lines covered (66.75%)

0.67 hits per line

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

77.78
/api/src/main/java/org/openmrs/BaseCustomizableData.java
1
/**
2
 * This Source Code Form is subject to the terms of the Mozilla Public License,
3
 * v. 2.0. If a copy of the MPL was not distributed with this file, You can
4
 * obtain one at http://mozilla.org/MPL/2.0/. OpenMRS is also distributed under
5
 * the terms of the Healthcare Disclaimer located at http://openmrs.org/license.
6
 *
7
 * Copyright (C) OpenMRS Inc. OpenMRS is a registered trademark and the OpenMRS
8
 * graphic logo is a trademark of OpenMRS Inc.
9
 */
10
package org.openmrs;
11

12
import java.util.ArrayList;
13
import java.util.Collection;
14
import java.util.LinkedHashSet;
15
import java.util.List;
16
import java.util.Set;
17

18
import org.openmrs.attribute.Attribute;
19
import org.openmrs.customdatatype.CustomValueDescriptor;
20
import org.openmrs.customdatatype.Customizable;
21
import org.openmrs.util.CollectionUtil;
22

23
/**
24
 * Extension of {@link BaseOpenmrsData} for classes that support customization via user-defined attributes.
25
 * @param <A> the type of attribute held
26
 * @since 1.9
27
 */
28
public abstract class BaseCustomizableData<A extends Attribute> extends BaseChangeableOpenmrsData implements Customizable<A> {
1 ✔
29
        
30
        private Set<A> attributes = new LinkedHashSet<>();
1 ✔
31
        
32
        /**
33
         * @see org.openmrs.customdatatype.Customizable#getAttributes()
34
         */
35
        @Override
36
        public Set<A> getAttributes() {
37
                return attributes;
1 ✔
38
        }
39
        
40
        /**
41
         * @param attributes the attributes to set
42
         */
43
        public void setAttributes(Set<A> attributes) {
UNCOV
44
                this.attributes = CollectionUtil.setCollection(this.attributes, attributes);
×
UNCOV
45
        }
×
46
        
47
        /**
48
         * @see org.openmrs.customdatatype.Customizable#getActiveAttributes()
49
         */
50
        @Override
51
        public Collection<A> getActiveAttributes() {
52
                List<A> ret = new ArrayList<>();
1 ✔
53
                if (getAttributes() != null) {
1 ✔
54
                        for (A attr : getAttributes()) {
1 ✔
55
                                if (!attr.getVoided()) {
1 ✔
56
                                        ret.add(attr);
1 ✔
57
                                }
58
                        }
1 ✔
59
                }
60
                return ret;
1 ✔
61
        }
62
        
63
        /**
64
         * @see org.openmrs.customdatatype.Customizable#getActiveAttributes(org.openmrs.customdatatype.CustomValueDescriptor)
65
         */
66
        @Override
67
        public List<A> getActiveAttributes(CustomValueDescriptor ofType) {
68
                List<A> ret = new ArrayList<>();
1 ✔
69
                if (getAttributes() != null) {
1 ✔
70
                        for (A attr : getAttributes()) {
1 ✔
71
                                if (attr.getAttributeType().equals(ofType) && !attr.getVoided()) {
1 ✔
72
                                        ret.add(attr);
1 ✔
73
                                }
74
                        }
1 ✔
75
                }
76
                return ret;
1 ✔
77
        }
78
        
79
        /**
80
         * @see org.openmrs.customdatatype.Customizable#addAttribute(Attribute)
81
         */
82
        @Override
83
        public void addAttribute(A attribute) {
84
                if (getAttributes() == null) {
1 ✔
UNCOV
85
                        setAttributes(new LinkedHashSet<>());
×
86
                }
87
                getAttributes().add(attribute);
1 ✔
88
                attribute.setOwner(this);
1 ✔
89
        }
1 ✔
90
        
91
        /**
92
         * Convenience method that voids all existing attributes of the given type, and sets this new one.
93
         * <strong>Should</strong> void the attribute if an attribute with same attribute type already exists and the maxOccurs is set to 1
94
         *
95
         * @param attribute
96
         */
97
        @SuppressWarnings("unchecked")
98
        public void setAttribute(A attribute) {
99
                if (getAttributes() == null) {
1 ✔
100
                        addAttribute(attribute);
×
UNCOV
101
                        return;
×
102
                }
103
                
104
                if (getActiveAttributes(attribute.getAttributeType()).size() == 1) {
1 ✔
105
                        A existing = getActiveAttributes(attribute.getAttributeType()).get(0);
1 ✔
106
                        if (!existing.getValue().equals(attribute.getValue())) {
1 ✔
107
                                if (existing.getId() != null) {
1 ✔
108
                                        existing.setVoided(true);
1 ✔
109
                                } else {
110
                                        getAttributes().remove(existing);
1 ✔
111
                                }
112
                                getAttributes().add(attribute);
1 ✔
113
                                attribute.setOwner(this);
1 ✔
114
                        }
115
                        return;
1 ✔
116
                }
117
                
118
                for (A existing : getActiveAttributes(attribute.getAttributeType())) {
1 ✔
119
                        if (existing.getAttributeType().equals(attribute.getAttributeType())) {
×
120
                                if (existing.getId() != null) {
×
UNCOV
121
                                        existing.setVoided(true);
×
122
                                } else {
UNCOV
123
                                        getAttributes().remove(existing);
×
124
                                }
125
                        }
UNCOV
126
                }
×
127
                getAttributes().add(attribute);
1 ✔
128
                attribute.setOwner(this);
1 ✔
129
        }
1 ✔
130
        
131
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc