/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package framework.audit.bean;
import framework.audit.Audit;
import framework.audit.AuditDetails;
import framework.beans.SecuredBean;
import framework.beans.collaborator.CollaboratorCertificate;
import framework.generic.ClipsServerException;
import framework.utils.Converter;
import java.util.Date;
import java.util.List;
import javax.ejb.Stateless;
/**
*
* @author petr
*/
@Stateless(mappedName="clips-beans/AuditBean")
public class AuditBean extends SecuredBean implements AuditBeanRemote {
@Override
public void saveAudit(List<AuditDetails> auditDetails) throws ClipsServerException {
String s = "";
long t1 = new Date().getTime();
for (AuditDetails ad : auditDetails) {
s += "AuditDetails[ id: " + ad.id + ", sign: " + Converter.hexDump(ad.sign) + "]\n";
Audit audit = findEntity(Audit.class, ad.id);
audit.setDsa(Converter.hexDump(ad.sign));
List list = findEntityWhatWithResCount(null, CollaboratorCertificate.class, new Field[]{new Field("collaborator.id", ad.collaboratorID)}, " ORDER BY a.id", 1);
if (list.size() != 1){
throw new ClipsServerException("Документ аудита не может быть подписан, т.к. не найден сертификат открытого ключа");
}
audit.setCertificate((CollaboratorCertificate) list.get(0));
manager.persist(audit);
}
System.out.println("Save audit\n" + s + " in " + (new Date().getTime() - t1)+ " мс");
// throw new UnsupportedOperationException("Not supported yet.");
}
// Add business logic below. (Right-click in editor and choose
// "Insert Code > Add Business Method" or "Web Service > Add Operation")
}