Changeset 12
- Timestamp:
- 04/28/20 12:56:50 (5 years ago)
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
pom.xml
r11 r12 6 6 <artifactId>profilesserver</artifactId> 7 7 <packaging>war</packaging> 8 <version>1. 3.1</version>8 <version>1.4.0</version> 9 9 <name>profileserver Maven Webapp</name> 10 10 <url>http://maven.apache.org</url> … … 18 18 <jackson-2-version>2.9.10</jackson-2-version> 19 19 <tomcat.version>8.5.20</tomcat.version> 20 <geniusweb.version>1.4.0</geniusweb.version> 20 21 </properties> 21 22 … … 50 51 <groupId>geniusweb</groupId> 51 52 <artifactId>profile</artifactId> 52 <version> 1.3.1</version>53 <version>${geniusweb.version}</version> 53 54 </dependency> 54 55 … … 56 57 <groupId>geniusweb</groupId> 57 58 <artifactId>bidspace</artifactId> 58 <version> 1.3.1</version>59 <version>${geniusweb.version}</version> 59 60 </dependency> 60 61 … … 213 214 214 215 <build> 215 <finalName>profilesserver</finalName> 216 <finalName>profilesserver-1.4.0</finalName> 217 216 218 217 219 … … 247 249 </executions> 248 250 </plugin> 251 252 <!-- This makes but does not install the jar <plugin> <groupId>org.apache.maven.plugins</groupId> 253 <artifactId>maven-jar-plugin</artifactId> <executions> <execution> <id>make-a-jar</id> 254 <phase>compile</phase> <goals> <goal>jar</goal> </goals> </execution> </executions> 255 </plugin> --> 256 <!-- This does nothign <plugin> <artifactId>maven-war-plugin</artifactId> 257 <configuration> <archiveClasses>true</archiveClasses> </configuration> </plugin> --> 258 259 <plugin> 260 <artifactId>maven-war-plugin</artifactId> 261 <version>3.2.3</version> 262 <configuration> 263 <attachClasses>true</attachClasses> 264 </configuration> 265 </plugin> 266 249 267 <plugin> 250 268 <groupId>org.apache.maven.plugins</groupId> … … 327 345 </executions> 328 346 </plugin> 329 330 <plugin> 331 <groupId>org.apache.maven.plugins</groupId> 332 <artifactId>maven-assembly-plugin</artifactId> 333 <version>2.4.1</version> 334 <configuration> 335 <!-- get all project dependencies --> 336 <descriptorRefs> 337 <descriptorRef>jar-with-dependencies</descriptorRef> 338 </descriptorRefs> 339 <archive> 340 <manifest> 341 <addDefaultImplementationEntries>true</addDefaultImplementationEntries> 342 <addDefaultSpecificationEntries>true</addDefaultSpecificationEntries> 343 </manifest> 344 </archive> 345 </configuration> 346 <executions> 347 <execution> 348 <id>make-assembly</id> 349 <!-- bind to the packaging phase --> 350 <phase>package</phase> 351 <goals> 352 <goal>single</goal> 353 </goals> 354 </execution> 355 </executions> 356 </plugin> 357 347 <!-- <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-assembly-plugin</artifactId> 348 <version>2.4.1</version> <configuration> get all project dependencies <descriptorRefs> 349 <descriptorRef>jar-with-dependencies</descriptorRef> </descriptorRefs> <archive> 350 <manifest> <addDefaultImplementationEntries>true</addDefaultImplementationEntries> 351 <addDefaultSpecificationEntries>true</addDefaultSpecificationEntries> </manifest> 352 </archive> </configuration> <executions> <execution> <id>make-assembly</id> 353 bind to the packaging phase <phase>package</phase> <goals> <goal>single</goal> 354 </goals> </execution> </executions> </plugin> --> 358 355 359 356 <!-- Special plugin for the tomcat embedded stuff? --> … … 410 407 </plugin> 411 408 </plugins> 409 412 410 </pluginManagement> 413 411 -
src/main/java/geniusweb/profilesserver/AutoUpdatingProfilesFactory.java
r8 r12 2 2 3 3 import java.io.File; 4 import java.io.FileWriter; 4 5 import java.io.IOException; 6 import java.io.Writer; 5 7 import java.net.URISyntaxException; 6 8 import java.nio.file.Path; … … 63 65 } 64 66 67 @Override 68 public synchronized void putProfile(Profile profile) throws IOException { 69 if (!available.containsKey(profile.getDomain())) { 70 throw new IOException("profile's domain does not exist"); 71 } 72 String domainname = profile.getDomain().getName(); 73 String profilename = profile.getName(); 74 if (!profilename.matches("[a-zA-Z0-9-]+")) 75 throw new IOException("illegal profile name " + profilename 76 + ", only letters, numbers and - allowed"); 77 File file = Paths 78 .get(rootdir.toString(), domainname, profilename + JSON) 79 .toFile(); 80 if (file.exists()) { 81 String msg = fileCheck(file, false, true); 82 if (msg != null) 83 throw new IOException(msg); 84 } 85 86 // CHECK utf-8 compatibility? Do we need that anyway? 87 try (Writer out = new FileWriter(file, false)) { 88 out.write(Jackson.instance().writeValueAsString(profile)); 89 } 90 // trigger the update immediately, avoid wait for FileChecker. 91 super.add(profile); 92 93 } 94 65 95 /** 66 96 * Called when some file that may be relevant has changed. Synchronized to … … 267 297 268 298 /** 269 * check and report basic problems with a file. 299 * Silent check and report basic problems with a file. Silent in the sense 300 * that errors are logged but cause no exception. 270 301 * 271 302 * @param file the file to check … … 275 306 */ 276 307 private boolean basicFileCheck(File file, boolean shouldbeDirectory) { 308 String msg = fileCheck(file, shouldbeDirectory, false); 309 if (msg != null) { 310 log.log(Level.WARNING, msg); 311 return false; 312 } 313 return true; 314 } 315 316 /** 317 * 318 * @param file the file to check 319 * @param shouldbeDirectory true if expected a directory 320 * @param shouldbeWritable true if expected to be writable 321 * @return null if file is there, is file/directory, allows reading and 322 * allows writing (if specified). 323 */ 324 private String fileCheck(File file, boolean shouldbeDirectory, 325 boolean shouldbeWritable) { 277 326 if (!file.exists()) { 278 log.log(Level.WARNING, file + " is missing"); 279 return false; 327 return file + " is missing"; 280 328 } 281 329 if (!file.canRead()) { 282 log.log(Level.WARNING, 283 "directory " + file + "does not allow reading "); 284 return false; 330 return "directory " + file + "does not allow reading "; 285 331 } 286 332 if (shouldbeDirectory) { 287 333 if (!file.isDirectory()) { 288 log.log(Level.WARNING, file + " is not a directory"); 289 return false; 334 return file + " is not a directory"; 290 335 } 291 336 } else { 292 337 if (!file.isFile()) { 293 log.log(Level.WARNING, file + " is not a file"); 294 return false; 295 } 296 } 297 return true; 338 return file + " is not a file"; 339 } 340 } 341 if (shouldbeWritable && !file.canWrite()) { 342 return file + "is read-only"; 343 } 344 return null; 345 298 346 } 299 347 -
src/main/java/geniusweb/profilesserver/DefaultProfilesFactory.java
r7 r12 1 1 package geniusweb.profilesserver; 2 2 3 import java.io.IOException; 3 4 import java.util.Collections; 4 5 import java.util.LinkedList; … … 84 85 } 85 86 87 @Override 88 public synchronized void putProfile(Profile profile) throws IOException { 89 if (!available.containsKey(profile.getDomain())) { 90 throw new IOException("profile's domain does not exist"); 91 } 92 add(profile); 93 } 94 86 95 /**************** support for updating ***************/ 87 96 /** -
src/main/java/geniusweb/profilesserver/ProfilesFactory.java
r1 r12 1 1 package geniusweb.profilesserver; 2 2 3 import java.io.IOException; 3 4 import java.util.List; 4 5 … … 40 41 List<Profile> getProfiles(String domainname); 41 42 43 /** 44 * Permanently (over)write a profile to the repository (not just in memory). 45 * 46 * @param profile the profile to be written. The domain file must exist and 47 * match. 48 * @throws IOException if the profile does not meet the requirements. 49 */ 50 void putProfile(Profile profile) throws IOException; 51 42 52 } -
src/main/webapp/WEB-INF/web.xml
r1 r12 6 6 <display-name>Domains and Profiles server</display-name> 7 7 8 <servlet> 9 <!-- List files in /ws-definitions --> 10 <servlet-name>listrepo</servlet-name> 11 <servlet-class>org.apache.catalina.servlets.DefaultServlet</servlet-class> 12 <init-param> 13 <param-name>debug</param-name> 14 <param-value>0</param-value> 15 </init-param> 16 <init-param> 17 <param-name>listings</param-name> 18 <param-value>true</param-value> 19 </init-param> 20 <load-on-startup>100</load-on-startup> 21 </servlet> 8 <filter> 9 <filter-name>CorsFilter</filter-name> 10 <filter-class>org.apache.catalina.filters.CorsFilter</filter-class> 11 <init-param> 12 <param-name>cors.allowed.origins</param-name> 13 <param-value>*</param-value> 14 </init-param> 15 <init-param> 16 <param-name>cors.exposed.headers</param-name> 17 <param-value>Access-Control-Allow-Origin</param-value> 18 </init-param> 19 </filter> 20 <filter-mapping> 21 <filter-name>CorsFilter</filter-name> 22 <url-pattern>/*</url-pattern> 23 </filter-mapping> 22 24 23 <servlet-mapping> 24 <servlet-name>listrepo</servlet-name> 25 <url-pattern>/domainsrepo/*</url-pattern> 26 </servlet-mapping> 27 25 <servlet> 26 <!-- List files in /ws-definitions --> 27 <servlet-name>listrepo</servlet-name> 28 <servlet-class>org.apache.catalina.servlets.DefaultServlet</servlet-class> 29 <init-param> 30 <param-name>debug</param-name> 31 <param-value>0</param-value> 32 </init-param> 33 <init-param> 34 <param-name>listings</param-name> 35 <param-value>true</param-value> 36 </init-param> 37 <load-on-startup>100</load-on-startup> 38 </servlet> 39 40 <servlet-mapping> 41 <servlet-name>listrepo</servlet-name> 42 <url-pattern>/domainsrepo/*</url-pattern> 43 </servlet-mapping> 44 28 45 </web-app> 29 46 -
src/test/java/geniusweb/profilesserver/AutoUpdatingProfilesFactoryTest.java
r8 r12 222 222 } 223 223 224 @Test 225 public void saveProfileTest() throws IOException { 226 assertEquals(0, changes.size()); 227 LinearAdditiveUtilitySpace profile = (LinearAdditiveUtilitySpace) factory 228 .getProfile(JOB1); 229 Profile newprofile = new LinearAdditiveUtilitySpace(profile.getDomain(), 230 "jobsA", profile.getUtilities(), profile.getWeights(), 231 profile.getReservationBid()); 232 factory.putProfile(newprofile); 233 // check response immediately 234 assertEquals(1, changes.size()); 235 assertTrue(changes.get(0) instanceof ProfileChangeEvent); 236 // check file was written 237 assertTrue(copyrepodir.resolve("jobs/jobsA.json").toFile().exists()); 238 } 239 224 240 /** 225 241 * We remove jobs domain.
Note:
See TracChangeset
for help on using the changeset viewer.