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

openmrs / openmrs-core / 41717837886

03 Nov 2026 08:59PM UTC coverage: 68.971% (+0.05%) from 68.922%
41717837886

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%)

413 existing lines in 30 files now uncovered.

26445 of 38342 relevant lines covered (68.97%)

0.69 hits per line

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

77.78
/api/src/main/java/org/openmrs/BaseCustomizableMetadata.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 org.hibernate.annotations.BatchSize;
13
import org.hibernate.envers.Audited;
14
import org.openmrs.attribute.Attribute;
15
import org.openmrs.customdatatype.CustomValueDescriptor;
16
import org.openmrs.customdatatype.Customizable;
17
import org.openmrs.util.CollectionUtil;
18

19
import javax.persistence.CascadeType;
20
import javax.persistence.FetchType;
21
import javax.persistence.JoinColumn;
22
import javax.persistence.MappedSuperclass;
23
import javax.persistence.OneToMany;
24
import javax.persistence.OrderBy;
25
import java.util.ArrayList;
26
import java.util.Collection;
27
import java.util.LinkedHashSet;
28
import java.util.List;
29
import java.util.Set;
30

31
/**
32
 * Extension of {@link org.openmrs.BaseOpenmrsMetadata} for classes that support customization via user-defined attributes.
33
 * @param <A> the type of attribute held
34
 * @since 1.9
35
 */
36
@MappedSuperclass
37
@Audited
38
public abstract class BaseCustomizableMetadata<A extends Attribute> extends BaseChangeableOpenmrsMetadata implements Customizable<A> {
1 ✔
39
        
40
        @OrderBy("voided asc")
1 ✔
41
        @BatchSize(size = 100)
42
        @OneToMany(cascade = CascadeType.ALL, orphanRemoval = true, fetch = FetchType.LAZY)
43
        @JoinColumn(name = "location_id")
44
        private Set<A> attributes = new LinkedHashSet<>();
45
        
46
        /**
47
         * @see org.openmrs.customdatatype.Customizable#getAttributes()
48
         */
49
        @Override
50
        public Set<A> getAttributes() {
51
                return attributes;
1 ✔
52
        }
53
        
54
        /**
55
         * @param attributes the attributes to set
56
         */
57
        public void setAttributes(Set<A> attributes) {
UNCOV
58
                this.attributes = CollectionUtil.setCollection(this.attributes, attributes);
×
UNCOV
59
        }
×
60
        
61
        /**
62
         * @see org.openmrs.customdatatype.Customizable#getActiveAttributes()
63
         */
64
        @Override
65
        public Collection<A> getActiveAttributes() {
66
                List<A> ret = new ArrayList<>();
1 ✔
67
                if (getAttributes() != null) {
1 ✔
68
                        for (A attr : getAttributes()) {
1 ✔
69
                                if (!attr.getVoided()) {
1 ✔
70
                                        ret.add(attr);
1 ✔
71
                                }
72
                        }
1 ✔
73
                }
74
                return ret;
1 ✔
75
        }
76
        
77
        /**
78
         * @see org.openmrs.customdatatype.Customizable#getActiveAttributes(org.openmrs.customdatatype.CustomValueDescriptor)
79
         */
80
        @Override
81
        public List<A> getActiveAttributes(CustomValueDescriptor ofType) {
82
                List<A> ret = new ArrayList<>();
1 ✔
83
                if (getAttributes() != null) {
1 ✔
84
                        for (A attr : getAttributes()) {
1 ✔
85
                                if (attr.getAttributeType().equals(ofType) && !attr.getVoided()) {
1 ✔
86
                                        ret.add(attr);
1 ✔
87
                                }
88
                        }
1 ✔
89
                }
90
                return ret;
1 ✔
91
        }
92
        
93
        /**
94
         * @see org.openmrs.customdatatype.Customizable#addAttribute(Attribute)
95
         */
96
        @Override
97
        public void addAttribute(A attribute) {
98
                if (getAttributes() == null) {
1 ✔
UNCOV
99
                        setAttributes(new LinkedHashSet<>());
×
100
                }
101
                getAttributes().add(attribute);
1 ✔
102
                attribute.setOwner(this);
1 ✔
103
        }
1 ✔
104
        
105
        /**
106
         * Convenience method that voids all existing attributes of the given type, and sets this new one.
107
         * <strong>Should</strong> void the attribute if an attribute with same attribute type already exists and the maxOccurs is set to 1
108
         * <strong>Should</strong> work for attributes with datatypes whose values are stored in other tables
109
         *
110
         * @param attribute
111
         */
112
        public void setAttribute(A attribute) {
113
                if (getAttributes() == null) {
1 ✔
114
                        addAttribute(attribute);
×
UNCOV
115
                        return;
×
116
                }
117
                
118
                if (getActiveAttributes(attribute.getAttributeType()).size() == 1) {
1 ✔
119
                        A existing = getActiveAttributes(attribute.getAttributeType()).get(0);
1 ✔
120
                        if (!existing.getValue().equals(attribute.getValue())) {
1 ✔
121
                                if (existing.getId() != null) {
1 ✔
122
                                        existing.setVoided(true);
1 ✔
123
                                } else {
124
                                        getAttributes().remove(existing);
1 ✔
125
                                }
126
                                getAttributes().add(attribute);
1 ✔
127
                                attribute.setOwner(this);
1 ✔
128
                        }
129
                        return;
1 ✔
130
                }
131
                
132
                for (A existing : getActiveAttributes(attribute.getAttributeType())) {
1 ✔
133
                        if (existing.getAttributeType().equals(attribute.getAttributeType())) {
×
134
                                if (existing.getId() != null) {
×
UNCOV
135
                                        existing.setVoided(true);
×
136
                                } else {
UNCOV
137
                                        getAttributes().remove(existing);
×
138
                                }
139
                        }
UNCOV
140
                }
×
141
                getAttributes().add(attribute);
1 ✔
142
                attribute.setOwner(this);
1 ✔
143
        }
1 ✔
144
        
145
}
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