public class SaveArtifact implements Action {
@Override
public void execute(IDataWrapper data) {
DataHelperRike<Artifact> helper = new DataHelperRike<Artifact>(Artifact.class);
Artifact artifact = null;
boolean newArtifactCreated = false;
if (data.getRequestAttribute("id") != null && !data.getRequestAttribute("id").isEmpty()) {
artifact = helper.find(data.getRequestAttribute("id"));
}
if (artifact == null) {
newArtifactCreated = true;
artifact = new Artifact();
}
artifact.setName(data.getRequestAttribute("name"));
artifact.setUrl(data.getRequestAttribute("url"));
artifact.setCreated(new Date());
artifact.setCreator(SecurityHelper.getUser(data.getUser()).getEmailAddress());
artifact.setClient("");
helper.save(artifact);
data.setSessionAttribute("artifact", artifact);
data.setSessionAttribute("targetView", "viewArtifact");
String message = " changed Artifact #";
if (newArtifactCreated) {
message = " created Artifact #";
}
ActivityLogHelper.log(message + artifact.getId() + " <a href=\"/web/guest/rike/-/show/artifact/" + artifact.getId() + "\">" + StringEscapeUtils.escapeHtml(artifact.getName()) + "</a>", "", artifact.getCreator(), data, artifact.toMap());
}