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

Refactoring of code and smell detection #49

Open
wants to merge 32 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 59 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
name: Deploy Spring Boot Application

on:
push:
branches:
- develop

jobs:
deploy:
runs-on: ubuntu-latest

steps:
- name: Checkout Code
uses: actions/checkout@v3

- name: Set Up JDK
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'temurin'

- name: Build with Maven (skip tests)
run: mvn clean package -DskipTests

- name: Package as ZIP
run: |
mkdir -p deploy/scripts
cp target/*.jar deploy/
cp appspec.yml deploy/
cp scripts/deploy.sh deploy/scripts/
cd deploy
zip -r deployment.zip ./*

- name: Upload Artifact
uses: actions/upload-artifact@v3
with:
name: deployment
path: deploy/deployment.zip

- name: Deploy to S3
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
AWS_SESSION_TOKEN: ${{ secrets.AWS_SESSION_TOKEN }}
AWS_REGION: 'us-east-1'
run: |
aws s3 cp deploy/deployment.zip s3://s3bucketmerin12/deployment.zip

- name: Deploy to EC2
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
AWS_SESSION_TOKEN: ${{ secrets.AWS_SESSION_TOKEN }}
AWS_REGION: 'us-east-1'
run: |
aws deploy create-deployment \
--application-name aws-demo-ec2-code-deploy \
--deployment-group-name AppointmentSchedulerCodeDeploy \
--s3-location bucket=s3bucketmerin12,key=deployment.zip,bundleType=zip
12 changes: 12 additions & 0 deletions appspec.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
version: 0.0
os: linux

files:
- source: /
destination: /home/ec2-user/app

hooks:
AfterInstall:
- location: scripts/deploy.sh
timeout: 300
runas: root
27 changes: 25 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.8</version>
<version>1.18.26</version>
<scope>provided</scope>
</dependency>

Expand Down Expand Up @@ -140,6 +140,8 @@
<artifactId>selenium-remote-driver</artifactId>
<version>3.141.59</version>
</dependency>


<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-chrome-driver</artifactId>
Expand Down Expand Up @@ -185,6 +187,28 @@
</executions>
</plugin>

<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.5</version>
<executions>
<execution>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<!-- attached to Maven test phase -->
<execution>
<id>report</id>
<phase>test</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>


<plugin>
<groupId>com.google.cloud.tools</groupId>
<artifactId>jib-maven-plugin</artifactId>
Expand All @@ -206,7 +230,6 @@
</configuration>
</plugin>
</plugins>

</build>

</project>
11 changes: 11 additions & 0 deletions scripts/deploy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/bash

# Stop the currently running application, if any
if pgrep -f "appointmentscheduler-1.0.5.jar" > /dev/null; then
echo "Stopping existing application..."
pkill -f "appointmentscheduler-1.0.5.jar"
fi

# Start the new application
echo "Starting new application..."
nohup java -jar /home/ec2-user/app/appointmentscheduler-1.0.5.jar > /home/ec2-user/app/application.log 2>&1 &
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.example.slabiak.appointmentscheduler.model;

class AdjusterAfterEnd implements TimePeriodAdjuster {


@Override
public TimePeroid adjust(TimePeroid original, TimePeroid breakPeriod) {
if (breakPeriod.getEnd().isAfter(original.getEnd())) {
original.setEnd(breakPeriod.getEnd());
}
return original;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.example.slabiak.appointmentscheduler.model;


import java.time.LocalDateTime;

class AdjusterBeforeStart implements TimePeriodAdjuster {


@Override
public TimePeroid adjust(TimePeroid original, TimePeroid breakPeriod) {
if (breakPeriod.getStart().isBefore(original.getStart())) {
original.setStart((breakPeriod.getStart()));
}
return original;
}
}


Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
package com.example.slabiak.appointmentscheduler.model;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;

@JsonIgnoreProperties(ignoreUnknown = true)
public class DayPlan {

private TimePeroid workingHours;
Expand All @@ -13,7 +16,8 @@ public DayPlan() {
breaks = new ArrayList();
}

public List<TimePeroid> timePeroidsWithBreaksExcluded() {

/* public List<TimePeroid> timePeroidsWithBreaksExcluded() {
ArrayList<TimePeroid> timePeroidsWithBreaksExcluded = new ArrayList<>();
timePeroidsWithBreaksExcluded.add(getWorkingHours());
List<TimePeroid> breaks = getBreaks();
Expand Down Expand Up @@ -46,8 +50,57 @@ public List<TimePeroid> timePeroidsWithBreaksExcluded() {


return timePeroidsWithBreaksExcluded;
}*/

