Commit da31073f authored by michael.simon's avatar michael.simon
Browse files

Attribute Source framework dev

parent f47887b9
/*******************************************************************************
* 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.entity;
import javax.persistence.Entity;
import javax.persistence.ManyToOne;
import edu.kit.scc.webreg.entity.as.AttributeSourceEntity;
@Entity(name = "AuditAttributeSourceEntity")
public class AuditAttributeSourceEntity extends AuditEntryEntity {
private static final long serialVersionUID = 1L;
@ManyToOne(targetEntity = UserEntity.class)
private UserEntity user;
@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 void setAttributeSource(AttributeSourceEntity attributeSource) {
this.attributeSource = attributeSource;
}
}
......@@ -25,7 +25,6 @@ import edu.kit.scc.webreg.entity.UserEntity;
@Entity(name = "ASUserAttrEntity")
@Table(name = "attribute_src_ua")
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
public class ASUserAttrEntity extends AbstractBaseEntity {
private static final long serialVersionUID = 1L;
......@@ -38,9 +37,9 @@ public class ASUserAttrEntity extends AbstractBaseEntity {
@JoinColumn(name = "attribute_src_id", nullable = false)
private AttributeSourceEntity attributeSource;
@Column(name = "key", nullable = false, length = 512)
private String key;
@Column(name = "last_successful_query")
private Date lastSuccessfulQuery;
public UserEntity getUser() {
return user;
}
......@@ -57,11 +56,12 @@ public class ASUserAttrEntity extends AbstractBaseEntity {
this.attributeSource = attributeSource;
}
public String getKey() {
return key;
public Date getLastSuccessfulQuery() {
return lastSuccessfulQuery;
}
public void setKey(String key) {
this.key = key;
public void setLastSuccessfulQuery(Date lastSuccessfulQuery) {
this.lastSuccessfulQuery = lastSuccessfulQuery;
}
}
......@@ -15,8 +15,8 @@ import java.util.Date;
import javax.persistence.Column;
import javax.persistence.Entity;
@Entity(name = "ASUserAttrDateEntity")
public class ASUserAttrDateEntity extends ASUserAttrEntity {
@Entity(name = "ASUserAttrValueDateEntity")
public class ASUserAttrValueDateEntity extends ASUserAttrValueEntity {
private static final long serialVersionUID = 1L;
......
/*******************************************************************************
* 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.entity.as;
import java.util.Date;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import edu.kit.scc.webreg.entity.AbstractBaseEntity;
import edu.kit.scc.webreg.entity.UserEntity;
@Entity(name = "ASUserAttrValueEntity")
@Table(name = "attribute_src_ua_value")
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
public class ASUserAttrValueEntity extends AbstractBaseEntity {
private static final long serialVersionUID = 1L;
@ManyToOne
@JoinColumn(name = "attribute_src_id", nullable = false)
private ASUserAttrEntity asUserAttr;
@Column(name = "key", nullable = false, length = 512)
private String key;
public String getKey() {
return key;
}
public void setKey(String key) {
this.key = key;
}
public ASUserAttrEntity getAsUserAttr() {
return asUserAttr;
}
public void setAsUserAttr(ASUserAttrEntity asUserAttr) {
this.asUserAttr = asUserAttr;
}
}
......@@ -13,8 +13,8 @@ package edu.kit.scc.webreg.entity.as;
import javax.persistence.Column;
import javax.persistence.Entity;
@Entity(name = "ASUserAttrLongEntity")
public class ASUserAttrLongEntity extends ASUserAttrEntity {
@Entity(name = "ASUserAttrValueLongEntity")
public class ASUserAttrValueLongEntity extends ASUserAttrValueEntity {
private static final long serialVersionUID = 1L;
......
......@@ -13,8 +13,8 @@ package edu.kit.scc.webreg.entity.as;
import javax.persistence.Column;
import javax.persistence.Entity;
@Entity(name = "ASUserAttrStringEntity")
public class ASUserAttrStringEntity extends ASUserAttrEntity {
@Entity(name = "ASUserAttrValueStringEntity")
public class ASUserAttrValueStringEntity extends ASUserAttrValueEntity {
private static final long serialVersionUID = 1L;
......
......@@ -2,11 +2,13 @@ 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.exc.RegisterException;
public interface AttributeSourceWorkflow extends Serializable {
public void pollUserAttributes(AttributeSourceEntity attributeSource, UserEntity user) throws RegisterException;
public void pollUserAttributes(AttributeSourceEntity attributeSource, UserEntity user,
AttributeSourceAuditor auditor) throws RegisterException;
}
......@@ -21,6 +21,7 @@ import org.apache.velocity.exception.MethodInvocationException;
import org.apache.velocity.exception.ParseErrorException;
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.AttributeSourceEntity;
import edu.kit.scc.webreg.exc.RegisterException;
......@@ -32,7 +33,7 @@ public class HttpUrlSingleAttributeSource extends
@Override
public void pollUserAttributes(AttributeSourceEntity attributeSource,
UserEntity user) throws RegisterException {
UserEntity user, AttributeSourceAuditor auditor) throws RegisterException {
init(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.audit;
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.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;
public class AttributeSourceAuditor extends AbstractAuditor {
private AuditAttributeSourceEntity audit;
public AttributeSourceAuditor(AuditEntryDao auditEntryDao,
AuditDetailDao auditDetailDao, ApplicationConfig appConfig) {
super(auditEntryDao, auditDetailDao, appConfig);
}
@Override
public AuditEntryEntity getAudit() {
if (audit == null)
audit = new AuditAttributeSourceEntity();
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);
}
}
......@@ -2,6 +2,14 @@ package edu.kit.scc.webreg.service.reg;
import java.io.Serializable;
import edu.kit.scc.webreg.entity.UserEntity;
import edu.kit.scc.webreg.entity.as.AttributeSourceEntity;
import edu.kit.scc.webreg.exc.RegisterException;
public interface AttributeSourceService extends Serializable {
void updateUserAttributes(UserEntity user,
AttributeSourceEntity attributeSource, String executor)
throws RegisterException;
}
......@@ -5,6 +5,11 @@ import javax.inject.Inject;
import org.slf4j.Logger;
import edu.kit.scc.webreg.as.AttributeSourceWorkflow;
import edu.kit.scc.webreg.audit.AttributeSourceAuditor;
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.AttributeSourceDao;
import edu.kit.scc.webreg.entity.UserEntity;
......@@ -26,10 +31,53 @@ public class AttributeSourceServiceImpl implements AttributeSourceService {
@Inject
private AttributeSourceDao attributeSourceDao;
public void updateUserAttributes(UserEntity user, AttributeSourceEntity attributeSource)
@Inject
private AuditEntryDao auditDao;
@Inject
private AuditDetailDao auditDetailDao;
@Inject
private ApplicationConfig appConfig;
@Override
public void updateUserAttributes(UserEntity user, AttributeSourceEntity attributeSource, String executor)
throws RegisterException {
attributeSource = attributeSourceDao.findById(attributeSource.getId());
AttributeSourceWorkflow workflow = getWorkflowInstance(attributeSource.getAsClass());
AttributeSourceAuditor auditor = new AttributeSourceAuditor(auditDao, auditDetailDao, appConfig);
auditor.startAuditTrail(executor);
auditor.setName(attributeSource.getName() + "-AttributeSource-Audit");
auditor.setDetail("Updateing attributes for user " + user.getEppn());
auditor.setAttributeSource(attributeSource);
workflow.pollUserAttributes(attributeSource, user, auditor);
auditor.finishAuditTrail();
}
public AttributeSourceWorkflow getWorkflowInstance(String className) {
try {
Object o = Class.forName(className).newInstance();
if (o instanceof AttributeSourceWorkflow)
return (AttributeSourceWorkflow) o;
else {
logger.warn("AttributeSourceWorkflow bean misconfigured, Object not Type AttributeSourceWorkflow but: {}", o.getClass());
return null;
}
} catch (InstantiationException e) {
logger.warn("AttributeSourceWorkflow bean misconfigured: {}", e.getMessage());
return null;
} catch (IllegalAccessException e) {
logger.warn("AttributeSourceWorkflow bean misconfigured: {}", e.getMessage());
return null;
} catch (ClassNotFoundException e) {
logger.warn("AttributeSourceWorkflow bean misconfigured: {}", e.getMessage());
return null;
}
}
}
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