Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
104 commits
Select commit Hold shift + click to select a range
219c330
Send an approved public kudos to the #kudos slack channel.
ocielliottc Nov 15, 2024
26fe554
Merge branch 'develop' into feature-2751/post-approved-kudos-to-slack
ocielliottc Nov 15, 2024
bce7706
Disable this test in native due to reflexive nature of Gson and records.
ocielliottc Nov 15, 2024
59ec115
Handle situation where daysBetween is zero.
ocielliottc Nov 15, 2024
917e22f
Inspect the posted slack block during kudos approval.
ocielliottc Nov 18, 2024
c980529
Non-functional cleanup.
ocielliottc Nov 18, 2024
16402cd
Switch to server-side markdown. This has not been fully tested.
ocielliottc Nov 19, 2024
74c159d
Merge branch 'develop' into feature-2751/post-approved-kudos-to-slack
mkimberlin Nov 21, 2024
d4bcf53
Merge branch 'develop' into feature-2751/post-approved-kudos-to-slack
mkimberlin Nov 21, 2024
9e3414d
Merge branch 'develop' into feature-2751/post-approved-kudos-to-slack
mkimberlin Nov 25, 2024
94c6d41
Merge branch 'develop' into feature-2751/post-approved-kudos-to-slack
mkimberlin Dec 11, 2024
b401698
#2790 - Added a bar chart per day showing the number of responses.
ocielliottc Dec 16, 2024
ad2b6d5
Use version 1.3.1.1 of the markdowngenerator from mavenCentral.
ocielliottc Dec 16, 2024
aa60fef
Provide an indicator for when document generation is complete.
ocielliottc Dec 16, 2024
f145ced
Added the review period name to the review period pull down.
ocielliottc Dec 16, 2024
e3c3e91
Merge branch 'develop' into feature-2759/server-side-markdown-generation
ocielliottc Dec 16, 2024
819a746
Corrected hour format of the generated markdown and updated the Repor…
ocielliottc Dec 17, 2024
ed83bb9
Merge pull request #2791 from objectcomputing/feature-2790/bar-chart-…
mkimberlin Dec 17, 2024
5a76dd4
Updated to reflect the label change.
ocielliottc Dec 17, 2024
b5e4977
Changed report generation to a POST so that member ids could be part …
ocielliottc Dec 17, 2024
88f61ca
Merge branch 'develop' into feature-2759/server-side-markdown-generation
ocielliottc Dec 17, 2024
52643a9
Merge branch 'develop' into feature-2751/post-approved-kudos-to-slack
mkimberlin Dec 17, 2024
ad41c96
Use a stacked bar chart to display counts for the day.
ocielliottc Dec 18, 2024
3291416
Renamed the line chart variable.
ocielliottc Dec 18, 2024
cd15b30
Merge pull request #2792 from objectcomputing/feature-2759/server-sid…
mkimberlin Dec 18, 2024
910713f
Merge branch 'develop' into bugfix-2793/bar-chart-truncated
mkimberlin Dec 18, 2024
7712618
Merge pull request #2794 from objectcomputing/bugfix-2793/bar-chart-t…
mkimberlin Dec 18, 2024
35143ef
Merge branch 'develop' into feature-2751/post-approved-kudos-to-slack
mkimberlin Dec 18, 2024
6f64ea6
Added a toggle for at-work/outside-work/both and a pie chart showing …
ocielliottc Dec 19, 2024
7d5ab31
Removed commented sentiment icons.
ocielliottc Dec 19, 2024
a0111da
Updated to reflect the removal of the drop-down.
ocielliottc Dec 19, 2024
5c74693
Filter out zero count pie pieces.
ocielliottc Dec 19, 2024
d29e636
Allow for anonymous pulse submission and viewing in the pulse report.
ocielliottc Dec 20, 2024
fb62f83
Fixed tests.
ocielliottc Dec 20, 2024
9162839
Updated test snapshot.
ocielliottc Dec 20, 2024
2eb13fb
Correct if check so that we do not auto-fill previous new member.
ocielliottc Dec 20, 2024
7601fc3
Merge pull request #2798 from objectcomputing/bugfix-2785/new-team-me…
mkimberlin Dec 20, 2024
b01f852
Rewrote the PulseResponseTest to remove mockito.
ocielliottc Dec 20, 2024
3dd68a3
Removed unnecessary db file and unnecessary refresh.
ocielliottc Dec 20, 2024
fa82c9d
Merge branch 'develop' into feature-2786/anonymous-pulse-responses
mkimberlin Dec 20, 2024
988c2c9
Merge pull request #2797 from objectcomputing/feature-2786/anonymous-…
mkimberlin Dec 23, 2024
a50dc16
Split the pie chart into two controlled by the toggle and colored lik…
ocielliottc Dec 23, 2024
985a199
Merge branch 'develop' into feature-2795/toggle-pulse-report
ocielliottc Dec 23, 2024
0545094
Reversed the tooltip order for the sentiment chart.
ocielliottc Dec 23, 2024
dcaddfe
Merge pull request #2800 from objectcomputing/feature-2799/reverse-to…
mkimberlin Dec 23, 2024
abee336
Removed mockito usage.
ocielliottc Dec 23, 2024
de8885d
Removed mockito.
ocielliottc Dec 23, 2024
405af20
Merge branch 'develop' of github.com:objectcomputing/check-ins into f…
mkimberlin Dec 23, 2024
74f2cc5
Adjust colors on pulse report
mkimberlin Dec 23, 2024
8c5d522
Removed mockito.
ocielliottc Dec 23, 2024
98b2cb7
Merge pull request #2796 from objectcomputing/feature-2795/toggle-pul…
mkimberlin Dec 23, 2024
ab7461e
Removed mockito from MemberProfileTest.
ocielliottc Dec 23, 2024
9b59314
Removed Mockito from MemberPhotoServiceImplTest.
ocielliottc Dec 23, 2024
daced47
Removed mockito from the MemberPhotoControllerTest.
ocielliottc Jan 2, 2025
2683afc
Removed mockito from CurrentUserServicesImplTest.
ocielliottc Jan 2, 2025
35f67db
Removed mockito from CurrentUserControllerTest.
ocielliottc Jan 2, 2025
e1524da
Account for the fact that the pulse email may or may not be sent.
ocielliottc Jan 2, 2025
fa6db81
Merge branch 'develop' into feature-2751/post-approved-kudos-to-slack
mkimberlin Jan 2, 2025
a6fcadb
Removed mockito from MemberProfileReportServicesImplTest.
ocielliottc Jan 2, 2025
78e324d
Removed mockito from the GuildTest.
ocielliottc Jan 2, 2025
aa8e86b
Removed mockito from the FeedbackRequestTest.
ocielliottc Jan 2, 2025
219d89c
Adjusted the configuration of the slack integration
mkimberlin Jan 2, 2025
b48fab5
Fixed missed configuration point
mkimberlin Jan 2, 2025
0040daa
Injected the KudosConverter and the SlackSearch
mkimberlin Jan 2, 2025
ac21685
Removed mockito from the CheckinDocumentServiceImplTest.
ocielliottc Jan 3, 2025
1c415b7
Factored out the main FileServicesImpl functionality into FileService…
ocielliottc Jan 6, 2025
0ea3edf
Factored out the main FileServicesImpl functionality into FileService…
ocielliottc Jan 6, 2025
994be14
Merge branch 'develop' into feature-2534/additional-test-mockito-removal
ocielliottc Jan 6, 2025
17f9706
Removed the import of DisabledInNativeImage
ocielliottc Jan 6, 2025
302142f
Moved the pulse responses up to the pie chart card, made them pageabl…
ocielliottc Jan 6, 2025
5770013
Changed the comment boxes to single line, expanding to 4 and changed …
ocielliottc Jan 7, 2025
34a5f1c
Updated test snapshots.
ocielliottc Jan 7, 2025
51eb2f2
Made the pulses pageable.
ocielliottc Jan 7, 2025
6817a6f
Added a property to show that the icon is required and changed to all…
ocielliottc Jan 7, 2025
c76a4c2
No longer load the previous pulse.
ocielliottc Jan 7, 2025
b4a0a63
Updated test snapshot
ocielliottc Jan 7, 2025
40f6318
Removed channel reference from the slack posting
mkimberlin Jan 7, 2025
50688d0
Added slack parameters to deployment workflows
mkimberlin Jan 7, 2025
7151f2d
Merge pull request #2776 from objectcomputing/feature-2751/post-appro…
mkimberlin Jan 7, 2025
dbcc427
Merge branch 'develop' into feature-2801/pulse-page-adjustments
ocielliottc Jan 8, 2025
ea1035c
Merge branch 'develop' into feature-2802/pageable-pulse-responses
ocielliottc Jan 8, 2025
e2d3243
Merge branch 'develop' into feature-2534/additional-test-mockito-removal
ocielliottc Jan 8, 2025
244fc81
Merge pull request #2803 from objectcomputing/feature-2534/additional…
mkimberlin Jan 8, 2025
a0b3aa5
Merge branch 'develop' into feature-2802/pageable-pulse-responses
mkimberlin Jan 8, 2025
bee62c5
Specify memberIds to download so that the "include terminated members…
ocielliottc Jan 8, 2025
ac12385
Default the event organization to an empty string instead of Unknown.
ocielliottc Jan 8, 2025
f194497
Support floating point hours for volunteering.
ocielliottc Jan 8, 2025
7fe227e
Merge pull request #2804 from objectcomputing/feature-2802/pageable-p…
mkimberlin Jan 9, 2025
c3b3da0
We still need to load today's pulse to ensure only a single submissio…
ocielliottc Jan 9, 2025
0fe00b7
Merge branch 'develop' into feature-2801/pulse-page-adjustments
ocielliottc Jan 9, 2025
6f060dc
Merge pull request #2806 from objectcomputing/feature-2801/pulse-page…
mkimberlin Jan 9, 2025
a80c49b
Send null for externalScore if not provided and handle null extern sc…
ocielliottc Jan 9, 2025
6264107
Merge pull request #2816 from objectcomputing/bugfix-2815/pulse-no-ex…
mkimberlin Jan 9, 2025
a71b1a1
Mark externalScore nullable so that we can pull responses with null v…
ocielliottc Jan 9, 2025
1bd9873
Merge branch 'develop' into bugfix-2815/pulse-no-external-score
mkimberlin Jan 9, 2025
ecd0886
Merge pull request #2817 from objectcomputing/bugfix-2815/pulse-no-ex…
mkimberlin Jan 9, 2025
64213b9
Merge branch 'develop' into bugfix-2809/terminated-members-csv
mkimberlin Jan 9, 2025
1ae8e0f
Merge pull request #2812 from objectcomputing/bugfix-2808/new-volunte…
mkimberlin Jan 9, 2025
c831956
Merge branch 'develop' into bugfix-2807/partial-volunteer-hours
mkimberlin Jan 9, 2025
03c2c99
Merge pull request #2811 from objectcomputing/bugfix-2809/terminated-…
mkimberlin Jan 9, 2025
0ea87c8
Merge branch 'develop' into bugfix-2807/partial-volunteer-hours
mkimberlin Jan 10, 2025
08d313e
Switch to setup-ruby@v1
mkimberlin Jan 10, 2025
8f0a304
Merge pull request #2813 from objectcomputing/bugfix-2807/partial-vol…
mkimberlin Jan 10, 2025
1ddde8d
Bump version
mkimberlin Jan 10, 2025
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
2 changes: 2 additions & 0 deletions .github/workflows/gradle-build-production.yml
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ jobs:
--set-env-vars "FROM_ADDRESS=no-reply@objectcomputing.com" \
--set-env-vars "FROM_NAME=Check-Ins" \
--set-env-vars "^@^MICRONAUT_ENVIRONMENTS=cloud,google,gcp" \
--set-env-vars "SLACK_WEBHOOK_URL=${{ secrets.SLACK_WEBHOOK_URL }}" \
--set-env-vars "SLACK_BOT_TOKEN=${{ secrets.SLACK_BOT_TOKEN }}" \
--platform "managed" \
--max-instances 8 \
--allow-unauthenticated
2 changes: 2 additions & 0 deletions .github/workflows/gradle-deploy-develop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,8 @@ jobs:
--set-env-vars "FROM_ADDRESS=no-reply@objectcomputing.com" \
--set-env-vars "FROM_NAME=Check-Ins - DEVELOP" \
--set-env-vars "^@^MICRONAUT_ENVIRONMENTS=dev,cloud,google,gcp" \
--set-env-vars "SLACK_WEBHOOK_URL=${{ secrets.SLACK_WEBHOOK_URL }}" \
--set-env-vars "SLACK_BOT_TOKEN=${{ secrets.SLACK_BOT_TOKEN }}" \
--platform "managed" \
--max-instances 2 \
--allow-unauthenticated
2 changes: 2 additions & 0 deletions .github/workflows/gradle-deploy-native-develop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,8 @@ jobs:
--set-env-vars "FROM_ADDRESS=kimberlinm@objectcomputing.com" \
--set-env-vars "FROM_NAME=Check-Ins - DEVELOP" \
--set-env-vars "^@^MICRONAUT_ENVIRONMENTS=dev,cloud,google,gcp" \
--set-env-vars "SLACK_WEBHOOK_URL=${{ secrets.SLACK_WEBHOOK_URL }}" \
--set-env-vars "SLACK_BOT_TOKEN=${{ secrets.SLACK_BOT_TOKEN }}" \
--platform "managed" \
--max-instances 2 \
--allow-unauthenticated
2 changes: 1 addition & 1 deletion .github/workflows/jekyll.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ jobs:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Ruby
uses: ruby/setup-ruby@8575951200e472d5f2d95c625da0c7bec8217c42 # v1.161.0
uses: ruby/setup-ruby@v1
with:
working-directory: docs
ruby-version: '3.3' # Not needed with a .ruby-version file
Expand Down
4 changes: 3 additions & 1 deletion server/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ plugins {
id "jacoco"
}