/*
public List<TimePeroid> timePeroidsWithBreaksExcluded() {
ArrayList<TimePeroid> timePeroidsWithBreaksExcluded = new ArrayList<>();
timePeroidsWithBreaksExcluded.add(getWorkingHours());
List<TimePeroid> breaks = getBreaks();

if (!breaks.isEmpty()) {
processBreaks(timePeroidsWithBreaksExcluded, breaks);
}

return timePeroidsWithBreaksExcluded;
}

private void processBreaks(List<TimePeroid> timePeroidsWithBreaksExcluded, List<TimePeroid> breaks) {
ArrayList<TimePeroid> toAdd = new ArrayList<>();
for (TimePeroid break1 : breaks) {
adjustBreakStartAndEnd(break1);
updateTimePeroids(timePeroidsWithBreaksExcluded, break1, toAdd);
}
timePeroidsWithBreaksExcluded.addAll(toAdd);
Collections.sort(timePeroidsWithBreaksExcluded);
}

private void adjustBreakStartAndEnd(TimePeroid break1) {
if (break1.getStart().isBefore(workingHours.getStart())) {
break1.setStart(workingHours.getStart());
}
if (break1.getEnd().isAfter(workingHours.getEnd())) {
break1.setEnd(workingHours.getEnd());
}
}

private void updateTimePeroids(List<TimePeroid> timePeroidsWithBreaksExcluded, TimePeroid break1, List<TimePeroid> toAdd) {
for (TimePeroid peroid : timePeroidsWithBreaksExcluded) {
if (break1.getStart().equals(peroid.getStart()) && break1.getEnd().isAfter(peroid.getStart()) && break1.getEnd().isBefore(peroid.getEnd())) {
peroid.setStart(break1.getEnd());
}
if (break1.getStart().isAfter(peroid.getStart()) && break1.getStart().isBefore(peroid.getEnd()) && break1.getEnd().equals(peroid.getEnd())) {
peroid.setEnd(break1.getStart());
}
if (break1.getStart().isAfter(peroid.getStart()) && break1.getEnd().isBefore(peroid.getEnd())) {
toAdd.add(new TimePeroid(peroid.getStart(), break1.getStart()));
peroid.setStart(break1.getEnd());
}
}
}
*/


public TimePeroid getWorkingHours() {
return workingHours;
}
Expand All @@ -72,4 +125,29 @@ public void addBreak(TimePeroid breakToAdd) {
breaks.add(breakToAdd);
}

public List<TimePeroid> timePeroidsWithBreaksExcluded() {
List<TimePeroid> timePeriodsWithBreaksExcluded = new ArrayList<>();
timePeriodsWithBreaksExcluded.add(getWorkingHours());
List<TimePeroid> breaks = getBreaks();

if (!breaks.isEmpty()) {
List<TimePeriodAdjuster> adjusters = Arrays.asList(
new AdjusterBeforeStart(),
new AdjusterAfterEnd()
// Add more adjusters as needed
);

for (TimePeroid breakPeriod : breaks) {
for (TimePeroid timePeriod : timePeriodsWithBreaksExcluded) {
for (TimePeriodAdjuster adjuster : adjusters) {
adjuster.adjust(timePeriod, breakPeriod);
}
}
}

Collections.sort(timePeriodsWithBreaksExcluded);
}

return timePeriodsWithBreaksExcluded;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.example.slabiak.appointmentscheduler.model;

public interface TimePeriodAdjuster {
TimePeroid adjust(TimePeroid original, TimePeroid breakPeriod);
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public interface AppointmentService {

List<Appointment> getAppointmentsByProviderAtDay(int providerId, LocalDate day);

List<Appointment> getAppointmentsByCustomerAtDay(int providerId, LocalDate day);
List<Appointment> getAppointmentsByCustomerAtDayAndTimePeriods(int providerId, LocalDate day);

List<Appointment> getConfirmedAppointmentsByCustomerId(int customerId);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.example.slabiak.appointmentscheduler.service;

import com.example.slabiak.appointmentscheduler.entity.user.Role;
import com.example.slabiak.appointmentscheduler.entity.user.customer.RetailCustomer;
import com.example.slabiak.appointmentscheduler.model.UserForm;
import org.springframework.security.access.prepost.PreAuthorize;

import java.util.Collection;
import java.util.List;

public interface RetailCustomerService {
public void saveNewRetailCustomer(UserForm userForm);

public void updateRetailCustomerProfile(UserForm updateData);

public List<RetailCustomer> getAllRetailCustomers();

public RetailCustomer getRetailCustomerById(int retailCustomerId);

public Collection<Role> getRolesForRetailCustomer();


}
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ public interface UserService {

void updateProviderProfile(UserForm updateData);

Collection<Role> getRoleForCorporateCustomers();

Collection<Role> getRolesForProvider();

/*
Expand All @@ -67,7 +69,6 @@ public interface UserService {

void updateRetailCustomerProfile(UserForm updateData);

Collection<Role> getRolesForRetailCustomer();

/*
* CorporateCustomer
Expand All @@ -80,7 +81,6 @@ public interface UserService {

void updateCorporateCustomerProfile(UserForm updateData);

Collection<Role> getRoleForCorporateCustomers();


}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,13 @@ public List<Appointment> getAppointmentsByProviderAtDay(int providerId, LocalDat
return appointmentRepository.findByProviderIdWithStartInPeroid(providerId, day.atStartOfDay(), day.atStartOfDay().plusDays(1));
}

@Override

public List<Appointment> getAppointmentsByCustomerAtDayAndTimePeriods(int providerId, LocalDate day) {
return appointmentRepository.findByCustomerIdWithStartInPeroid(providerId, day.atStartOfDay(), day.atStartOfDay().plusDays(1));
}



public List<Appointment> getAppointmentsByCustomerAtDay(int providerId, LocalDate day) {
return appointmentRepository.findByCustomerIdWithStartInPeroid(providerId, day.atStartOfDay(), day.atStartOfDay().plusDays(1));
}
Expand Down Expand Up @@ -127,6 +133,8 @@ public void createNewAppointment(int workId, int providerId, int customerId, Loc
}

}
// Before


@Override
public void addMessageToAppointmentChat(int appointmentId, int authorId, ChatMessage chatMessage) {
Expand Down
Loading
Loading