-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 494bce4
Showing
971 changed files
with
53,171 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
# Operating System Files | ||
|
||
*.DS_Store | ||
Thumbs.db | ||
*.sw? | ||
.#* | ||
*# | ||
*~ | ||
*.sublime-* | ||
|
||
# Build Artifacts | ||
|
||
.gradle/ | ||
build/ | ||
target/ | ||
bin/ | ||
out/ | ||
dependency-reduced-pom.xml | ||
|
||
# Eclipse Project Files | ||
|
||
.classpath | ||
.project | ||
.metadata | ||
.loadpath | ||
bin/ | ||
.settings/ | ||
|
||
# IntelliJ IDEA Files | ||
|
||
*.iml | ||
*.ipr | ||
*.iws | ||
*.idea | ||
|
||
.vscode/ | ||
README.html | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# Core Spring and Spring Boot Lab Projects | ||
|
||
Labs for the Core Spring and Spring Boot courses | ||
|
||
To import these labs into your IDE, import the parent pom `lab/pom.xml` as Maven projects or `lab/build.gradle` as Gradle projects. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
/* | ||
Licensed to the Apache Software Foundation (ASF) under one | ||
or more contributor license agreements. See the NOTICE file | ||
distributed with this work for additional information | ||
regarding copyright ownership. The ASF licenses this file | ||
to you under the Apache License, Version 2.0 (the | ||
"License"); you may not use this file except in compliance | ||
with the License. You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, | ||
software distributed under the License is distributed on an | ||
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
KIND, either express or implied. See the License for the | ||
specific language governing permissions and limitations | ||
under the License. | ||
*/ | ||
|
||
import java.net.*; | ||
import java.io.*; | ||
import java.nio.channels.*; | ||
import java.util.Properties; | ||
|
||
public class MavenWrapperDownloader { | ||
|
||
/** | ||
* Default URL to download the maven-wrapper.jar from, if no 'downloadUrl' is provided. | ||
*/ | ||
private static final String DEFAULT_DOWNLOAD_URL = | ||
"https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.4.2/maven-wrapper-0.4.2.jar"; | ||
|
||
/** | ||
* Path to the maven-wrapper.properties file, which might contain a downloadUrl property to | ||
* use instead of the default one. | ||
*/ | ||
private static final String MAVEN_WRAPPER_PROPERTIES_PATH = | ||
".mvn/wrapper/maven-wrapper.properties"; | ||
|
||
/** | ||
* Path where the maven-wrapper.jar will be saved to. | ||
*/ | ||
private static final String MAVEN_WRAPPER_JAR_PATH = | ||
".mvn/wrapper/maven-wrapper.jar"; | ||
|
||
/** | ||
* Name of the property which should be used to override the default download url for the wrapper. | ||
*/ | ||
private static final String PROPERTY_NAME_WRAPPER_URL = "wrapperUrl"; | ||
|
||
public static void main(String args[]) { | ||
System.out.println("- Downloader started"); | ||
File baseDirectory = new File(args[0]); | ||
System.out.println("- Using base directory: " + baseDirectory.getAbsolutePath()); | ||
|
||
// If the maven-wrapper.properties exists, read it and check if it contains a custom | ||
// wrapperUrl parameter. | ||
File mavenWrapperPropertyFile = new File(baseDirectory, MAVEN_WRAPPER_PROPERTIES_PATH); | ||
String url = DEFAULT_DOWNLOAD_URL; | ||
if(mavenWrapperPropertyFile.exists()) { | ||
FileInputStream mavenWrapperPropertyFileInputStream = null; | ||
try { | ||
mavenWrapperPropertyFileInputStream = new FileInputStream(mavenWrapperPropertyFile); | ||
Properties mavenWrapperProperties = new Properties(); | ||
mavenWrapperProperties.load(mavenWrapperPropertyFileInputStream); | ||
url = mavenWrapperProperties.getProperty(PROPERTY_NAME_WRAPPER_URL, url); | ||
} catch (IOException e) { | ||
System.out.println("- ERROR loading '" + MAVEN_WRAPPER_PROPERTIES_PATH + "'"); | ||
} finally { | ||
try { | ||
if(mavenWrapperPropertyFileInputStream != null) { | ||
mavenWrapperPropertyFileInputStream.close(); | ||
} | ||
} catch (IOException e) { | ||
// Ignore ... | ||
} | ||
} | ||
} | ||
System.out.println("- Downloading from: : " + url); | ||
|
||
File outputFile = new File(baseDirectory.getAbsolutePath(), MAVEN_WRAPPER_JAR_PATH); | ||
if(!outputFile.getParentFile().exists()) { | ||
if(!outputFile.getParentFile().mkdirs()) { | ||
System.out.println( | ||
"- ERROR creating output direcrory '" + outputFile.getParentFile().getAbsolutePath() + "'"); | ||
} | ||
} | ||
System.out.println("- Downloading to: " + outputFile.getAbsolutePath()); | ||
try { | ||
downloadFileFromURL(url, outputFile); | ||
System.out.println("Done"); | ||
System.exit(0); | ||
} catch (Throwable e) { | ||
System.out.println("- Error downloading"); | ||
e.printStackTrace(); | ||
System.exit(1); | ||
} | ||
} | ||
|
||
private static void downloadFileFromURL(String urlString, File destination) throws Exception { | ||
URL website = new URL(urlString); | ||
ReadableByteChannel rbc; | ||
rbc = Channels.newChannel(website.openStream()); | ||
FileOutputStream fos = new FileOutputStream(destination); | ||
fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE); | ||
fos.close(); | ||
rbc.close(); | ||
} | ||
|
||
} |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.8.6/apache-maven-3.8.6-bin.zip | ||
wrapperUrl=https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.1.0/maven-wrapper-3.1.0.jar |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
apply plugin: 'java-library' | ||
|
||
dependencies { | ||
api "org.hibernate:hibernate-entitymanager" | ||
api "com.fasterxml.jackson.core:jackson-annotations" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?xml version="1.0" encoding="UTF-8" standalone="no"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<artifactId>00-rewards-common</artifactId> | ||
<organization> | ||
<name>Spring Training</name> | ||
<url>https://spring.io/training</url> | ||
</organization> | ||
<packaging>jar</packaging> | ||
<parent> | ||
<groupId>io.spring.training.core-spring</groupId> | ||
<artifactId>parentProject</artifactId> | ||
<version>5.3.23</version> | ||
</parent> | ||
<dependencies> | ||
<dependency> | ||
<groupId>org.hibernate</groupId> | ||
<artifactId>hibernate-entitymanager</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.fasterxml.jackson.core</groupId> | ||
<artifactId>jackson-annotations</artifactId> | ||
</dependency> | ||
</dependencies> | ||
</project> |
21 changes: 21 additions & 0 deletions
21
lab/00-rewards-common/src/main/java/common/datetime/DateInterval.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package common.datetime; | ||
|
||
public class DateInterval { | ||
|
||
private SimpleDate start; | ||
|
||
private SimpleDate end; | ||
|
||
public DateInterval(SimpleDate start, SimpleDate end) { | ||
this.start = start; | ||
this.end = end; | ||
} | ||
|
||
public SimpleDate getStart() { | ||
return start; | ||
} | ||
|
||
public SimpleDate getEnd() { | ||
return end; | ||
} | ||
} |
113 changes: 113 additions & 0 deletions
113
lab/00-rewards-common/src/main/java/common/datetime/SimpleDate.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
package common.datetime; | ||
|
||
import java.io.Serializable; | ||
import java.util.Calendar; | ||
import java.util.Date; | ||
import java.util.GregorianCalendar; | ||
import java.text.SimpleDateFormat; | ||
|
||
/** | ||
* A simple wrapper around a calendar for working with dates like 12/29/1977. Does not consider time. | ||
*/ | ||
public class SimpleDate implements Serializable { | ||
|
||
private static final long serialVersionUID = 2285962420279644602L; | ||
|
||
private GregorianCalendar base; | ||
|
||
/** | ||
* Create a new simple date. | ||
* @param month the month | ||
* @param day the day | ||
* @param year the year | ||
*/ | ||
public SimpleDate(int month, int day, int year) { | ||
init(new GregorianCalendar(year, month - 1, day)); | ||
} | ||
|
||
SimpleDate(long time) { | ||
GregorianCalendar cal = new GregorianCalendar(); | ||
cal.setTimeInMillis(time); | ||
init(cal); | ||
} | ||
|
||
private SimpleDate() { | ||
init(new GregorianCalendar()); | ||
} | ||
|
||
private void init(GregorianCalendar cal) { | ||
this.base = trimToDays(cal); | ||
} | ||
|
||
private GregorianCalendar trimToDays(GregorianCalendar cal) { | ||
cal.set(Calendar.HOUR_OF_DAY, 0); | ||
cal.set(Calendar.MINUTE, 0); | ||
cal.set(Calendar.SECOND, 0); | ||
cal.set(Calendar.MILLISECOND, 0); | ||
return cal; | ||
} | ||
|
||
/** | ||
* Returns this simple date as a <code>java.util.Date</code> | ||
* @return this simple date as a Date | ||
*/ | ||
public Date asDate() { | ||
return base.getTime(); | ||
} | ||
|
||
/** | ||
* Returns this date in milliseconds since 1970. | ||
* @return | ||
*/ | ||
public long inMilliseconds() { | ||
return asDate().getTime(); | ||
} | ||
|
||
public int compareTo(Object date) { | ||
SimpleDate other = (SimpleDate) date; | ||
return asDate().compareTo(other.asDate()); | ||
} | ||
|
||
public boolean equals(Object day) { | ||
if (!(day instanceof SimpleDate)) { | ||
return false; | ||
} | ||
SimpleDate other = (SimpleDate) day; | ||
return (base.equals(other.base)); | ||
} | ||
|
||
public int hashCode() { | ||
return 29 * base.hashCode(); | ||
} | ||
|
||
/** | ||
* Returns todays date. A convenient static factory method. | ||
*/ | ||
public static SimpleDate today() { | ||
return new SimpleDate(); | ||
} | ||
|
||
/** | ||
* Converts the specified date to a SimpleDate. Will trim hour, minute, second, and millisecond fields. | ||
* @param date the java.util.Date | ||
* @return the simple date | ||
*/ | ||
public static SimpleDate valueOf(Date date) { | ||
return valueOf(date.getTime()); | ||
} | ||
|
||
/** | ||
* Converts the specified long time value to a SimpleDate. Will trim hour, minute, second, and millisecond fields. | ||
* @param time time in millseconds since 1970 | ||
* @return the time as a SimpleDate | ||
*/ | ||
public static SimpleDate valueOf(long time) { | ||
return new SimpleDate(time); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return new SimpleDateFormat().format(base.getTime()); | ||
} | ||
|
||
} |
34 changes: 34 additions & 0 deletions
34
lab/00-rewards-common/src/main/java/common/datetime/SimpleDateEditor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package common.datetime; | ||
|
||
import java.beans.PropertyEditorSupport; | ||
import java.text.DateFormat; | ||
import java.text.ParseException; | ||
import java.util.Locale; | ||
|
||
/** | ||
* A formatter for Simple date properties. Converts object values to well-formatted strings and strings back to | ||
* values. Usable by a data binding framework for binding user input to the model. | ||
*/ | ||
public class SimpleDateEditor extends PropertyEditorSupport { | ||
|
||
private DateFormat dateFormat = DateFormat.getDateInstance(DateFormat.LONG, Locale.ENGLISH); | ||
|
||
@Override | ||
public String getAsText() { | ||
SimpleDate date = (SimpleDate) getValue(); | ||
if (date == null) { | ||
return ""; | ||
} else { | ||
return dateFormat.format(date.asDate()); | ||
} | ||
} | ||
|
||
@Override | ||
public void setAsText(String text) throws IllegalArgumentException { | ||
try { | ||
setValue(SimpleDate.valueOf(dateFormat.parse(text))); | ||
} catch (ParseException e) { | ||
throw new IllegalArgumentException("Unable to convert String '" + text + "' to a SimpleDate", e); | ||
} | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
lab/00-rewards-common/src/main/java/common/datetime/package.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<html> | ||
<body> | ||
<p> | ||
Shared classes for representing date and time. | ||
</p> | ||
</body> | ||
</html> |
Oops, something went wrong.