-
Notifications
You must be signed in to change notification settings - Fork 86
/
DefaultDeleteGenerator.java
133 lines (110 loc) · 5.82 KB
/
DefaultDeleteGenerator.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
/* $This file is distributed under the terms of the license in LICENSE$ */
package edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.generators;
import javax.servlet.http.HttpSession;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import edu.cornell.mannlib.vitro.webapp.beans.DataPropertyStatement;
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.EditConfigurationUtils;
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.EditConfigurationVTwo;
/**
* Generates delete form which submits the deletion request to the deletion controller.
* This is the page to which the user is redirected if they select Delete on the default property form.
*
*/
public class DefaultDeleteGenerator extends BaseEditConfigurationGenerator implements EditConfigurationGenerator {
private static final Log log = LogFactory.getLog(DefaultObjectPropertyFormGenerator.class);
private static final String PROPERTY_TEMPLATE = "confirmDeletePropertyForm.ftl";
private static final String INDIVIDUAL_TEMPLATE = "confirmDeleteIndividualForm.ftl";
private String subjectUri = null;
private String predicateUri = null;
private String objectUri = null;
private Integer dataHash = 0;
private DataPropertyStatement dps = null;
//In this case, simply return the edit configuration currently saved in session
//Since this is forwarding from another form, an edit configuration should already exist in session
@Override
public EditConfigurationVTwo getEditConfiguration(VitroRequest vreq,
HttpSession session) {
EditConfigurationVTwo editConfiguration = EditConfigurationVTwo.getConfigFromSession(session, vreq);
//Two paths for deletion: (i) from front page and (ii) from edit page of individual
//If (ii), edit configuration already exists but if (i) no edit configuration exists or is required for deletion
//so stub will be created that contains a minimal set of information
//Set template to be confirm delete
if(editConfiguration == null) {
editConfiguration = setupEditConfiguration(vreq, session);
}
//prepare update?
prepare(vreq, editConfiguration);
if (editConfiguration.getPredicateUri() == null && editConfiguration.getSubjectUri() == null) {
editConfiguration.setTemplate(INDIVIDUAL_TEMPLATE);
addDeleteParams(vreq, editConfiguration);
}else {
editConfiguration.setTemplate(PROPERTY_TEMPLATE);
}
return editConfiguration;
}
private void addDeleteParams(VitroRequest vreq, EditConfigurationVTwo editConfiguration) {
String redirectUrl = vreq.getParameter("redirectUrl");
if (redirectUrl != null) {
editConfiguration.addFormSpecificData("redirectUrl", redirectUrl);
}
String individualName = vreq.getParameter("individualName");
if (redirectUrl != null) {
editConfiguration.addFormSpecificData("individualName", individualName);
}
String individualType = vreq.getParameter("individualType");
if (redirectUrl != null) {
editConfiguration.addFormSpecificData("individualType", individualType);
}
}
private EditConfigurationVTwo setupEditConfiguration(VitroRequest vreq, HttpSession session) {
EditConfigurationVTwo editConfiguration = new EditConfigurationVTwo();
initProcessParameters(vreq, session, editConfiguration);
//set edit key for this as well
editConfiguration.setEditKey(EditConfigurationVTwo.newEditKey(session));
return editConfiguration;
}
//Do need to know whether data or object property and how to handle that
private void initProcessParameters(VitroRequest vreq, HttpSession session, EditConfigurationVTwo editConfiguration) {
subjectUri = EditConfigurationUtils.getSubjectUri(vreq);
predicateUri = EditConfigurationUtils.getPredicateUri(vreq);
editConfiguration.setSubjectUri(subjectUri);
editConfiguration.setPredicateUri(predicateUri);
editConfiguration.setEntityToReturnTo(subjectUri);
editConfiguration.setUrlPatternToReturnTo("/individual");
if(EditConfigurationUtils.isObjectProperty(predicateUri, vreq)) {
//not concerned about remainder, can move into default obj prop form if required
this.initObjectParameters(vreq);
this.processObjectPropForm(vreq, editConfiguration);
} else {
this.processDataPropForm(vreq, session, editConfiguration);
}
}
private void initObjectParameters(VitroRequest vreq) {
//in case of object property
objectUri = EditConfigurationUtils.getObjectUri(vreq);
}
private void processObjectPropForm(VitroRequest vreq, EditConfigurationVTwo editConfiguration) {
editConfiguration.setObject(objectUri);
//this needs to be set for the editing to be triggered properly, otherwise the 'prepare' method
//pretends this is a data property editing statement and throws an error
//TODO: Check if null in case no object uri exists but this is still an object property
}
private void processDataPropForm(VitroRequest vreq, HttpSession session, EditConfigurationVTwo editConfiguration) {
dataHash = EditConfigurationUtils.getDataHash(vreq);
if( dataHash != null ){
log.debug("Found a datapropKey in parameters and parsed it to int: " + dataHash);
editConfiguration.setDatapropKey( dataHash );
dps = EditConfigurationUtils.getDataPropertyStatement(vreq, session, dataHash, predicateUri);
if( dps != null ){
editConfiguration.addFormSpecificData("dataPropertyLexicalValue", dps.getData());
}else{
editConfiguration.addFormSpecificData("dataPropertyLexicalValue", "unknown value");
}
}else{
log.debug("Did NOT find a datapropKey for hte data hash.");
editConfiguration.addFormSpecificData("dataPropertyLexicalValue", "unknown value");
}
}
}