Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

T2d 262 verify #12

Open
wants to merge 16 commits into
base: master
Choose a base branch
from
14 changes: 8 additions & 6 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,16 @@ pipeline {
}
environment {
stagingPostgresDbUrl = credentials('STAGINGPROPERTYREGISTRYDBURL')
fallBackPostgresDbUrl = credentials('STAGINGPROPERTYREGISTRYDBURL')
productionPostgresDbUrl = credentials('STAGINGPROPERTYREGISTRYDBURL')
fallBackPostgresDbUrl = credentials('PRODUCTIONPROPERTYREGISTRYDBURL')
productionPostgresDbUrl = credentials('PRODUCTIONPROPERTYREGISTRYDBURL')
postgresDBUserName = credentials('POSTGRESDBUSERNAME')
postgresDBPassword = credentials('POSTGRESDBPASSWORD')
tomcatCredentials = credentials('TOMCATCREDENTIALS')
stagingHost = credentials('STAGINGHOST')
fallbackHost = credentials('FALLBACKHOST')
productionHost = credentials('PRODUCTIONHOST')
smtpHost = credentials('SMTPHOST')
ampt2dEmailId = credentials('AMPT2DEMAILID')
}
parameters {
booleanParam(name: 'DeployToStaging' , defaultValue: false , description: '')
Expand All @@ -22,7 +24,7 @@ pipeline {
stages {
stage('Default Build pointing to Staging DB') {
steps {
sh "mvn clean package -DskipTests -DbuildDirectory=staging/target -Dampt2d-property-registry-db.url=${stagingPostgresDbUrl} -Dampt2d-property-registry-db.username=${postgresDBUserName} -Dampt2d-property-registry-db.password=${postgresDBPassword}"
sh "mvn clean package -DskipTests -DbuildDirectory=staging/target -Dampt2d-property-registry-db.url=${stagingPostgresDbUrl} -Dampt2d-property-registry-db.username=${postgresDBUserName} -Dampt2d-property-registry-db.password=${postgresDBPassword} -Dsmtp-host=${smtpHost} -Damp-t2d-email-id=${ampt2dEmailId}"
}
}
stage('Build For FallBack And Production') {
Expand All @@ -33,9 +35,9 @@ pipeline {
}
steps {
echo 'Build pointing to FallBack DB'
sh "mvn clean package -DskipTests -DbuildDirectory=fallback/target -Dampt2d-property-registry-db.url=${fallBackPostgresDbUrl} -Dampt2d-property-registry-db.username=${postgresDBUserName} -Dampt2d-property-registry-db.password=${postgresDBPassword}"
sh "mvn clean package -DskipTests -DbuildDirectory=fallback/target -Dampt2d-property-registry-db.url=${fallBackPostgresDbUrl} -Dampt2d-property-registry-db.username=${postgresDBUserName} -Dampt2d-property-registry-db.password=${postgresDBPassword} -Dsmtp-host=${smtpHost} -Damp-t2d-email-id=${ampt2dEmailId}"
echo 'Build pointing to Production DB'
sh "mvn clean package -DskipTests -DbuildDirectory=production/target -Dampt2d-property-registry-db.url=${productionPostgresDbUrl} -Dampt2d-property-registry-db.username=${postgresDBUserName} -Dampt2d-property-registry-db.password=${postgresDBPassword}"
sh "mvn clean package -DskipTests -DbuildDirectory=production/target -Dampt2d-property-registry-db.url=${productionPostgresDbUrl} -Dampt2d-property-registry-db.username=${postgresDBUserName} -Dampt2d-property-registry-db.password=${postgresDBPassword} -Dsmtp-host=${smtpHost} -Damp-t2d-email-id=${ampt2dEmailId}"
}
}
stage('Deploy To Staging') {
Expand All @@ -46,7 +48,7 @@ pipeline {
}
steps {
echo 'Deploying to Staging'
sh "curl --upload-file staging/target/amp-t2d-property-registry-*.war 'http://'${tomcatCredentials}'@'${stagingHost}':8080/manager/text/deploy?path=/registry&update=true' | grep 'OK - Deployed application at context path '"
sh "curl --upload-file staging/target/amp-t2d-property-registry-*.war 'http://'${tomcatCredentials}'@'${stagingHost}':8080/manager/text/deploy?path=/dev/registry&update=true' | grep 'OK - Deployed application at context path '"
}
}
stage('Deploy To FallBack And Production') {
Expand Down
8 changes: 6 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-mail</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
Expand Down Expand Up @@ -68,7 +72,7 @@
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>test</scope>
<!--<scope>test</scope>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
Expand All @@ -78,7 +82,7 @@
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
<scope>provided</scope>-->
</dependency>
<!-- documentation -->
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@
import org.springframework.boot.web.support.SpringBootServletInitializer;

@SpringBootApplication
public class PropertyRegistryServiceApplication extends SpringBootServletInitializer {
public class PropertyRegistryServiceApplication {//extends SpringBootServletInitializer {

public static void main(String[] args) throws Exception {
SpringApplication.run(PropertyRegistryServiceApplication.class, args);
}

@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(PropertyRegistryServiceApplication.class);
}
// @Override
// protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
// return application.sources(PropertyRegistryServiceApplication.class);
// }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
*
* Copyright 2018 EMBL - European Bioinformatics Institute
*
* Licensed 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.
*
*/
package uk.ac.ebi.ampt2d.registry.entities;

import uk.ac.ebi.ampt2d.registry.util.BeanUtil;
import uk.ac.ebi.ampt2d.registry.service.mail.MailService;

import javax.persistence.PostPersist;
import javax.persistence.PostRemove;
import javax.persistence.PostUpdate;

public class EntityEventListener {

private enum Event {
CREATED,
UPDATED,
REMOVED
}

@PostPersist
public void onPersistEntity(IdentifiableEntity entity) {
sendNotification(entity, Event.CREATED);
}

@PostUpdate
public void onUpdateEntity(IdentifiableEntity entity) {
sendNotification(entity, Event.UPDATED);
}

@PostRemove
public void onRemoveEntity(IdentifiableEntity entity) {
sendNotification(entity, Event.REMOVED);
}

private void sendNotification(IdentifiableEntity entity, Event event) {
BeanUtil.getBean(MailService.class).send(entity.getClass().getSimpleName() + " " + entity.getId() + " " + event);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
*
* Copyright 2018 EMBL - European Bioinformatics Institute
*
* Licensed 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.
*
*/
package uk.ac.ebi.ampt2d.registry.entities;

public interface IdentifiableEntity<ENTITY_ID> {

ENTITY_ID getId();

}
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@
import java.time.ZonedDateTime;

@Entity
@EntityListeners(AuditingEntityListener.class)
public class Phenotype {
@EntityListeners({AuditingEntityListener.class, EntityEventListener.class})
public class Phenotype implements IdentifiableEntity<String> {

public enum Group {

Expand Down Expand Up @@ -68,4 +68,8 @@ public enum Group {

@LastModifiedDate
private ZonedDateTime lastModifiedDate;

public String getId() {
return id;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@
import java.time.ZonedDateTime;

@Entity
@EntityListeners(AuditingEntityListener.class)
public class Property {
@EntityListeners({AuditingEntityListener.class, EntityEventListener.class})
public class Property implements IdentifiableEntity<String> {

public enum Type {

Expand Down Expand Up @@ -102,4 +102,7 @@ public enum Meaning {
@LastModifiedDate
private ZonedDateTime lastModifiedDate;

public String getId() {
return id;
}
}
2 changes: 1 addition & 1 deletion src/main/java/uk/ac/ebi/ampt2d/registry/entities/User.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import javax.persistence.Enumerated;
import javax.persistence.Id;

@Entity
@Entity(name = "users")
public class User {

public enum Role {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
*
* Copyright 2018 EMBL - European Bioinformatics Institute
*
* Licensed 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.
*
*/
package uk.ac.ebi.ampt2d.registry.exceptionhandling;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.mail.MailSendException;
import org.springframework.transaction.TransactionSystemException;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;

import java.util.logging.Level;
import java.util.logging.Logger;

@ControllerAdvice
public class ExceptionHandlers {

private static final Logger exceptionLogger = Logger.getLogger(ExceptionHandlers.class.getSimpleName());

@Value("${mail.from}")
private String mailFrom;

@ExceptionHandler(value = TransactionSystemException.class)
public ResponseEntity<String> handleMailSendException(TransactionSystemException ex) {
if (ex.getOriginalException().getCause().getClass().equals(MailSendException.class)) {
exceptionLogger.log(Level.SEVERE, ex.getOriginalException().getCause().getMessage());
return new ResponseEntity("An automated email could not be sent, please contact " + mailFrom,
HttpStatus.INTERNAL_SERVER_ERROR);
}
throw ex;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
*
* Copyright 2018 EMBL - European Bioinformatics Institute
*
* Licensed 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.
*
*/
package uk.ac.ebi.ampt2d.registry.service.mail;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.stereotype.Service;

@Service
public class MailService {

@Autowired
private JavaMailSender javaMailSender;

@Value("${mail.notify:false}")
private Boolean nofify;

@Value("${mail.to}")
private String to;

@Value("${mail.from}")
private String from;

@Value("${mail.subject}")
private String subject;

public void send(String text) {
if (nofify == true) {
SimpleMailMessage message = new SimpleMailMessage();
message.setTo(to);
message.setFrom(from);
message.setSubject(subject);
message.setText(text);
javaMailSender.send(message);
}
}
}
38 changes: 38 additions & 0 deletions src/main/java/uk/ac/ebi/ampt2d/registry/util/BeanUtil.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
*
* Copyright 2018 EMBL - European Bioinformatics Institute
*
* Licensed 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.
*
*/
package uk.ac.ebi.ampt2d.registry.util;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Service;

@Service
public class BeanUtil implements ApplicationContextAware {

private static ApplicationContext context;

@Override
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
context = applicationContext;
}

public static <T> T getBean(Class<T> beanClass) {
return context.getBean(beanClass);
}
}
Loading