Commit 61d7d76e authored by Sonia Zorba's avatar Sonia Zorba
Browse files

TAP 1.1 XML config changes, UserEditor changes and various improvements

parent e24e5873
......@@ -164,6 +164,7 @@ Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
<updatable>false</updatable>
<nullable>false</nullable>
<key>indexed</key>
<default-value>0</default-value>
<description>an indexed column; 1 means true, 0 means false</description>
</property>
<property>
......
......@@ -35,15 +35,45 @@ Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
<add>
<property>
<name>arraysize</name>
<type>java.lang.Integer</type>
<type>java.lang.String</type>
<updatable>false</updatable>
<key>arraysize</key>
</property>
<property>
<name>xtype</name>
<type>java.lang.String</type>
<updatable>true</updatable>
</property>
<property>
<name>column_index</name>
<type>java.lang.Integer</type>
<updatable>true</updatable>
</property>
<property>
<name>indexed</name>
<type>java.lang.Boolean</type>
<updatable>false</updatable>
<nullable>false</nullable>
<default-value>false</default-value>
<key>indexed</key>
<description>an indexed column</description>
</property>
<property>
<name>principal</name>
<type>java.lang.Boolean</type>
<updatable>true</updatable>
<nullable>false</nullable>
<default-value>false</default-value>
<description>a principal column</description>
</property>
<property>
<name>std</name>
<type>java.lang.Boolean</type>
<updatable>true</updatable>
<nullable>false</nullable>
<default-value>false</default-value>
<description>a standard column</description>
</property>
</add>
</table>
</tap_schema>
......@@ -123,7 +123,7 @@ public class ConfigurationManager {
if (user.getUsername() == null) {
return false;
}
for (UserConfiguration u : usersConfig.getUsers()) {
if (u.getUsername().equals(user.getUsername())) {
return false;
......@@ -148,6 +148,20 @@ public class ConfigurationManager {
return false;
}
public synchronized boolean editUser(String username, String role, String password) {
for (UserConfiguration u : usersConfig.getUsers()) {
if (u.getUsername().equals(username)) {
u.setRole(role);
u.setPassword(password);
updateUsersConfigurationFile();
return true;
}
}
return false;
}
/**
* Add a new UCD to the list, but only if the word has not already been
* entered.
......
......@@ -65,6 +65,10 @@ public class CredentialsEditing implements Serializable {
private boolean separateCredentials;
private int currentEditingRow;
public void test() {
String x = "";
}
@PostConstruct
public void init() {
sourceCredentials = new Credentials();
......
......@@ -57,8 +57,6 @@ public class TapSchemaEditingBean implements Serializable {
private static final long serialVersionUID = -6251004452688984277L;
private static final Logger LOG = LoggerFactory.getLogger(TapSchemaEditingBean.class);
private static final String COLUMNS_COMPONENT_ID = "main:columns-list";
@Inject
SchemaSelectionBean schemaSelection;
......@@ -352,53 +350,23 @@ public class TapSchemaEditingBean implements Serializable {
public void removeColumn(String name) {
selectedTable.removeChild(name);
Integer selectedColumnIndex = null;
if (selectedColumn != null) {
int index = 0;
for (Column column : selectedTable.getAddedOrRemovedChildren()) {
if (column.getName().equals(selectedColumn.getName())) {
selectedColumnIndex = index;
break;
}
index++;
}
}
CustomPartialResponseWriter writer = CustomPartialResponseWriter.getCurrentInstance();
final String updateResult = selectedColumnIndex == null ? "{}" : "{\"selectedColumn\":" + selectedColumnIndex + "}";
writer.encodeComponent(COLUMNS_COMPONENT_ID);
writer.addCustomJSUpdate(COLUMNS_COMPONENT_ID, new JSUpdateHandler() {
@Override
public String getUpdate() {
return updateResult;
}
});
}
public void undoRemoveColumn() throws SQLException {
this.undoRemove(selectedColumn);
int i = 0;
for (Column column : selectedTable.getAddedOrRemovedChildren()) {
if (column.getName().equals(selectedColumn.getName())) {
break;
}
i++;
}
final int columnIndex = i;
CustomPartialResponseWriter writer = CustomPartialResponseWriter.getCurrentInstance();
writer.addCustomJSUpdate(COLUMNS_COMPONENT_ID, new JSUpdateHandler() {
@Override
public String getUpdate() {
return columnIndex + "";
}
});
}
public void reload() {
......
......@@ -6,6 +6,7 @@ import it.inaf.ia2.tsm.webapp.xmlconfig.UCDConfiguration;
import java.io.IOException;
import java.io.Serializable;
import java.util.List;
import javax.annotation.PostConstruct;
import javax.inject.Inject;
import javax.inject.Named;
import org.apache.deltaspike.core.api.scope.WindowScoped;
......@@ -29,7 +30,7 @@ public class UCDEditor implements Serializable {
private boolean viewExisting;
private UCDConfiguration newUCDConfiguration;
private String invalidUCDMessage;
public void openDialog() {
viewExisting = true;
newUCDConfiguration = new UCDConfiguration(user.getUsername());
......
......@@ -22,9 +22,13 @@
*/
package it.inaf.ia2.tsm.webapp;
import it.inaf.ia2.tsm.webapp.env.CustomPartialResponseWriter;
import it.inaf.ia2.tsm.webapp.env.JSUpdateHandler;
import it.inaf.ia2.tsm.webapp.xmlconfig.UserConfiguration;
import java.io.Serializable;
import java.util.List;
import javax.faces.application.FacesMessage;
import javax.faces.context.FacesContext;
import javax.inject.Inject;
import javax.inject.Named;
import org.apache.deltaspike.core.api.scope.WindowScoped;
......@@ -42,7 +46,13 @@ public class UsersEditing implements Serializable {
@Inject
private ConfigurationManager config;
private UserConfiguration newUser;
private UserConfiguration userInEditing;
private UserConfiguration userToRemove;
private boolean newUser;
private String password;
private String passwordConfirm;
private String role;
public String open() {
return "usersEditing.xhtml?faces-redirect=true";
......@@ -52,29 +62,108 @@ public class UsersEditing implements Serializable {
return config.getUsersConfiguration();
}
public void save() {
//config.updateUsersList(users);
public void editNewUser() {
newUser = true;
userInEditing = new UserConfiguration();
role = "user";
}
public void createNewUser() {
newUser = new UserConfiguration();
public void editExistingUser(UserConfiguration user) {
newUser = false;
userInEditing = user;
role = user.getRole();
}
public void addUser() {
if (newUser != null) {
config.addUser(newUser);
}
public UserConfiguration getUserInEditing() {
return userInEditing;
}
public void removeUser(UserConfiguration user) {
config.deleteUser(user.getUsername());
public boolean isNewUser() {
return newUser;
}
public UserConfiguration getNewUser() {
return newUser;
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getPasswordConfirm() {
return passwordConfirm;
}
public void setPasswordConfirm(String passwordConfirm) {
this.passwordConfirm = passwordConfirm;
}
public String getRole() {
return role;
}
public void setRole(String role) {
this.role = role;
}
public UserConfiguration getUserToRemove() {
return userToRemove;
}
public void setNewUser(UserConfiguration newUser) {
this.newUser = newUser;
public void setUserToRemove(UserConfiguration userToRemove) {
this.userToRemove = userToRemove;
}
public void saveEdit() {
boolean canSave = true;
if (userInEditing.getUsername() == null || userInEditing.getUsername().isEmpty()) {
FacesContext.getCurrentInstance().addMessage("main:username", new FacesMessage("Username is required"));
canSave = false;
}
if (canSave && newUser) {
for (UserConfiguration user : config.getUsersConfiguration()) {
if (user.getUsername().equals(userInEditing.getUsername())) {
FacesContext.getCurrentInstance().addMessage("main:username", new FacesMessage("This username already exists."));
canSave = false;
break;
}
}
}
if (password == null || password.isEmpty()) {
FacesContext.getCurrentInstance().addMessage("main:password", new FacesMessage("Password is required"));
canSave = false;
}
if (password != null && !password.equals(passwordConfirm)) {
FacesContext.getCurrentInstance().addMessage("main:confirm-password", new FacesMessage("Passwords don't match"));
canSave = false;
}
final String jsUpdate = String.valueOf(canSave);
CustomPartialResponseWriter.getCurrentInstance().addCustomJSUpdate(new JSUpdateHandler() {
@Override
public String getUpdate() {
return jsUpdate;
}
});
if (canSave) {
if (newUser) {
userInEditing.setRole(role);
userInEditing.setPassword(password);
config.addUser(userInEditing);
} else {
config.editUser(userInEditing.getUsername(), role, password);
}
}
}
public void confirmUserDeletion() {
if (userToRemove != null) {
config.deleteUser(userToRemove.getUsername());
}
}
}
......@@ -24,11 +24,8 @@ package it.inaf.ia2.tsm.webapp.env;
import java.io.IOException;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import javax.faces.component.UIComponent;
import java.util.concurrent.ConcurrentHashMap;
import javax.faces.context.FacesContext;
import javax.faces.context.PartialResponseWriter;
import javax.faces.context.ResponseWriter;
......@@ -39,19 +36,15 @@ import javax.faces.context.ResponseWriter;
*/
public class CustomPartialResponseWriter extends PartialResponseWriter {
private final Set<String> componentsToEncode;
private final Map<String, JSUpdateHandler> customJSUpdates;
public CustomPartialResponseWriter(ResponseWriter wrapped) {
super(wrapped);
componentsToEncode = new HashSet<>();
customJSUpdates = new HashMap<>();
customJSUpdates = new ConcurrentHashMap<>();
}
@Override
public void endDocument() throws IOException {
FacesContext fctx = FacesContext.getCurrentInstance();
if (!customJSUpdates.isEmpty()) {
startExtension(Collections.singletonMap("id", "jsupdates"));
for (Map.Entry<String, JSUpdateHandler> entry : customJSUpdates.entrySet()) {
......@@ -64,25 +57,9 @@ public class CustomPartialResponseWriter extends PartialResponseWriter {
endExtension();
}
if (!componentsToEncode.isEmpty()) {
startExtension(Collections.singletonMap("id", "htmlupdates"));
for (String componentId : componentsToEncode) {
UIComponent component = fctx.getViewRoot().findComponent(componentId);
startElement("htmlupdate", null);
writeAttribute("src", componentId, null);
component.encodeAll(fctx);
endElement("htmlupdate");
}
endExtension();
}
super.endDocument();
}
public void encodeComponent(String componentId) {
componentsToEncode.add(componentId);
}
public void addCustomJSUpdate(String componentId, JSUpdateHandler updateHandler) {
customJSUpdates.put(componentId, updateHandler);
}
......
......@@ -206,4 +206,16 @@ footer {
table input+label {
margin-right: 10px;
margin-left: 3px;
}
#users-list-wrapper {
font-size: 17px;
}
#users-list-wrapper li {
padding-top: 8px;
}
#users-list-wrapper li a:hover {
text-decoration: none;
}
\ No newline at end of file
......@@ -27,6 +27,40 @@
$('#errorModal .errorName').text("");
$('#errorModal .errorMessage').text(errorMessage);
$('#errorModal').modal('show');
},
doOnSuccess: function (callback) {
return function (event) {
if (event.status === 'success'
&& $(event.responseXML).find('error').length === 0) {
callback();
}
};
},
// Function factory to handle custom communications between the backing bean and JavaScript functions
eventHandlerFactory: function (handler, componentId) {
return function (event) {
if (event.status === 'success'
&& $(event.responseXML).find('error').length === 0) {
var srcId = componentId ? componentId : event.source.getAttribute('id');
var jsUpdate = null;
var jsupdates = event.responseXML.getElementById('jsupdates');
if (jsupdates) {
jsupdates = jsupdates.childNodes;
for (var i = 0; i < jsupdates.length; i++) {
var jsu = jsupdates[i];
if (jsu.getAttribute('src') === srcId) {
jsUpdate = jsu.innerText || jsu.textContent;
break;
}
}
}
handler(event.source, jsUpdate);
}
};
}
};
......@@ -40,6 +74,9 @@
if (jsf) {
jsf.ajax.addOnError(function (error) {
// Close all previously opened modals.
$('.modal').modal('hide');
$('#errorModal .errorName').text(error.errorName);
$('#errorModal .errorMessage').text(error.errorMessage);
if (error.errorName.indexOf('ViewExpiredException') !== -1) {
......
(function ($, TSM) {
// Function factory to handle custom communications between the backing bean and JavaScript functions
function eventHandlerFactory(handler, componentId) {
return function (event) {
if (event.status === 'success') {
var srcId = componentId ? componentId : event.source.getAttribute('id');
var jsUpdate = null, htmlUpdate = null;
var jsupdates = event.responseXML.getElementById('jsupdates');
if (jsupdates) {
jsupdates = jsupdates.childNodes;
for (var i = 0; i < jsupdates.length; i++) {
var jsu = jsupdates[i];
if (jsu.getAttribute('src') === srcId) {
jsUpdate = jsu.innerText || jsu.textContent;
break;
}
}
}
var htmlupdates = event.responseXML.getElementById('htmlupdates');
if (htmlupdates) {
htmlupdates = htmlupdates.childNodes;
for (var i = 0; i < htmlupdates.length; i++) {
var hu = htmlupdates[i];
if (hu.getAttribute('src') === srcId) {
htmlUpdate = hu;
break;
}
}
}
handler(event.source, jsUpdate, htmlUpdate);
}
};
}
var COLUMNS_COMPONENT_ID = 'main:columns-list';
TSM.displayUpdateOperations = eventHandlerFactory(function (srcElement, jsupdate) {
TSM.displayUpdateOperations = TSM.eventHandlerFactory(function (srcElement, jsupdate) {
$('#updateOperationsModal').modal('show');
});
TSM.saveUCDCalled = eventHandlerFactory(function (srcElement, jsupdate) {
TSM.saveUCDCalled = TSM.eventHandlerFactory(function (srcElement, jsupdate) {
if (jsupdate !== null) {
$('#searchUCDModal').modal('hide');
}
......@@ -50,7 +14,7 @@
$('.loading').addClass('hide');
});
TSM.textInputChanged = eventHandlerFactory(function (srcElement, jsupdate) {
TSM.textInputChanged = TSM.eventHandlerFactory(function (srcElement, jsupdate) {
$(srcElement).toggleClass('changed', jsupdate === 'true');
});
......@@ -68,7 +32,7 @@
}
};
TSM.columnRemoved = eventHandlerFactory(function (srcElement, jsupdate, htmlupdate) {
TSM.columnRemoved = TSM.eventHandlerFactory(function (srcElement, jsupdate) {
jsupdate = JSON.parse(jsupdate);
var $ul = $(srcElement).closest('ul');
$(srcElement).closest('a').find('span').addClass('strikeout');
......@@ -80,7 +44,7 @@
}
}, COLUMNS_COMPONENT_ID);
TSM.columnRemovalUndo = eventHandlerFactory(function (srcElement, jsupdate) {
TSM.columnRemovalUndo = TSM.eventHandlerFactory(function (srcElement, jsupdate) {
var $a = $('#main\\:columns-list\\:' + jsupdate + '\\:column-selector');
$a.find('input').prop('disabled', false);
$a.find('.strikeout').removeClass('strikeout');
......
......@@ -2,12 +2,9 @@
window.UCDEditor = {
open: function (event) {
if (event.status === 'success') {
$('#ucd-editor').modal('show');
}
}
open: TSM.doOnSuccess(function () {
$('#ucd-editor').modal('show');
})
};
})(jQuery);
\ No newline at end of file
(function ($, TSM) {
window.UserEditor = {
open: TSM.doOnSuccess(function () {
$('#user-editing-modal').modal('show');
}),
checkEditResult: TSM.eventHandlerFactory(function(srcElement, jsUpdate) {
if(jsUpdate === "true") {
$('#user-editing-modal').modal('hide');
}
}),
openConfirmDelete: TSM.doOnSuccess(function () {
$('#confirm-user-deletion-modal').modal('show');
}),
closeConfirmDelete: TSM.doOnSuccess(function () {
$('#confirm-user-deletion-modal').modal('hide');
})
};
})(jQuery, TSM);
\ No newline at end of file