This repository has been archived by the owner on Nov 3, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
55cafcb
commit 582d6b5
Showing
10 changed files
with
131 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
src/main/java/net/collaud/fablab/manager/data/type/DoorAction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package net.collaud.fablab.manager.data.type; | ||
|
||
/** | ||
* | ||
* @author Gaetan Collaud | ||
*/ | ||
public enum DoorAction { | ||
OPEN, | ||
CLOSE, | ||
TRY_OPEN_BUT_FAIL | ||
} |
85 changes: 85 additions & 0 deletions
85
src/main/java/net/collaud/fablab/manager/rest/legacy/DoorWS.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
package net.collaud.fablab.manager.rest.legacy; | ||
|
||
import java.util.Optional; | ||
import javax.annotation.security.RunAs; | ||
import lombok.extern.slf4j.Slf4j; | ||
import net.collaud.fablab.manager.annotation.JavascriptAPIConstant; | ||
import net.collaud.fablab.manager.audit.AuditUtils; | ||
import net.collaud.fablab.manager.data.UserEO; | ||
import net.collaud.fablab.manager.data.type.AuditAction; | ||
import net.collaud.fablab.manager.data.type.AuditObject; | ||
import net.collaud.fablab.manager.data.type.DoorAction; | ||
import net.collaud.fablab.manager.exceptions.FablabException; | ||
import net.collaud.fablab.manager.security.Roles; | ||
import net.collaud.fablab.manager.service.AuditService; | ||
import net.collaud.fablab.manager.service.ConfigurationService; | ||
import net.collaud.fablab.manager.service.UserService; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RequestMethod; | ||
import org.springframework.web.bind.annotation.RequestParam; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
/** | ||
* | ||
* @author Gaetan Collaud <[email protected]> Collaud <[email protected]> | ||
*/ | ||
@RestController() | ||
@RequestMapping("/door") | ||
@JavascriptAPIConstant("DOOR_API") | ||
@RunAs(Roles.SYSTEM) | ||
@Slf4j | ||
public class DoorWS { | ||
|
||
@Autowired | ||
private ConfigurationService configurationService; | ||
|
||
@Autowired | ||
private UserService userService; | ||
|
||
@Autowired | ||
private AuditService auditService; | ||
|
||
@RequestMapping(value = "event", method = RequestMethod.GET) | ||
public void getallMembershipType( | ||
@RequestParam("eventAction") DoorAction action, | ||
@RequestParam("rfid") String rfid, | ||
@RequestParam("token") String token) { | ||
StringBuilder sb = new StringBuilder(); | ||
|
||
Optional<UserEO> user = Optional.empty(); | ||
if (rfid != null) { | ||
user = userService.findByRFID(rfid); | ||
sb.append(user.map(u -> u.getFirstLastName()).orElse("Anonymous")); | ||
sb.append(" with RFID ").append(rfid).append(" "); | ||
} else { | ||
sb.append("Someone "); | ||
} | ||
boolean success = true; | ||
if (action | ||
!= null) { | ||
switch (action) { | ||
case OPEN: | ||
sb.append("opened the door"); | ||
break; | ||
case CLOSE: | ||
sb.append("closed the door"); | ||
break; | ||
case TRY_OPEN_BUT_FAIL: | ||
sb.append("tried to open the door but failed"); | ||
success = false; | ||
break; | ||
} | ||
} else { | ||
sb.append("did something with the door"); | ||
} | ||
|
||
log.info(sb.toString()); | ||
try { | ||
AuditUtils.addAudit(auditService, user.orElse(null), AuditObject.ACCESS_DOOR, AuditAction.UPDATE, success, sb.toString()); | ||
} catch (FablabException ex) { | ||
log.error("Cannot add audit entry"); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -168,4 +168,9 @@ public void updateMailingList() { | |
mailService.sendPlainTextMail("Update mailing list", sb.toString(), "[email protected]"); | ||
} | ||
|
||
@Override | ||
public Optional<UserEO> findByRFID(String rfid) { | ||
return userDao.findByRFID(rfid); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<Context antiJARLocking="true" path="/fablab-manager-2.0.1-SNAPSHOT"/> | ||
<Context antiJARLocking="true" path="/fablab-manager"/> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters