Serving angular2 content from Spring Boot application

Recently I had to ship an Angular2/Angular4 application within a Spring boot WAR packaged application and I was having some issues when dealing with the the urls in the angular routes, since it goes through the DispatcherServlet I was getting 404 all over the place There are a few ways to handle this, below is my preferred solution : @Controller public class Angular2ViewController { @RequestMapping({"/books", "/login", "/admin", "/logout", "/configure"}) public String index() { return "forward:/index.html"; } } There you go, as easy as thatThe inconvenience about this solution is that you have to maintain a set of urls in your controller also

Editable combobox in HTML5 and bootstrap

Creating an editable combobox in HTML5Recently while reading the HTML5 specification I found out a new cool feature called datalist element
Which basically allows you to create an editable select form element by providing a list of possible values to an input whilst also allowing for new values to be provided (think of it as a basic auto-complete field)Below is an example of how to implement this :Select a color : Note that this is also compatible with Bootstrap 4 and 3

Custom converter for Mongodb and Spring Data for BigDecimal type

Recently I found that MongoDB does not support java's java.math.BigDecimal as you can read in the official spring data mongodb documentation As it turns out java.math.BigDecimal will be converted to java.lang.String when saved to the database and parsed back to BigDecimal which in most cases I guess it's alrightHowever as I found out things get broken when trying to perform range queries on this field such as : $gte, $lte you will get inconsistent results since MongoDB sees this as a StringLuckily this can be easily fixed by creating 2 custom converters (one for each side), below is how I've done it :1. Define custom converters by implementing the appropriate interface import org.springframework.core.convert.converter.Converter; import java.math.BigDecimal; public class BigDecimalToDoubleConverter implements Converter<BigDecimal, Double&gt { @Override public Double convert(BigDecimal source) { return source.doubleValue(); } } import org.spr…

Angular2 prevent ngboopstrap dialogs to close when clicking outside

The default behaviour for bootstrap modal dialogs is to close when you click outside the dialog however this is not always the desired behaviourWhen using Bootstrap 4 without the angular wrapper you need to add the data-backdrop='static' and data-keyboard="false" to the button in order to achieve this : If you are using the angular wrapper for bootstrap (and assuming you have your project already configured you can achieve this like so : export class MyComponent implements OnInit { constructor(private modalService: NgbModal) {} showDialog(): void {,{size: "lg",backdrop: 'static', keyboard: false}); } } And simply calling the showDialog() method from your template should do the trick

Prevent OSX from idle sleep

There are several ways to prevent an OSX system to sleep when idle such as the caffeine application or changing the parameters in the System preferencesHowever there is an even easier way to accomplish this without installing any extra apps, just open a terminal window and run the following command : pmset noidle You should see the following output : Preventing idle sleep (^C to exit)... Your OSX should now stay awake whilst pmset is running

Spring boot and mongodb with geo-localisation queries 1/3

MongoDB offers a number of indexes and query mechanisms to handle geospatial information, below are some of the features offered by the database : SurfacesLocation DataQuery OperationsGeospatial indexes.....More detailed information can be found at their website : MongoDB Geospatial queriesIn this 3 part post we will be creating a sample REST API application using Spring Boot, Spring Data and MongoDB to determinate if a given "Interest Point" is within a certain distance of the provided coordinates 1. Setup Before we start please ensure that you have a running MongoDB instance So let's get things started, we will be using Gradle as our build tool for this project, if you're not familiar with this build tool you can read the documentationBelow is the build file used to build our project, there is some noise in here that is related to IDE support as well as a few things needed to deploy this application in heroku which can be avoided but I've chosen to leave here f…

Spring Data force version and lastmodified date to update on JPA Entity

Spring data has a feature that allows you to track automatically a certain amount of fields through annotations :@CreatedDate : The date on which the entity was created@CreatedBy : The user that created the entity@LastModifiedDate : The date the entity was last modified@LastModifiedBy : The user that modified last the entity@Version : the version of the entity (increased each time the entity is modified and savesd)Let's say for example we have this simple entity with the appropriate annotations : @Entity @EntityListeners(AuditingEntityListener.class) public class Contact implements Serializable { private static final long serialVersionUID = 1L; @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; @Version() private Long version = 0L; @NotNull @CreatedDate private Date creationDate; @NotNull @Size(max = 50) @CreatedBy private String creationUserLogin; @NotNull @LastModifiedDate private Date m…