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

13 define entity seniormanageraccess #18

Closed
wants to merge 4 commits into from
Closed
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/*
* Copyright (c) 2018-2023 adorsys GmbH and Co. KG
* All rights are reserved.
*/

package de.adorsys.ledgers.baam.db.domain;

import jakarta.persistence.*;
import lombok.Data;

import java.util.HashMap;
import java.util.Map;

@Entity
@Data
public class SeniorManagerAccess {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private String id;

private String name;

@Enumerated(EnumType.STRING)
private AccessStatus status;

@ElementCollection
private Map<String, String> managerRoles = new HashMap<>();

// Constructor
public SeniorManagerAccess(String name, AccessStatus status) {
this.name = name;
this.status = status.ACTIVE;
}
Comment on lines +30 to +34
Copy link
Contributor

@NkwaTambe NkwaTambe Sep 27, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're trying to access the ACTIVE value in the wrong way.

In your constructor, you're passing status as a parameter, and then you use status.ACTIVE. This confuses Java, because it thinks you're trying to get ACTIVE from the status parameter, which doesn't make sense.

The Fix:
Instead of using status.ACTIVE, you should directly use the enum name AccessStatus.ACTIVE to get the ACTIVE value.

The constructor sets this.status to AccessStatus.ACTIVE regardless of the input.
Correction: Change the constructor to accept the status parameter.(this.status=status)


// Default constructor for JPA
public SeniorManagerAccess() {}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

perfect...

doing these will make more sense:

public SeniorManagerAccess() {
        this.status = AccessStatus.ACTIVE; // Set default status
    }```


// Getters and Setters
//...
Comment on lines +38 to +40
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PLease remove these comment, it's not needed


// Methods
public void createManagerRole(String managerId, String permissions) {
if (this.status != AccessStatus.ACTIVE) {
throw new IllegalStateException("Cannot create roles when status is not active.");
}
managerRoles.put(managerId, permissions);
}

public void modifyManagerRole(String managerId, String newPermissions) {
if (managerRoles.containsKey(managerId)) {
managerRoles.put(managerId, newPermissions);
} else {
throw new IllegalArgumentException("Manager role not found.");
}
}

public void revokeManagerRole(String managerId) {
if (managerRoles.containsKey(managerId)) {
managerRoles.remove(managerId);
} else {
throw new IllegalArgumentException("Manager role not found.");
}
}

public void suspendAccess() {
this.status = AccessStatus.SUSPENDED;
}

public void activateAccess() {
this.status = AccessStatus.ACTIVE;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/*
* Copyright (c) 2018-2023 adorsys GmbH and Co. KG
* All rights are reserved.
*/

package de.adorsys.ledgers.baam.db.repository;
import de.adorsys.ledgers.baam.db.domain.SeniorManagerAccess;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

@Repository
public interface SeniorManagerAccessRepository extends JpaRepository<SeniorManagerAccess, Long> {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* Copyright (c) 2018-2023 adorsys GmbH and Co. KG
* All rights are reserved.
*/

package de.adorsys.ledgers.baam.db.domain;

import org.junit.jupiter.api.Test;
class SeniorManagerAccessTest {

@Test
void createManagerRole() {
}

@Test
void modifyManagerRole() {
}

@Test
void revokeManagerRole() {
}

@Test
void suspendAccess() {
}

@Test
void activateAccess() {
}
Comment on lines +1 to +29
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PLease right a full test for these entity..

use you can use an h2 database which acts as an in memory DB for the test..

these is to ensure that the entire logic is working perfectly fine and everything is actually stored in a database.

Also please ensure to do a git pull so as to see recent changes, these will help you see the new recent project structure for our module.

}
Comment on lines +1 to +30
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello @Koufan-De-King please implememt the various test cases ..

Also since the seniormanageraccess is an entity, it needs to be included into the ledgers DB..

to verify, executed docker compose up on the ledgers root directory to see..

Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
<artifactId>ledgers-deposit-account-rest-api</artifactId>

<properties>
<ruleset.basedir>../..</ruleset.basedir>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
<artifactId>ledgers-deposit-account-rest-server</artifactId>

<properties>
<ruleset.basedir>../..</ruleset.basedir>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
Expand Down
Loading