Commit 3383cb59 authored by E19C486L's avatar E19C486L
Browse files

dernier exercice

parent 7e9efdd5
Pipeline #27739 passed with stages
in 6 minutes
<?xml version="1.0" encoding="UTF-8"?>
<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_11">
<output url="file://$MODULE_DIR$/target/classes" />
<output-test url="file://$MODULE_DIR$/target/test-classes" />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
<excludeFolder url="file://$MODULE_DIR$/target" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="Maven: org.atlanmod.commons:commons-core:1.0.5" level="project" />
<orderEntry type="library" name="Maven: com.github.ben-manes.caffeine:caffeine:2.8.0" level="project" />
<orderEntry type="library" name="Maven: org.checkerframework:checker-qual:2.10.0" level="project" />
<orderEntry type="library" name="Maven: com.google.errorprone:error_prone_annotations:2.3.3" level="project" />
<orderEntry type="library" name="Maven: net.openhft:zero-allocation-hashing:0.9" level="project" />
<orderEntry type="library" name="Maven: de.ruedigermoeller:fst:2.57" level="project" />
<orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-core:2.8.8" level="project" />
<orderEntry type="library" name="Maven: org.javassist:javassist:3.21.0-GA" level="project" />
<orderEntry type="library" name="Maven: org.objenesis:objenesis:2.5.1" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.junit.jupiter:junit-jupiter-api:5.7.1" level="project" />
<orderEntry type="library" name="Maven: org.apiguardian:apiguardian-api:1.1.0" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.opentest4j:opentest4j:1.2.0" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.junit.platform:junit-platform-commons:1.7.1" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.junit.jupiter:junit-jupiter-engine:5.7.1" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.junit.platform:junit-platform-engine:1.7.1" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.assertj:assertj-core:3.19.0" level="project" />
<orderEntry type="library" name="Maven: org.junit.jupiter:junit-jupiter-params:5.7.0" level="project" />
</component>
</module>
\ No newline at end of file
package fr.unantes.l3.construction.mail;
public interface BodySetter {
public MailBuilder body(String str);
}
package fr.unantes.l3.construction.mail;
public interface BuildMail {
BuildMail priority(int i);
Mail build();
}
package fr.unantes.l3.construction.mail;
public class Mail {
private String subject;
private String sender;
private String receiver;
private String body;
private String date;
private int priority;
Mail(String subject, String sender, String body) {
this.subject = subject;
this.sender = sender;
this.body = body;
}
/*
Mail m = new MailBuilder()
.subject("Mon message")
.sender("thomas@georges.ge")
.body("Bonjour, ....")
.build();
*/
}
package fr.unantes.l3.construction.mail;
public class MailBuilder implements SubjectSetter, SenderSetter, BodySetter, BuildMail {
private String subject;
private String sender;
private String body;
private int priority;
private MailBuilder() {
}
public static SubjectSetter create() {
return new MailBuilder();
}
public MailBuilder subject(String str) {
subject = str;
return this;
}
public MailBuilder sender(String str) {
sender = str;
return this;
}
public MailBuilder body(String str) {
body = str;
return this;
}
@Override
public BuildMail priority(int i) {
priority = i;
return this;
}
public Mail build() {
return new Mail(subject, sender, body);
}
public static void main(String[] args) {
Mail newMail = MailBuilder.create()
.subject("eee")
.sender("zeze")
.body("eeeee")
.priority(3)
.build();
}
}
/*
Mail m = MailBuilder.create()
.subject("Mon message")
.sender("thomas@georges.ge")
.body("Bonjour, ....")
.build();
*/
\ No newline at end of file
package fr.unantes.l3.construction.mail;
public interface SenderSetter {
MailBuilder sender(String str);
}
package fr.unantes.l3.construction.mail;
public interface SubjectSetter {
MailBuilder subject(String str);
}
package fr.unantes.l3.construction.refactorings;
public class PermissionClaimed extends PermissionState {
public PermissionClaimed() {
super("CLAIMED");
}
public void claimedBy(SystemAdmin admin, SystemPermission systemPermission) {
}
@Override
public void deniedBy(SystemAdmin admin, SystemPermission systemPermission) {
if (!systemPermission.isAdmin(admin)) {
return;
}
systemPermission.setNotGranted();
systemPermission.setPermissionDenied();
systemPermission.notifyUserOfPermissionRequestResult();
}
@Override
public void grantedBy(SystemAdmin admin, SystemPermission systemPermission) {
if (!systemPermission.isAdmin(admin)) {
return;
}
systemPermission.setStateGranted();
systemPermission.setGranted();
systemPermission.notifyUserOfPermissionRequestResult();
}
}
package fr.unantes.l3.construction.refactorings;
public class PermissionDenied extends PermissionState {
public PermissionDenied() {
super("DENIED");
}
public void claimedBy(SystemAdmin admin, SystemPermission systemPermission) {
}
public void deniedBy(SystemAdmin admin, SystemPermission systemPermission) {
}
public void grantedBy(SystemAdmin admin, SystemPermission systemPermission) {
}
}
......@@ -5,4 +5,15 @@ public class PermissionGranted extends PermissionState{
public PermissionGranted() {
super(("GRANTED"));
}
public void claimedBy(SystemAdmin admin, SystemPermission systemPermission) {
}
@Override
public void deniedBy(SystemAdmin admin, SystemPermission systemPermission) {
}
@Override
public void grantedBy(SystemAdmin admin, SystemPermission systemPermission) {
}
}
package fr.unantes.l3.construction.refactorings;
public class PermissionRequested extends PermissionState {
public PermissionRequested() {
super("REQUESTED");
}
public void claimedBy(SystemAdmin admin, SystemPermission systemPermission) {
systemPermission.willBeHandledBy(admin);
systemPermission.setStateClaimed();
}
@Override
public void deniedBy(SystemAdmin admin, SystemPermission systemPermission) {
}
@Override
public void grantedBy(SystemAdmin admin, SystemPermission systemPermission) {
}
}
package fr.unantes.l3.construction.refactorings;
public class PermissionState {
public abstract class PermissionState {
public final static PermissionState REQUESTED = new PermissionState("REQUESTED");
public final static PermissionState CLAIMED = new PermissionState("REQUESTED");
public final static PermissionState REQUESTED = new PermissionRequested();
public final static PermissionState CLAIMED = new PermissionClaimed();
public final static PermissionState GRANTED = new PermissionGranted();
public final static PermissionState DENIED = new PermissionState("DENIED");
public final static PermissionState DENIED = new PermissionDenied();
private final String name;
public PermissionState(String name) {
this.name = name;
}
public abstract void claimedBy(SystemAdmin admin, SystemPermission systemPermission);
public abstract void deniedBy(SystemAdmin admin, SystemPermission systemPermission);
public abstract void grantedBy(SystemAdmin admin, SystemPermission systemPermission);
}
......@@ -14,7 +14,7 @@ public class SystemPermission {
private SystemUser requestor;
private SystemAdmin admin;
private boolean isGranted;
private PermissionState state;
PermissionState state;
public SystemPermission(SystemUser requestor, SystemProfile profile) {
this.requestor = requestor;
......@@ -25,42 +25,38 @@ public class SystemPermission {
}
public void claimedBy(SystemAdmin admin) {
if (!state.equals(PermissionState.REQUESTED)) {
return;
}
willBeHandledBy(admin);
state = PermissionState.CLAIMED;
this.state.claimedBy(admin, this);
}
public void deniedBy(SystemAdmin admin) {
if (!state.equals(PermissionState.CLAIMED)) {
return;
this.state.deniedBy(admin, this);
}
if (!admin.equals(this.admin)) {
return;
public void grantedBy(SystemAdmin admin) {
this.state.grantedBy(admin, this);
}
void setNotGranted() {
isGranted = false;
state = PermissionState.DENIED;
notifyUserOfPermissionRequestResult();
}
public void grantedBy(SystemAdmin admin) {
if (!state.equals(PermissionState.CLAIMED)) {
return;
void setGranted() {
isGranted = true;
}
if (!admin.equals(this.admin)) {
return;
public boolean isGranted() {
return isGranted;
}
state = PermissionState.GRANTED;
isGranted = true;
notifyUserOfPermissionRequestResult();
boolean isAdmin(SystemAdmin admin) {
return admin.equals(this.admin);
}
private void willBeHandledBy(SystemAdmin admin) {
void willBeHandledBy(SystemAdmin admin) {
this.admin = admin;
}
private void notifyUserOfPermissionRequestResult() {
void notifyUserOfPermissionRequestResult() {
}
private void notifyAdminOfPermissionRequest() {
......@@ -70,8 +66,22 @@ public class SystemPermission {
return state;
}
public boolean isGranted() {
return isGranted;
// group state methods
void setStateClaimed() {
this.state = PermissionState.CLAIMED;
}
void setPermissionDenied() {
state = PermissionState.DENIED;
}
void setStateGranted() {
state = PermissionState.GRANTED;
}
// endgroup
}
package fr.unantes.l3.construction.refactorings;
import org.junit.jupiter.api.Test;
class SystemPermissionTest {
@Test
void deniedBy() {
SystemPermission permission = new SystemPermission(new SystemUser(),
new SystemProfile());
permission.deniedBy(null);
}
}
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment