Commit 03e4d066 authored by michael.simon's avatar michael.simon
Browse files

Attribute Source dev

parent da31073f
/*******************************************************************************
* Copyright (c) 2014 Michael Simon.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the GNU Public License v3.0
* which accompanies this distribution, and is available at
* http://www.gnu.org/licenses/gpl.html
*
* Contributors:
* Michael Simon - initial
******************************************************************************/
package edu.kit.scc.webreg.dao.as;
import edu.kit.scc.webreg.dao.BaseDao;
import edu.kit.scc.webreg.entity.UserEntity;
import edu.kit.scc.webreg.entity.as.ASUserAttrEntity;
import edu.kit.scc.webreg.entity.as.AttributeSourceEntity;
public interface ASUserAttrDao extends BaseDao<ASUserAttrEntity, Long> {
ASUserAttrEntity findASUserAttr(UserEntity user,
AttributeSourceEntity attributeSource);
}
/*******************************************************************************
* Copyright (c) 2014 Michael Simon.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the GNU Public License v3.0
* which accompanies this distribution, and is available at
* http://www.gnu.org/licenses/gpl.html
*
* Contributors:
* Michael Simon - initial
******************************************************************************/
package edu.kit.scc.webreg.dao.jpa.as;
import javax.enterprise.context.ApplicationScoped;
import javax.inject.Named;
import javax.persistence.NoResultException;
import edu.kit.scc.webreg.dao.as.ASUserAttrDao;
import edu.kit.scc.webreg.dao.jpa.JpaBaseDao;
import edu.kit.scc.webreg.entity.UserEntity;
import edu.kit.scc.webreg.entity.as.ASUserAttrEntity;
import edu.kit.scc.webreg.entity.as.AttributeSourceEntity;
@Named
@ApplicationScoped
public class JpaASUserAttrDao extends JpaBaseDao<ASUserAttrEntity, Long> implements ASUserAttrDao {
@Override
public ASUserAttrEntity findASUserAttr(UserEntity user, AttributeSourceEntity attributeSource) {
try {
return (ASUserAttrEntity) em.createQuery("select a from ASUserAttrEntity e where "
+ "a.user = :user and a.attributeSource = :attributeSource")
.setParameter("user", user).setParameter("attributeSource", "attributeSource").getSingleResult();
}
catch (NoResultException e) {
return null;
}
}
@Override
public Class<ASUserAttrEntity> getEntityClass() {
return ASUserAttrEntity.class;
}
}
......@@ -13,43 +13,21 @@ package edu.kit.scc.webreg.entity;
import javax.persistence.Entity;
import javax.persistence.ManyToOne;
import edu.kit.scc.webreg.entity.as.AttributeSourceEntity;
import edu.kit.scc.webreg.entity.as.ASUserAttrEntity;
@Entity(name = "AuditAttributeSourceEntity")
public class AuditAttributeSourceEntity extends AuditEntryEntity {
private static final long serialVersionUID = 1L;
@ManyToOne(targetEntity = UserEntity.class)
private UserEntity user;
@ManyToOne(targetEntity = ASUserAttrEntity.class)
private ASUserAttrEntity asUserAttr;
@ManyToOne(targetEntity = ServiceEntity.class)
private ServiceEntity service;
@ManyToOne(targetEntity = AttributeSourceEntity.class)
private AttributeSourceEntity attributeSource;
public UserEntity getUser() {
return user;
}
public void setUser(UserEntity user) {
this.user = user;
}
public ServiceEntity getService() {
return service;
}
public void setService(ServiceEntity service) {
this.service = service;
}
public AttributeSourceEntity getAttributeSource() {
return attributeSource;
public ASUserAttrEntity getAsUserAttr() {
return asUserAttr;
}
public void setAttributeSource(AttributeSourceEntity attributeSource) {
this.attributeSource = attributeSource;
public void setAsUserAttr(ASUserAttrEntity asUserAttr) {
this.asUserAttr = asUserAttr;
}
}
......@@ -3,7 +3,7 @@ package edu.kit.scc.webreg.as;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import edu.kit.scc.webreg.entity.as.AttributeSourceEntity;
import edu.kit.scc.webreg.entity.as.ASUserAttrEntity;
import edu.kit.scc.webreg.exc.RegisterException;
import edu.kit.scc.webreg.service.reg.ldap.PropertyReader;
......@@ -15,9 +15,9 @@ public abstract class AbstractAttributeSourceWorkflow implements AttributeSource
protected PropertyReader prop;
public void init(AttributeSourceEntity attributeSource)
public void init(ASUserAttrEntity asUserAttr)
throws RegisterException {
prop = new PropertyReader(attributeSource.getAsProps());
prop = new PropertyReader(asUserAttr.getAttributeSource().getAsProps());
}
}
......@@ -3,12 +3,11 @@ package edu.kit.scc.webreg.as;
import java.io.Serializable;
import edu.kit.scc.webreg.audit.AttributeSourceAuditor;
import edu.kit.scc.webreg.entity.UserEntity;
import edu.kit.scc.webreg.entity.as.AttributeSourceEntity;
import edu.kit.scc.webreg.entity.as.ASUserAttrEntity;
import edu.kit.scc.webreg.exc.RegisterException;
public interface AttributeSourceWorkflow extends Serializable {
public void pollUserAttributes(AttributeSourceEntity attributeSource, UserEntity user,
public void pollUserAttributes(ASUserAttrEntity asUserAttr,
AttributeSourceAuditor auditor) throws RegisterException;
}
......@@ -23,6 +23,7 @@ import org.apache.velocity.exception.ResourceNotFoundException;
import edu.kit.scc.webreg.audit.AttributeSourceAuditor;
import edu.kit.scc.webreg.entity.UserEntity;
import edu.kit.scc.webreg.entity.as.ASUserAttrEntity;
import edu.kit.scc.webreg.entity.as.AttributeSourceEntity;
import edu.kit.scc.webreg.exc.RegisterException;
......@@ -32,10 +33,12 @@ public class HttpUrlSingleAttributeSource extends
private static final long serialVersionUID = 1L;
@Override
public void pollUserAttributes(AttributeSourceEntity attributeSource,
UserEntity user, AttributeSourceAuditor auditor) throws RegisterException {
public void pollUserAttributes(ASUserAttrEntity asUserAttr, AttributeSourceAuditor auditor) throws RegisterException {
init(attributeSource);
init(asUserAttr);
UserEntity user = asUserAttr.getUser();
AttributeSourceEntity attributeSource = asUserAttr.getAttributeSource();
String urlTemplate = prop.readProp("url_template");
......
......@@ -15,9 +15,7 @@ import edu.kit.scc.webreg.dao.AuditDetailDao;
import edu.kit.scc.webreg.dao.AuditEntryDao;
import edu.kit.scc.webreg.entity.AuditAttributeSourceEntity;
import edu.kit.scc.webreg.entity.AuditEntryEntity;
import edu.kit.scc.webreg.entity.ServiceEntity;
import edu.kit.scc.webreg.entity.UserEntity;
import edu.kit.scc.webreg.entity.as.AttributeSourceEntity;
import edu.kit.scc.webreg.entity.as.ASUserAttrEntity;
public class AttributeSourceAuditor extends AbstractAuditor {
......@@ -37,15 +35,7 @@ public class AttributeSourceAuditor extends AbstractAuditor {
return audit;
}
public void setAttributeSource(AttributeSourceEntity entity) {
audit.setAttributeSource(entity);
}
public void setUser(UserEntity entity) {
audit.setUser(entity);
}
public void setService(ServiceEntity entity) {
audit.setService(entity);
public void setAsUserAttr(ASUserAttrEntity entity) {
audit.setAsUserAttr(entity);
}
}
......@@ -11,8 +11,10 @@ import edu.kit.scc.webreg.bootstrap.ApplicationConfig;
import edu.kit.scc.webreg.dao.AuditDetailDao;
import edu.kit.scc.webreg.dao.AuditEntryDao;
import edu.kit.scc.webreg.dao.UserDao;
import edu.kit.scc.webreg.dao.as.ASUserAttrDao;
import edu.kit.scc.webreg.dao.as.AttributeSourceDao;
import edu.kit.scc.webreg.entity.UserEntity;
import edu.kit.scc.webreg.entity.as.ASUserAttrEntity;
import edu.kit.scc.webreg.entity.as.AttributeSourceEntity;
import edu.kit.scc.webreg.exc.RegisterException;
import edu.kit.scc.webreg.service.reg.AttributeSourceService;
......@@ -31,6 +33,9 @@ public class AttributeSourceServiceImpl implements AttributeSourceService {
@Inject
private AttributeSourceDao attributeSourceDao;
@Inject
private ASUserAttrDao asUserAttrDao;
@Inject
private AuditEntryDao auditDao;
......@@ -45,6 +50,16 @@ public class AttributeSourceServiceImpl implements AttributeSourceService {
throws RegisterException {
attributeSource = attributeSourceDao.findById(attributeSource.getId());
user = userDao.findById(user.getId());
ASUserAttrEntity asUserAttr = asUserAttrDao.findASUserAttr(user, attributeSource);
if (asUserAttr == null) {
asUserAttr = asUserAttrDao.createNew();
asUserAttr.setAttributeSource(attributeSource);
asUserAttr.setUser(user);
asUserAttr = asUserAttrDao.persist(asUserAttr);
}
AttributeSourceWorkflow workflow = getWorkflowInstance(attributeSource.getAsClass());
......@@ -52,9 +67,9 @@ public class AttributeSourceServiceImpl implements AttributeSourceService {
auditor.startAuditTrail(executor);
auditor.setName(attributeSource.getName() + "-AttributeSource-Audit");
auditor.setDetail("Updateing attributes for user " + user.getEppn());
auditor.setAttributeSource(attributeSource);
auditor.setAsUserAttr(asUserAttr);
workflow.pollUserAttributes(attributeSource, user, auditor);
workflow.pollUserAttributes(asUserAttr, auditor);
auditor.finishAuditTrail();
}
......
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