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

Return status object

parent cdbf1659
package edu.kit.scc.webreg.as;
import java.io.Serializable;
public class AttributeSourceQueryLog implements Serializable {
private static final long serialVersionUID = 1L;
private AttributeSourceQueryStatus status;
private String message;
public AttributeSourceQueryStatus getStatus() {
return status;
}
public void setStatus(AttributeSourceQueryStatus status) {
this.status = status;
}
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
}
package edu.kit.scc.webreg.as;
public enum AttributeSourceQueryStatus {
SUCCESS,
USER_NOT_FOUND,
FAIL
}
......@@ -9,7 +9,7 @@ import edu.kit.scc.webreg.exc.RegisterException;
public interface AttributeSourceWorkflow extends Serializable {
void pollUserAttributes(ASUserAttrEntity asUserAttr,
AttributeSourceQueryLog pollUserAttributes(ASUserAttrEntity asUserAttr,
ASUserAttrValueDao asValueDao, AttributeSourceAuditor auditor)
throws RegisterException;
}
......@@ -38,8 +38,10 @@ public class HttpUrlSingleAttributeSource extends
private static final long serialVersionUID = 1L;
@Override
public void pollUserAttributes(ASUserAttrEntity asUserAttr, ASUserAttrValueDao asValueDao, AttributeSourceAuditor auditor) throws RegisterException {
public AttributeSourceQueryLog pollUserAttributes(ASUserAttrEntity asUserAttr, ASUserAttrValueDao asValueDao, AttributeSourceAuditor auditor) throws RegisterException {
AttributeSourceQueryLog queryLog = new AttributeSourceQueryLog();
init(asUserAttr);
UserEntity user = asUserAttr.getUser();
......@@ -57,13 +59,16 @@ public class HttpUrlSingleAttributeSource extends
engine.evaluate(velocityContext, out, "log", urlTemplate);
} catch (ParseErrorException e) {
logger.warn("Velocity problem", e);
return;
queryLog.setStatus(AttributeSourceQueryStatus.FAIL);
return queryLog;
} catch (MethodInvocationException e) {
logger.warn("Velocity problem", e);
return;
queryLog.setStatus(AttributeSourceQueryStatus.FAIL);
return queryLog;
} catch (ResourceNotFoundException e) {
logger.warn("Velocity problem", e);
return;
queryLog.setStatus(AttributeSourceQueryStatus.FAIL);
return queryLog;
}
String url = out.toString();
......@@ -78,9 +83,13 @@ public class HttpUrlSingleAttributeSource extends
try {
response = httpclient.execute(httpget);
} catch (ClientProtocolException e) {
throw new RegisterException(e);
logger.info("Problem", e);
queryLog.setStatus(AttributeSourceQueryStatus.FAIL);
return queryLog;
} catch (IOException e) {
throw new RegisterException(e);
logger.info("Problem", e);
queryLog.setStatus(AttributeSourceQueryStatus.FAIL);
return queryLog;
}
HttpEntity entity = response.getEntity();
......@@ -99,11 +108,15 @@ public class HttpUrlSingleAttributeSource extends
logger.debug("Processing entry {}, value {}", entry.getKey(), entry.getValue());
createOrUpdateValue(entry.getKey(), entry.getValue(), asUserAttr, asValueDao, auditor);
}
queryLog.setStatus(AttributeSourceQueryStatus.SUCCESS);
} catch (JsonMappingException e) {
/*
* Datasource generates invalid JSON
*/
logger.warn("Json Parse failed: {}", e.getMessage());
queryLog.setStatus(AttributeSourceQueryStatus.FAIL);
}
} catch (ParseException e) {
throw new RegisterException(e);
......@@ -117,7 +130,10 @@ public class HttpUrlSingleAttributeSource extends
* probably no info for this user from datasource
*/
logger.debug("Status HttpUrlSingleAS is not OK. It is {} - {}", response.getStatusLine().getStatusCode(), response.getStatusLine().getReasonPhrase());
queryLog.setStatus(AttributeSourceQueryStatus.USER_NOT_FOUND);
}
return queryLog;
}
}
......@@ -2,13 +2,14 @@ package edu.kit.scc.webreg.service.reg;
import java.io.Serializable;
import edu.kit.scc.webreg.as.AttributeSourceQueryLog;
import edu.kit.scc.webreg.entity.UserEntity;
import edu.kit.scc.webreg.entity.as.AttributeSourceEntity;
import edu.kit.scc.webreg.exc.RegisterException;
public interface AttributeSourceQueryService extends Serializable {
void updateUserAttributes(UserEntity user,
AttributeSourceQueryLog updateUserAttributes(UserEntity user,
AttributeSourceEntity attributeSource, String executor)
throws RegisterException;
}
......@@ -7,6 +7,8 @@ import javax.inject.Inject;
import org.slf4j.Logger;
import edu.kit.scc.webreg.as.AttributeSourceQueryLog;
import edu.kit.scc.webreg.as.AttributeSourceQueryStatus;
import edu.kit.scc.webreg.as.AttributeSourceWorkflow;
import edu.kit.scc.webreg.audit.AttributeSourceAuditor;
import edu.kit.scc.webreg.bootstrap.ApplicationConfig;
......@@ -53,7 +55,7 @@ public class AttributeSourceQueryServiceImpl implements AttributeSourceQueryServ
private ApplicationConfig appConfig;
@Override
public void updateUserAttributes(UserEntity user, AttributeSourceEntity attributeSource, String executor)
public AttributeSourceQueryLog updateUserAttributes(UserEntity user, AttributeSourceEntity attributeSource, String executor)
throws RegisterException {
attributeSource = attributeSourceDao.findById(attributeSource.getId());
......@@ -77,14 +79,19 @@ public class AttributeSourceQueryServiceImpl implements AttributeSourceQueryServ
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.setDetail("Updating attributes for user " + user.getEppn());
auditor.setAsUserAttr(asUserAttr);
workflow.pollUserAttributes(asUserAttr, asValueDao, auditor);
asUserAttr.setLastSuccessfulQuery(new Date());
AttributeSourceQueryLog queryLog = workflow.pollUserAttributes(asUserAttr, asValueDao, auditor);
if (AttributeSourceQueryStatus.SUCCESS.equals(queryLog.getStatus())) {
asUserAttr.setLastSuccessfulQuery(new Date());
}
asUserAttr = asUserAttrDao.persist(asUserAttr);
auditor.finishAuditTrail();
auditor.finishAuditTrail();
return queryLog;
}
public AttributeSourceWorkflow getWorkflowInstance(String className) {
......
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