version "0.8.11"
version "0.8.12"
group "com.objectcomputing.checkins"

repositories {
Expand Down Expand Up @@ -79,6 +79,7 @@ dependencies {

yarnBuildElements(project(":web-ui"))

implementation("net.steppschuh.markdowngenerator:markdowngenerator:1.3.1.1")
implementation("io.micronaut:micronaut-jackson-databind")
implementation("io.micronaut:micronaut-http-client")
implementation("io.micronaut:micronaut-management")
Expand Down Expand Up @@ -116,6 +117,7 @@ dependencies {
implementation("io.micrometer:context-propagation")

implementation 'ch.digitalfondue.mjml4j:mjml4j:1.0.3'
implementation("com.slack.api:slack-api-client:1.44.1")

testRuntimeOnly "org.seleniumhq.selenium:selenium-chrome-driver:$seleniumVersion"
testRuntimeOnly "org.seleniumhq.selenium:selenium-firefox-driver:$seleniumVersion"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ public static class ApplicationConfig {
@NotNull
private GoogleApiConfig googleApi;

@NotNull
private NotificationsConfig notifications;

@Getter
@Setter
@ConfigurationProperties("feedback")
Expand Down Expand Up @@ -66,5 +69,25 @@ public static class ScopeConfig {
private String scopeForDirectoryApi;
}
}

@Getter
@Setter
@ConfigurationProperties("notifications")
public static class NotificationsConfig {

@NotNull
private SlackConfig slack;

@Getter
@Setter
@ConfigurationProperties("slack")
public static class SlackConfig {
@NotBlank
private String webhookUrl;

@NotBlank
private String botToken;
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package com.objectcomputing.checkins.notifications.social_media;

import com.objectcomputing.checkins.configuration.CheckInsConfiguration;
import io.micronaut.http.HttpRequest;
import io.micronaut.http.HttpResponse;
import io.micronaut.http.HttpStatus;
import io.micronaut.http.client.BlockingHttpClient;
import io.micronaut.http.client.HttpClient;

import jakarta.inject.Singleton;
import jakarta.inject.Inject;

import java.util.List;

@Singleton
public class SlackPoster {
@Inject
private HttpClient slackClient;

@Inject
private CheckInsConfiguration configuration;

public HttpResponse post(String slackBlock) {
// See if we can have a webhook URL.
String slackWebHook = configuration.getApplication().getNotifications().getSlack().getWebhookUrl();
if (slackWebHook != null) {
// POST it to Slack.
BlockingHttpClient client = slackClient.toBlocking();
HttpRequest<String> request = HttpRequest.POST(slackWebHook,
slackBlock);
return client.exchange(request);
}
return HttpResponse.status(HttpStatus.GONE,
"Slack Webhook URL is not configured");
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
package com.objectcomputing.checkins.notifications.social_media;

import com.objectcomputing.checkins.configuration.CheckInsConfiguration;
import com.slack.api.model.block.LayoutBlock;
import com.slack.api.Slack;
import com.slack.api.methods.MethodsClient;
import com.slack.api.model.Conversation;
import com.slack.api.methods.SlackApiException;
import com.slack.api.methods.request.conversations.ConversationsListRequest;
import com.slack.api.methods.response.conversations.ConversationsListResponse;
import com.slack.api.methods.request.users.UsersLookupByEmailRequest;
import com.slack.api.methods.response.users.UsersLookupByEmailResponse;

import jakarta.inject.Singleton;
import jakarta.inject.Inject;

import java.util.List;
import java.io.IOException;

import jnr.ffi.annotations.In;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

@Singleton
public class SlackSearch {
private static final Logger LOG = LoggerFactory.getLogger(SlackSearch.class);

private CheckInsConfiguration configuration;

public SlackSearch(CheckInsConfiguration checkInsConfiguration) {
this.configuration = checkInsConfiguration;
}

public String findChannelId(String channelName) {
String token = configuration.getApplication().getNotifications().getSlack().getBotToken();
if (token != null) {
try {
MethodsClient client = Slack.getInstance().methods(token);
ConversationsListResponse response = client.conversationsList(
ConversationsListRequest.builder().build()
);

if (response.isOk()) {
for (Conversation conversation: response.getChannels()) {
if (conversation.getName().equals(channelName)) {
return conversation.getId();
}
}
}
} catch(IOException e) {
LOG.error("SlackSearch.findChannelId: " + e.toString());
} catch(SlackApiException e) {
LOG.error("SlackSearch.findChannelId: " + e.toString());
}
}
return null;
}

public String findUserId(String userEmail) {
String token = configuration.getApplication().getNotifications().getSlack().getBotToken();
if (token != null) {
try {
MethodsClient client = Slack.getInstance().methods(token);
UsersLookupByEmailResponse response = client.usersLookupByEmail(
UsersLookupByEmailRequest.builder().email(userEmail).build()
);

if (response.isOk()) {
return response.getUser().getId();
}
} catch(IOException e) {
LOG.error("SlackSearch.findUserId: " + e.toString());
} catch(SlackApiException e) {
LOG.error("SlackSearch.findUserId: " + e.toString());
}
}
return null;
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,177 @@
package com.objectcomputing.checkins.services.file;

import com.objectcomputing.checkins.services.checkindocument.CheckinDocument;
import com.objectcomputing.checkins.services.checkindocument.CheckinDocumentServices;
import com.objectcomputing.checkins.services.checkins.CheckIn;
import com.objectcomputing.checkins.services.checkins.CheckInServices;
import com.objectcomputing.checkins.services.memberprofile.MemberProfile;
import com.objectcomputing.checkins.services.memberprofile.MemberProfileServices;
import com.objectcomputing.checkins.services.memberprofile.MemberProfileUtils;
import com.objectcomputing.checkins.services.memberprofile.currentuser.CurrentUserServices;

import io.micronaut.core.annotation.Nullable;
import io.micronaut.http.multipart.CompletedFileUpload;

import jakarta.inject.Singleton;
import jakarta.validation.constraints.NotNull;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
import java.util.UUID;
import java.util.function.Function;

import static com.objectcomputing.checkins.services.validate.PermissionsValidation.NOT_AUTHORIZED_MSG;

@Singleton
abstract public class FileServicesBaseImpl implements FileServices {
private static final Logger LOG = LoggerFactory.getLogger(FileServicesBaseImpl.class);

protected final CheckInServices checkInServices;
protected final CheckinDocumentServices checkinDocumentServices;
protected final MemberProfileServices memberProfileServices;
protected final CurrentUserServices currentUserServices;

public FileServicesBaseImpl(CheckInServices checkInServices,
CheckinDocumentServices checkinDocumentServices,
MemberProfileServices memberProfileServices,
CurrentUserServices currentUserServices) {
this.checkInServices = checkInServices;
this.checkinDocumentServices = checkinDocumentServices;
this.memberProfileServices = memberProfileServices;
this.currentUserServices = currentUserServices;
}

abstract protected void getCheckinDocuments(
Set<FileInfoDTO> result, Set<CheckinDocument> checkinDocuments) throws IOException;
abstract protected void downloadSingleFile(
String docId, FileOutputStream myWriter) throws IOException;
abstract protected FileInfoDTO uploadSingleFile(
CompletedFileUpload file, String directoryName,
Function<String, CheckinDocument> consumer) throws IOException;
abstract protected void deleteSingleFile(String docId) throws IOException;

@Override
public Set<FileInfoDTO> findFiles(@Nullable UUID checkInID) {
boolean isAdmin = currentUserServices.isAdmin();
validate(checkInID == null && !isAdmin, NOT_AUTHORIZED_MSG);

try {
Set<FileInfoDTO> result = new HashSet<>();
if (checkInID == null && isAdmin) {
getCheckinDocuments(result, Collections.emptySet());
} else if (checkInID != null) {
validate(!checkInServices.accessGranted(checkInID, currentUserServices.getCurrentUser().getId()),
"You are not authorized to perform this operation");

// If there aren't any documents, do not call
// getCheckinDocument. It assumes that an empty set means
// that it should attempt to get all documents. And, in this
// case, we just want an empty result set.
Set<CheckinDocument> checkinDocuments = checkinDocumentServices.read(checkInID);
if (!checkinDocuments.isEmpty()) {
getCheckinDocuments(result, checkinDocuments);
}
}

return result;
} catch (IOException e) {
LOG.error("Error occurred while retrieving files.", e);
throw new FileRetrievalException(e.getMessage());
}
}

@Override
public java.io.File downloadFiles(@NotNull String uploadDocId) {
MemberProfile currentUser = currentUserServices.getCurrentUser();
boolean isAdmin = currentUserServices.isAdmin();

CheckinDocument cd = checkinDocumentServices.getFindByUploadDocId(uploadDocId);
validate(cd == null, String.format("Unable to find record with id %s", uploadDocId));

CheckIn associatedCheckin = checkInServices.read(cd.getCheckinsId());

if(!isAdmin) {
validate((!currentUser.getId().equals(associatedCheckin.getTeamMemberId()) && !currentUser.getId().equals(associatedCheckin.getPdlId())), NOT_AUTHORIZED_MSG);
}
try {
java.io.File file = java.io.File.createTempFile("tmp", ".txt");
file.deleteOnExit();
try(
FileOutputStream myWriter = new FileOutputStream(file)
) {
downloadSingleFile(uploadDocId, myWriter);
return file;
} catch (IOException e) {
LOG.error("Error occurred while retrieving files.", e);
throw new FileRetrievalException(e.getMessage());
}
} catch(IOException e) {
LOG.error("Error occurred while attempting to create a temporary file.", e);
throw new FileRetrievalException(e.getMessage());
}
}

@Override
public FileInfoDTO uploadFile(@NotNull UUID checkInID, @NotNull CompletedFileUpload file) {
MemberProfile currentUser = currentUserServices.getCurrentUser();
boolean isAdmin = currentUserServices.isAdmin();
validate((file.getFilename() == null || file.getFilename().equals("")), "Please select a valid file before uploading.");

CheckIn checkIn = checkInServices.read(checkInID);
validate(checkIn == null, "Unable to find checkin record with id %s", checkInID);
if(!isAdmin) {
validate((!currentUser.getId().equals(checkIn.getTeamMemberId()) && !currentUser.getId().equals(checkIn.getPdlId())), "You are not authorized to perform this operation");
validate(checkIn.isCompleted(), NOT_AUTHORIZED_MSG);
}

// create folder for each team member
final String directoryName = MemberProfileUtils.getFullName(memberProfileServices.getById(checkIn.getTeamMemberId()));

try {
return uploadSingleFile(file, directoryName,
(fileId) -> {
//create record in checkin-document service
CheckinDocument cd = new CheckinDocument(checkInID, fileId);
checkinDocumentServices.save(cd);
return cd;
});
} catch (IOException e) {
LOG.error("Unexpected error processing file upload.", e);
throw new FileRetrievalException(e.getMessage());
}
}

@Override
public boolean deleteFile(@NotNull String uploadDocId) {
MemberProfile currentUser = currentUserServices.getCurrentUser();
boolean isAdmin = currentUserServices.isAdmin();

CheckinDocument cd = checkinDocumentServices.getFindByUploadDocId(uploadDocId);
validate(cd == null, String.format("Unable to find record with id %s", uploadDocId));

CheckIn associatedCheckin = checkInServices.read(cd.getCheckinsId());
if(!isAdmin) {
validate((!currentUser.getId().equals(associatedCheckin.getTeamMemberId()) && !currentUser.getId().equals(associatedCheckin.getPdlId())), NOT_AUTHORIZED_MSG);
}

try {
deleteSingleFile(uploadDocId);
checkinDocumentServices.deleteByUploadDocId(uploadDocId);
return true;
} catch (IOException e) {
LOG.error("Error occurred while deleting files.", e);
throw new FileRetrievalException(e.getMessage());
}
}

protected void validate(boolean isError, String message, Object... args) {
if(isError) {
throw new FileRetrievalException(String.format(message, args));
}
}
}
Loading
Loading