Commit 1c6e0f74 authored by IevaBekmane's avatar IevaBekmane
Browse files

First commit

parent d5b6639c
Pipeline #1130 failed with stages
/*
* Copyright 2007-present the original author or authors.
*
* 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
*
* https://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 {
private static final String WRAPPER_VERSION = "0.5.6";
/**
* 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/"
+ WRAPPER_VERSION + "/maven-wrapper-" + WRAPPER_VERSION + ".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 directory '" + 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 {
if (System.getenv("MVNW_USERNAME") != null && System.getenv("MVNW_PASSWORD") != null) {
String username = System.getenv("MVNW_USERNAME");
char[] password = System.getenv("MVNW_PASSWORD").toCharArray();
Authenticator.setDefault(new Authenticator() {
@Override
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(username, password);
}
});
}
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();
}
}
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.6.3/apache-maven-3.6.3-bin.zip
wrapperUrl=https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar
...@@ -35,6 +35,11 @@ ...@@ -35,6 +35,11 @@
<groupId>com.h2database</groupId> <groupId>com.h2database</groupId>
<artifactId>h2</artifactId> <artifactId>h2</artifactId>
</dependency> </dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
</dependency>
<dependency> <dependency>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId> <artifactId>spring-boot-starter-test</artifactId>
......
package lv.venta.demo.controllers; package lv.venta.demo.controllers;
import javax.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
import org.springframework.ui.Model; import org.springframework.ui.Model;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import lv.venta.demo.models.Appointment; import lv.venta.demo.models.Appointment;
import lv.venta.demo.models.Doctor; import lv.venta.demo.models.Doctor;
import lv.venta.demo.models.Patient; import lv.venta.demo.models.Patient;
import lv.venta.demo.models.User;
import lv.venta.demo.services.impl.HospitalServiceImpl;
@Controller @Controller
@RequestMapping(value = "/hospital")
public class HospitalController { public class HospitalController {
@Autowired
HospitalServiceImpl hospitalServiceImpl;
@GetMapping(value = "/dummyDataInput") @GetMapping("/main")
public String main() {
return "main";
}
@GetMapping("/dummydatainput")
public String callInputDataService() { public String callInputDataService() {
hospitalServiceImpl.dataInput();
return ""; return "ok";
} }
@GetMapping(value = "/showAllDoctors") @GetMapping("/showalldoctors")
public String showAllDoctorsInHospital(Model model) { public String showAllDoctorsInHospital(Model model) {
model.addAttribute("doctor", hospitalServiceImpl.selectAllDoctors());
return ""; return "showalldoctors";
} }
@GetMapping(value = "/showAllPatients") @GetMapping("/showallpatients")
public String showAllPatientsInHospital(Model model) { public String showAllPatientsInHospital(Model model) {
model.addAttribute("patient", hospitalServiceImpl.selectAllPatients());
return ""; return "showallpatients";
}
@GetMapping("/showallappointments")
public String showAllAppointmentsInHospital(Model model) {
model.addAttribute("appointment", hospitalServiceImpl.selectAllAppointments());
return "showallappointments";
} }
@GetMapping(value = "/insertNewPatient") @GetMapping("/insertnewpatient")
public String insertNewPatientGet(Patient patient) { public String insertNewPatientGet(Patient patient) {
return "insertnewpatient";
return "";
} }
@PostMapping(value = "/insertNewPatient") @PostMapping("/insertnewpatient")
public String insertNewPatientPost() { public String insertNewPatientPost(@Valid Patient patient, BindingResult result) {
System.out.println(patient);
return ""; if(hospitalServiceImpl.insertNewPatientByObject(patient)) {
return "redirect:/showallpatients";
}
else {
return "insertnewpatient";
}
} }
@GetMapping(value = "/insertNewDoctor") @GetMapping("/insertnewdoctor")
public String insertNewDoctorGet(Doctor doctor) { public String insertNewDoctorGet(Doctor doctor) {
return "insertnewdoctor";
return "";
} }
@PostMapping(value = "/insertNewDoctor") @PostMapping("/insertnewdoctor")
public String insertNewDoctorPost() { public String insertNewDoctorPost(@Valid Doctor doctor) {
System.out.println(doctor);
return ""; if(hospitalServiceImpl.insertNewDoctorByObject(doctor)) {
return "redirect:/showalldoctors";
}
else {
return "insertnewdoctor";
}
} }
@GetMapping(value = "/autorise") @GetMapping("/authorise")
public String autoriseGet() { public String authoriseGet(User user) {
return "authorise";
return "";
} }
@PostMapping(value = "/autorise") @PostMapping("/authorise")
public String autorisePost() { public String authorisePost(User user, BindingResult result) {
if(hospitalServiceImpl.authorise(user) && !result.hasErrors()) {
return ""; return "redirect:/main";
}
return "authorise";
} }
@GetMapping(value = "/insertNewAppointment") @GetMapping("/insertnewappointment")
public String insertNewAppointmentGet(Appointment app) { public String insertNewAppointmentGet(Appointment app) {
return "insertnewappointment";
return "";
} }
@PostMapping(value = "/insertNewAppointment") @PostMapping("/insertnewappointment")
public String insertNewAppointmentPost() { public String insertNewAppointmentPost(@Valid Appointment app, BindingResult result) {
System.out.println(app);
return ""; if(hospitalServiceImpl.insertNewAppointmant(app) && !result.hasErrors()) {
return "redirect:/showalldoctors";
}
else {
return "insertnewappointment";
}
} }
@GetMapping(value = "/showAllAppointmentsByPatient/{id}") @GetMapping("/showallappointmentsbypatient/{id}")
public String showAllAppointmentsByPatient(Model model) { public String showAllAppointmentsByPatient(Model model, @PathVariable(name = "id") int id) {
model.addAttribute("allapp", hospitalServiceImpl.showAllAppointmentsByPatientId(id));
return ""; return "showallappointmentsbyid";
} }
@GetMapping(value = "/showAllAppointmentsByDoctor/{id}") @GetMapping("/showallappointmentsbydoctor/{id}")
public String showAllAppointmentsByDoctor(Model model) { public String showAllAppointmentsByDoctor(Model model, @PathVariable(name = "id") int id) {
model.addAttribute("alldoc", hospitalServiceImpl.showAllAppointmentsByDoctorId(id));
return ""; return "showallappointmentsbyid";
} }
@GetMapping(value = "/showAllAppointmentsByDoctorToday/{id}") @GetMapping("/showallappointmentsbydoctortoday/{id}")
public String showAllAppointmentsByDoctorToday(Model model) { public String showAllAppointmentsByDoctorToday(Model model) {
return ""; return "";
......
...@@ -4,14 +4,19 @@ import java.util.Date; ...@@ -4,14 +4,19 @@ import java.util.Date;
import javax.persistence.CascadeType; import javax.persistence.CascadeType;
import javax.persistence.Column; import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue; import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType; import javax.persistence.GenerationType;
import javax.persistence.Id; import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne; import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.validation.constraints.Size; import javax.validation.constraints.Size;
import org.springframework.format.annotation.DateTimeFormat; import org.springframework.format.annotation.DateTimeFormat;
@Entity
@Table(name = "AppointmentTable")
public class Appointment { public class Appointment {
@Id @Id
...@@ -19,7 +24,7 @@ public class Appointment { ...@@ -19,7 +24,7 @@ public class Appointment {
@Column(name = "AppointmentID") @Column(name = "AppointmentID")
private int appId; private int appId;
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm") //@DateTimeFormat(pattern = "dd-MM-yyyy hh:mm")
@Column(name = "DateAndTime") @Column(name = "DateAndTime")
private Date date; private Date date;
...@@ -28,11 +33,11 @@ public class Appointment { ...@@ -28,11 +33,11 @@ public class Appointment {
private String description; private String description;
@ManyToOne(cascade = CascadeType.ALL) @ManyToOne(cascade = CascadeType.ALL)
@Column(name = "PatientID") @JoinColumn(name = "PatientID")
private Patient patient; private Patient patient;
@ManyToOne(cascade = CascadeType.ALL) @ManyToOne(cascade = CascadeType.ALL)
@Column(name = "DoctorID") @JoinColumn(name = "DoctorID")
private Doctor doctor; private Doctor doctor;
public int getAppId() { public int getAppId() {
...@@ -64,12 +69,15 @@ public class Appointment { ...@@ -64,12 +69,15 @@ public class Appointment {
} }
public void setDoctor(Doctor doctor) { public void setDoctor(Doctor doctor) {
this.doctor = doctor; this.doctor = doctor;
}
public Appointment() {
} }
public Appointment(Date date, String description, Patient patient, Doctor doctor) { public Appointment(Date date, String description, Patient patient, Doctor doctor) {
setDate(date); this.date = date;
setDescription(description); this.description = description;
setPatient(patient); this.doctor = doctor;
setDoctor(doctor); this.patient = patient;
} }
@Override @Override
public String toString() { public String toString() {
......
package lv.venta.demo.models; package lv.venta.demo.models;
import java.util.Arrays;
import java.util.Collection; import java.util.Collection;
import javax.persistence.Column; import javax.persistence.Column;
...@@ -12,54 +11,51 @@ import javax.persistence.JoinColumn; ...@@ -12,54 +11,51 @@ import javax.persistence.JoinColumn;
import javax.persistence.OneToMany; import javax.persistence.OneToMany;
import javax.persistence.OneToOne; import javax.persistence.OneToOne;
import javax.persistence.Table; import javax.persistence.Table;
import javax.validation.constraints.Max;
import javax.validation.constraints.Min;
import javax.validation.constraints.Pattern; import javax.validation.constraints.Pattern;
import javax.validation.constraints.Size; import javax.validation.constraints.Size;
import lv.venta.demo.enums.Gender;
import lv.venta.demo.enums.Nationality;
import lv.venta.demo.enums.Speciality; import lv.venta.demo.enums.Speciality;
@Entity @Entity
@Table(name = "DoctorTable") @Table(name = "DoctotTable")
public class Doctor { public class Doctor {
@Id @Id
@GeneratedValue(strategy = GenerationType.AUTO) @GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "DoctorID") @Column(name = "doctorID")
private int doctorId; public int doctorID;
@Column(name = "name") @Column(name = "Name")
@Size(min = 3, max = 30) @Size(min = 3, max = 30)
@Pattern(regexp = "[a-zA-Z\\s]+$") @Pattern(regexp = "[a-zA-Z\\s]+$")
private String name; public String name;
@Column(name = "Surname") @Column(name = "Surname")
@Size(min = 3, max = 30) @Size(min = 3, max = 30)
@Pattern(regexp = "[a-zA-Z\\s]+$") @Pattern(regexp = "[a-zA-Z\\s]+$")
private String surname; public String surname;
@Column(name = "Identificator") @Size(min = 11, max = 11)
private int[] identificator; @Pattern(regexp = "\\d+")
@Column(name = "IdentificationNum")
@Column(name = "Gender") public String identificationNum;
private Gender gender;
@Column(name = "Nationality")
private Nationality nationality;
@Column(name = "Speciality") @Column(name = "Speciality")
private Speciality speciality; public Speciality speciality;
@Column(name = "Office Number") @Min(value = 100)
@Size(min = 100, max = 1000) @Max(value = 1000)
private short officeNum; @Column(name = "OfficeNumber")
public int officeNum;
@OneToMany(mappedBy = "doctor") @OneToMany(mappedBy = "doctor")
private Collection<Doctor> appointmentsForDoctor; private Collection<Appointment> allAppointmentsForDoctor;
@OneToOne @OneToOne
@JoinColumn(name = "UserID") @JoinColumn(name = "UserID")
private User user; private User doctorUser;
public String getName() { public String getName() {
return name; return name;
...@@ -73,56 +69,45 @@ public class Doctor { ...@@ -73,56 +69,45 @@ public class Doctor {
public void setSurname(String surname) { public void setSurname(String surname) {
this.surname = surname; this.surname = surname;
} }
public int[] getIdentificator() { public String getIdentificationNum() {
return identificator; return identificationNum;
}
public void setIdentificator(int[] identificator) {
this.identificator = identificator;
} }
public Gender getGender() { public void setIdentificationNum(String identificationNum) {
return gender; this.identificationNum = identificationNum;
} }
public void setGender(Gender gender) { public Speciality getSpeciality() {
this.gender = gender; return speciality;
}
public Nationality getNationality() {
return nationality;
} }
public void setNationality(Nationality nationality) { public void setSpeciality(Speciality speciality) {
this.nationality = nationality; this.speciality = speciality;
} }
public short getOfficeNum() { public int getOfficeNum() {
return officeNum; return officeNum;
} }
public void setOfficeNum(short officeNum) {