/*
|
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
|
*/
|
package com.megatim.apifdxweb.core.impl.tmp;
|
|
import com.megatim.apifdxweb.core.ifaces.helper.RoutingChecker;
|
import com.megatim.apifdxweb.core.ifaces.tmp.TokenTmpManager;
|
import com.megatim.apifdxweb.dao.ifaces.tmp.TokenTmpDAO;
|
import com.megatim.apifdxweb.model.tmp.StatutTmp;
|
import com.megatim.apifdxweb.model.tmp.TokenTmp;
|
import com.megatim.fdxcommons.core.ifaces.helper.DataInMemoryHandler;
|
import com.mgt.rs.security.core.service.AuthenticationTokenService;
|
import java.time.LocalDateTime;
|
import java.time.format.DateTimeFormatter;
|
import java.util.List;
|
import java.util.UUID;
|
import javax.ejb.EJB;
|
import javax.enterprise.context.Dependent;
|
import javax.inject.Inject;
|
import javax.transaction.Transactional;
|
|
/**
|
*
|
* @author ASUS
|
*/
|
@Dependent
|
public class TokenTmpManagerImpl implements TokenTmpManager {
|
|
@EJB
|
private TokenTmpDAO dao;
|
|
@Inject
|
private AuthenticationTokenService authenticationTokenService;
|
|
@Inject
|
private DataInMemoryHandler dataInMemoryHandler;
|
|
@Inject
|
private RoutingChecker routingChecker;
|
|
@Override
|
public TokenTmpDAO getDao() {
|
return this.dao;
|
}
|
|
@Override
|
@Transactional
|
public TokenTmp saveEntity(TokenTmp entity, String connectedParticipant) {
|
|
stopIfProductionNotPermitted(entity.getCodeTypeFichier(), connectedParticipant);
|
|
TokenTmp foundToken = dao.getByParticipantAndTypeFichier(connectedParticipant, entity.getCodeTypeFichier());
|
if (foundToken != null) {
|
foundToken.setStatutTmp(StatutTmp.EXPIRE);
|
save(foundToken);
|
}
|
|
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyyMMddHHmmss");
|
String str = LocalDateTime.now().format(formatter);
|
UUID uuid = UUID.nameUUIDFromBytes((str + entity.toString()).getBytes());
|
|
entity.setToken(uuid.toString());
|
entity.setCodeParticipant(connectedParticipant);
|
entity.setDateExpiration(entity.getDateCreation().plusMinutes(entity.getValidite()));
|
|
return save(entity);
|
|
}
|
|
@Override
|
public List<TokenTmp> getByStatutTmp(StatutTmp statut) {
|
return dao.getByStatutTmp(statut);
|
}
|
|
@Override
|
public List<TokenTmp> getExpiredToken() {
|
return dao.getExpiredToken();
|
}
|
|
private void stopIfProductionNotPermitted(String codeTypeFichier, String connectedParticipant) {
|
|
routingChecker.stopIfCurrentReferentielNotExists(dataInMemoryHandler.getDataInMemory());
|
routingChecker.stopIfTypeFichierNotExists(codeTypeFichier, dataInMemoryHandler.getDataInMemory());
|
routingChecker.stopIfNotProducer(codeTypeFichier, dataInMemoryHandler.getDataInMemory(), connectedParticipant);
|
|
}
|
|
}
|