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

SpiNNakerManchester / JavaSpiNNaker / 6809

16 Jul 2025 02:10PM UTC coverage: 36.499%. First build
6809

Pull #1257

github

rowleya
Updates from Dependabot
Pull Request #1257: Fix migration issues

1907 of 5890 branches covered (32.38%)

Branch coverage included in aggregate %.

13 of 16 new or added lines in 2 files covered. (81.25%)

9060 of 24157 relevant lines covered (37.5%)

0.75 hits per line

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

50.0
/SpiNNaker-allocserv/src/main/java/uk/ac/manchester/spinnaker/alloc/web/ControllerUtils.java
1
/*
2
 * Copyright (c) 2021 The University of Manchester
3
 *
4
 * Licensed under the Apache License, Version 2.0 (the "License");
5
 * you may not use this file except in compliance with the License.
6
 * You may obtain a copy of the License at
7
 *
8
 *     https://www.apache.org/licenses/LICENSE-2.0
9
 *
10
 * Unless required by applicable law or agreed to in writing, software
11
 * distributed under the License is distributed on an "AS IS" BASIS,
12
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
 * See the License for the specific language governing permissions and
14
 * limitations under the License.
15
 */
16
package uk.ac.manchester.spinnaker.alloc.web;
17

18
import static java.util.Objects.isNull;
19
import static org.springframework.web.servlet.mvc.method.annotation.MvcUriComponentsBuilder.fromMethodCall;
20

21
import java.net.URI;
22

23
import org.springframework.ui.ModelMap;
24
import org.springframework.validation.ObjectError;
25
import org.springframework.web.servlet.ModelAndView;
26
import org.springframework.web.servlet.mvc.method.annotation.MvcUriComponentsBuilder;
27

28
import com.google.errorprone.annotations.CompileTimeConstant;
29
import com.google.errorprone.annotations.Immutable;
30

31
import uk.ac.manchester.spinnaker.utils.UsedInJavadocOnly;
32

33
/** Utilities to support MVC controllers. */
34
public abstract class ControllerUtils {
35

36
        private ControllerUtils() {
37
        }
38

39
        /**
40
         * Convert the result of calling a
41
         * {@linkplain MvcUriComponentsBuilder#on(Class) component builder delegate}
42
         * into a URL. Fixes the scheme to {@code https} and always ignores the
43
         * query part.
44
         * <p>
45
         * <strong>Do not</strong> define a {@code static} variable holding the
46
         * result of {@link MvcUriComponentsBuilder#on(Class)}; it tries to be
47
         * request-aware, and that defeats it. Rely on the Spring MVC core to do the
48
         * relevant object caching.
49
         *
50
         * @param selfCall
51
         *            component builder delegate result
52
         * @param objects
53
         *            Values to substitute into the template; can be none at all
54
         * @return URL that will invoke the method
55
         * @see MvcUriComponentsBuilder
56
         */
57
        @UsedInJavadocOnly(MvcUriComponentsBuilder.class)
58
        public static URI uri(Object selfCall, Object... objects) {
59

60
                var b = fromMethodCall(selfCall);
2✔
61
                // Force some dumb stuff to be right
62
                if (!System.getenv().containsKey("spalloc_use_http")) {
2!
63
                        b.query(null).scheme("https");
2✔
64
                } else {
NEW
65
                        b.query(null).scheme("http");
×
66
                }
67
                return b.buildAndExpand(objects).toUri();
2✔
68
        }
69

70
        /** The name of the Spring MVC error view. */
71
        public static final String MVC_ERROR = "erroroccurred";
72

73
        /** The main URI variable for JSP pages. */
74
        public static final String MAIN_URI = "mainUri";
75

76
        /** The change password URI variable for JSP pages. */
77
        public static final String CHANGE_PASSWORD_URI = "changePasswordUri";
78

79
        /** The login URI variable for JSP pages. */
80
        public static final String LOGOUT_URI = "logoutUri";
81

82
        /** The logout URI variable for JSP pages. */
83
        public static final String LOGIN_URI = "loginUri";
84

85
        /** The OIDC URI variable for JSP pages. */
86
        public static final String LOGIN_OIDC_URI = "loginOidcUri";
87

88
        /** The Spalloc CSS URI variable for JSP pages. */
89
        public static final String SPALLOC_CSS_URI = "spallocCssUri";
90

91
        /** The Spalloc JS URI variable for JSP pages. */
92
        public static final String SPALLOC_JS_URI = "spallocJsUri";
93

94
        /** The URI path to use to perform logins. */
95
        public static final String LOGIN_PATH = "perform_login";
96

97
        /** The URI path to use to perform OIDC logins. */
98
        public static final String LOGIN_OIDC_PATH =
99
                        "perform_oidc/auth/hbp-ebrains";
100

101
        /** The URI path to use to change passwords. */
102
        public static final String CHANGE_PASSWORD_PATH = "change_password";
103

104
        /** The URI path to use to perform logouts. */
105
        public static final String LOGOUT_PATH = "perform_logout";
106

107
        /** The URI path of the Spalloc CSS file. */
108
        public static final String SPALLOC_CSS_PATH = "resources/spalloc.css";
109

110
        /** The URI path of the Spalloc JS file. */
111
        public static final String SPALLOC_JS_PATH = "resources/spinnaker.js";
112

113
        /**
114
         * Create a view that shows an error to the user.
115
         *
116
         * @param message
117
         *            The error message.
118
         * @return The view.
119
         */
120
        public static ModelAndView error(String message) {
121
                return new ModelAndView(MVC_ERROR, "error", message);
×
122
        }
123

124
        /**
125
         * Convert a problem with validation into a user-suitable error message.
126
         *
127
         * @param error
128
         *            The error detail.
129
         * @return The message.
130
         */
131
        public static String errorMessage(ObjectError error) {
132
                var msg = error.getDefaultMessage();
×
133
                return isNull(msg) ? error.toString() : msg;
×
134
        }
135

136
        /**
137
         * Creates a {@link ModelAndView} on demand.
138
         *
139
         * @author Donal Fellows
140
         */
141
        @Immutable
142
        public static final class ViewFactory {
143
                private final String view;
144

145
                /**
146
                 * @param viewName
147
                 *            The name of the view that this class will make.
148
                 */
149
                public ViewFactory(@CompileTimeConstant final String viewName) {
2✔
150
                        view = viewName;
2✔
151
                }
2✔
152

153
                /**
154
                 * Make an instance.
155
                 *
156
                 * @return The model-and-view, ready for decorating with the model.
157
                 */
158
                public ModelAndView view() {
159
                        return new ModelAndView(view);
×
160
                }
161

162
                /**
163
                 * Make an instance.
164
                 *
165
                 * @param model
166
                 *            The model we want to start with.
167
                 * @return The model-and-view, ready for decorating with the model.
168
                 */
169
                public ModelAndView view(ModelMap model) {
170
                        return new ModelAndView(view, model);
2✔
171
                }
172

173
                /**
174
                 * Make an instance.
175
                 *
176
                 * @param key
177
                 *            Name of item to initially insert in the model.
178
                 * @param value
179
                 *            Value of item to initially insert in the model.
180
                 * @return The model-and-view, ready for decorating with the model.
181
                 */
182
                public ModelAndView view(String key, Object value) {
183
                        return new ModelAndView(view, key, value);
×
184
                }
185
        }
186
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc