Commit 5e2bad95 authored by Sonia Zorba's avatar Sonia Zorba
Browse files

Changes and improvements in credentials insertion page

parent 61d7d76e
......@@ -266,9 +266,6 @@ public class TapSchema implements EntitiesContainer<Schema>, Serializable {
if (!keyFound) {
boolean setKeyToRemove = true;
if (Tasman.ALLOWS_FICTITIOUS_KEYS) {
// TODO
}
if (setKeyToRemove) {
String[] fromColumns = new String[kcPropsById.size()];
String[] targetColumns = new String[kcPropsById.size()];
......
......@@ -39,14 +39,14 @@ public class Credentials implements Serializable {
private static final long serialVersionUID = 1153912575502196261L;
private static final Logger LOG = LoggerFactory.getLogger(Credentials.class);
private DatabaseType databaseType;
private String hostname;
private int port;
private String username;
private String password;
private String database;
private DatabaseType databaseType;
public Credentials() {
this(DatabaseType.MYSQL);
}
......@@ -56,6 +56,16 @@ public class Credentials implements Serializable {
this.setDefaults();
}
// Copy constructor
public Credentials(Credentials credentials) {
this(credentials.getDatabaseType());
this.hostname = credentials.getHostname();
this.port = credentials.getPort();
this.username = credentials.getUsername();
this.password = credentials.getPassword();
this.database = credentials.getDatabase();
}
/**
* The name of the server that hosts the RDBMS.
*/
......
......@@ -65,6 +65,8 @@ public class PropertyModel implements Serializable {
defaultValue = Long.parseLong(strDefVal);
} else if (type == Float.class) {
defaultValue = Float.parseFloat(strDefVal);
} else if (type == Boolean.class) {
defaultValue = Boolean.parseBoolean(strDefVal);
} else {
throw new UnsupportedOperationException("Default value for type " + type.getCanonicalName() + " not supported yet.");
}
......
......@@ -24,8 +24,10 @@ package it.inaf.ia2.tsm.model;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import javax.xml.bind.JAXB;
......@@ -102,4 +104,14 @@ public class TapSchemaModels {
public static TableModel getTableModel(String tableName, String version) {
return getTapSchemaModel(version).getTables().get(tableName);
}
public static List<String> getAvailableVersions() {
List<String> versions = new ArrayList<>();
Iterator<TapSchemaModel> ite = getIterator();
while (ite.hasNext()) {
TapSchemaModel tapSchemaModel = ite.next();
versions.add(tapSchemaModel.getVersion());
}
return versions;
}
}
......@@ -34,7 +34,6 @@ import java.util.Properties;
public class Tasman {
public static final String[] XML_MODEL_FILES;
public static final boolean ALLOWS_FICTITIOUS_KEYS;
static {
try (InputStream in = Tasman.class.getClassLoader().getResourceAsStream("core.properties")) {
......@@ -46,8 +45,6 @@ public class Tasman {
String suffix = models[i];
XML_MODEL_FILES[i] = "tap_schema" + File.separator + "tap_schema-" + suffix + ".xml";
}
ALLOWS_FICTITIOUS_KEYS = Boolean.parseBoolean(props.getProperty("allow_fictitious_keys"));
} catch (IOException e) {
throw new ExceptionInInitializerError(e);
}
......
......@@ -233,18 +233,11 @@ public class ConfigurationManager {
* @return true if the credentials has been deleted from the list, false
* otherwise.
*/
public synchronized boolean deleteCredentials(String username, TapCredentials credentials) {
public synchronized boolean deleteCredentials(String username, int credentialsIndex) {
for (UserConfiguration user : usersConfig.getUsers()) {
if (user.getUsername().equals(username)) {
Iterator<TapCredentials> ite = user.getCredentialsInfo().iterator();
while (ite.hasNext()) {
TapCredentials tapCredentials = ite.next();
if (tapCredentials.equals(credentials)) {
ite.remove();
updateUsersConfigurationFile();
return true;
}
}
user.getCredentialsInfo().remove(credentialsIndex);
return true;
}
}
return false;
......
......@@ -25,6 +25,10 @@ package it.inaf.ia2.tsm.webapp;
import it.inaf.ia2.tsm.webapp.xmlconfig.SeparatedCredentials;
import it.inaf.ia2.tsm.datalayer.Credentials;
import it.inaf.ia2.tsm.datalayer.DBWrapper;
import it.inaf.ia2.tsm.model.TapSchemaModels;
import it.inaf.ia2.tsm.webapp.env.UIModal;
import it.inaf.ia2.tsm.webapp.xmlconfig.JoinedCredentials;
import it.inaf.ia2.tsm.webapp.xmlconfig.TapCredentials;
import java.io.IOException;
import java.io.Serializable;
import java.sql.SQLException;
......@@ -58,54 +62,87 @@ public class CredentialsEditing implements Serializable {
@Inject
private SchemaSelectionBean schemaSelectionBean;
private Integer credentialsInEditing;
private Integer credentialsToRemove;
private UIModal.StatusObserver credentialsDialogStatusObserver;
private boolean credentialsDialogOpened;
private List<String> tapSchemaVersions;
private boolean separateCredentials;
private Credentials sourceCredentials;
private Credentials tapSchemaCredentials;
private boolean separateCredentials;
private int currentEditingRow;
private String tapSchemaName;
private String tapSchemaVersion;
private boolean hasObscore;
public void test() {
String x = "";
}
@PostConstruct
public void init() {
sourceCredentials = new Credentials();
tapSchemaCredentials = new Credentials();
this.credentialsDialogStatusObserver = new UIModal.StatusObserver() {
@Override
public void statusChanged(boolean isOpen) {
credentialsDialogOpened = isOpen;
}
};
this.tapSchemaVersions = TapSchemaModels.getAvailableVersions();
}
public List getSavedCredentials() {
public List<TapCredentials> getSavedCredentials() {
return user.getUserConfiguration().getCredentialsInfo();
}
public void editCredentials(Credentials credentials, int index) {
this.sourceCredentials = credentials;
separateCredentials = false;
currentEditingRow = index;
}
public void editCredentials(int index) {
credentialsInEditing = index;
TapCredentials credentials = getSavedCredentials().get(index);
if (credentials instanceof JoinedCredentials) {
public void editSeparateCredentials(SeparatedCredentials sc, int index) {
this.sourceCredentials = sc.getSourceCredentials();
this.tapSchemaCredentials = sc.getTapSchemaCredentials();
currentEditingRow = index;
separateCredentials = true;
JoinedCredentials joinedCredentials = (JoinedCredentials) credentials;
separateCredentials = false;
sourceCredentials = new Credentials(joinedCredentials.getCredentials());
// in case the user wants to split credentials
tapSchemaCredentials = new Credentials();
} else if (credentials instanceof SeparatedCredentials) {
SeparatedCredentials separatedCredentials = (SeparatedCredentials) credentials;
separateCredentials = true;
sourceCredentials = new Credentials(separatedCredentials.getSourceCredentials());
tapSchemaCredentials = new Credentials(separatedCredentials.getTapSchemaCredentials());
}
tapSchemaName = credentials.getTapSchemaName();
tapSchemaVersion = credentials.getTapSchemaVersion();
hasObscore = credentials.isHasObscore();
}
public void addNewCredentials() {
separateCredentials = false;
this.sourceCredentials = new Credentials();
this.tapSchemaCredentials = new Credentials();
currentEditingRow = getSavedCredentials().size();
sourceCredentials = new Credentials();
tapSchemaCredentials = new Credentials();
tapSchemaName = "";
tapSchemaVersion = "";
hasObscore = false;
}
public String loginWithSingleCredentials(Credentials credentials) {
LOG.debug("Login with single credentials");
return loginWithDBWrapper(new DBWrapper(credentials));
// public void editCredentials(Credentials credentials, int index) {
// this.sourceCredentials = credentials;
// separateCredentials = false;
// currentEditingRow = index;
// }
//
// public void editSeparateCredentials(SeparatedCredentials sc, int index) {
// this.sourceCredentials = sc.getSourceCredentials();
// this.tapSchemaCredentials = sc.getTapSchemaCredentials();
// currentEditingRow = index;
// separateCredentials = true;
// }
public String loginWithJoinedCredentials(JoinedCredentials credentials) {
return loginWithDBWrapper(new DBWrapper(credentials.getCredentials()));
}
public String loginWithSeparatedCredentials(Credentials sourceCredentials, Credentials tapSchemaCredentials) {
LOG.debug("Login with separated credentials");
return loginWithDBWrapper(new DBWrapper(sourceCredentials, tapSchemaCredentials));
}
......@@ -144,6 +181,18 @@ public class CredentialsEditing implements Serializable {
// config.updateUsersConfigurationFile();
}
public UIModal.StatusObserver getCredentialsDialogStatus() {
return credentialsDialogStatusObserver;
}
public List<String> getTapSchemaVersions() {
return tapSchemaVersions;
}
public void setTapSchemaVersions(List<String> tapSchemaVersions) {
this.tapSchemaVersions = tapSchemaVersions;
}
public boolean isSeparateCredentials() {
return separateCredentials;
}
......@@ -152,6 +201,41 @@ public class CredentialsEditing implements Serializable {
this.separateCredentials = separateCredentials;
}
// public void separateCredentialsChanged() {
// if (separateCredentials) {
// Credentials credentials = getJoinedCredentialsInEditing().getCredentials();
// SeparatedCredentials separatedCredentials = new SeparatedCredentials();
// separatedCredentials.setSourceCredentials(credentials);
// credentialsInEditing = separatedCredentials;
// } else {
// Credentials credentials = getSeparatedCredentialsInEditing().getSourceCredentials();
// JoinedCredentials joinedCredentials = new JoinedCredentials();
// joinedCredentials.setCredentials(credentials);
// credentialsInEditing = joinedCredentials;
// }
// }
//
// public JoinedCredentials getJoinedCredentialsInEditing() {
// if (credentialsInEditing instanceof JoinedCredentials) {
// return (JoinedCredentials) credentialsInEditing;
// }
// return null;
// }
//
// public SeparatedCredentials getSeparatedCredentialsInEditing() {
// if (credentialsInEditing instanceof SeparatedCredentials) {
// return (SeparatedCredentials) credentialsInEditing;
// }
// return null;
// }
public boolean isCredentialsDialogOpened() {
return credentialsDialogOpened;
}
public void setCredentialsDialogOpened(boolean credentialsDialogOpened) {
this.credentialsDialogOpened = credentialsDialogOpened;
}
public Credentials getSourceCredentials() {
return sourceCredentials;
}
......@@ -168,11 +252,27 @@ public class CredentialsEditing implements Serializable {
this.tapSchemaCredentials = tapSchemaCredentials;
}
public boolean isCredentialsDialogOpened() {
return credentialsDialogOpened;
public String getTapSchemaName() {
return tapSchemaName;
}
public void setCredentialsDialogOpened(boolean credentialsDialogOpened) {
this.credentialsDialogOpened = credentialsDialogOpened;
public void setTapSchemaName(String tapSchemaName) {
this.tapSchemaName = tapSchemaName;
}
public String getTapSchemaVersion() {
return tapSchemaVersion;
}
public void setTapSchemaVersion(String tapSchemaVersion) {
this.tapSchemaVersion = tapSchemaVersion;
}
public boolean isHasObscore() {
return hasObscore;
}
public void setHasObscore(boolean hasObscore) {
this.hasObscore = hasObscore;
}
}
......@@ -45,7 +45,6 @@ public class ApplicationConfig extends Application {
* out calling this method in getClasses().
*/
private void addRestResourceClasses(Set<Class<?>> resources) {
resources.add(it.inaf.ia2.tsm.webapp.CredentialsDialogResource.class);
resources.add(it.inaf.ia2.tsm.webapp.TapSchemaLoaderResource.class);
resources.add(it.inaf.ia2.tsm.webapp.env.KeepAliveResource.class);
}
......
......@@ -20,29 +20,52 @@
* this program; if not, write to the Free Software Foundation, Inc., 51
* Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package it.inaf.ia2.tsm.webapp;
package it.inaf.ia2.tsm.webapp.env;
import javax.ws.rs.Path;
import javax.enterprise.context.RequestScoped;
import javax.inject.Inject;
import javax.ws.rs.POST;
import javax.ws.rs.QueryParam;
import java.io.IOException;
import javax.faces.component.FacesComponent;
import javax.faces.component.UIComponentBase;
import javax.faces.context.FacesContext;
import javax.faces.context.ResponseWriter;
/**
* REST Web Service for setting opening dialog status using JavaScript. This is
* necessary to conditionally disable JSF validation when dialog is closed.
*
* @author Sonia Zorba {@literal <zorba at oats.inaf.it>}
*/
@Path("credentialsDialog")
@RequestScoped
public class CredentialsDialogResource {
@FacesComponent(tagName = "modal", namespace = "http://ia2.inaf.it/component", createTag = true)
public class UIModal extends UIComponentBase {
@Inject
CredentialsEditing credentialsEditing;
public static abstract class StatusObserver {
@POST
public void setOpened(@QueryParam("opened") boolean opened) {
credentialsEditing.setCredentialsDialogOpened(opened);
public abstract void statusChanged(boolean isOpen);
}
@Override
public void decode(FacesContext context) {
if (getAttributes().containsKey("status-observer")) {
StatusObserver status = (StatusObserver) getAttributes().get("status-observer");
boolean open = Boolean.parseBoolean((String) getAttributes().get("open"));
status.statusChanged(open);
}
}
@Override
public String getFamily() {
return "modal";
}
@Override
public void encodeBegin(FacesContext context) throws IOException {
ResponseWriter writer = context.getResponseWriter();
writer.write("<div class=\"modal fade\" tabindex=\"-1\" role=\"dialog\" id=\"");
writer.write(getClientId());
writer.write("\">");
}
@Override
public void encodeEnd(FacesContext context) throws IOException {
ResponseWriter writer = context.getResponseWriter();
writer.write("</div>");
}
}
......@@ -36,12 +36,19 @@ public class JoinedCredentials extends TapCredentials {
private Credentials credentials;
public JoinedCredentials() {
credentials = new Credentials();
}
public JoinedCredentials(Credentials credentials) {
this.credentials = credentials;
}
// Copy constructor
public JoinedCredentials(JoinedCredentials joinedCredentials) {
super(joinedCredentials);
this.credentials = new Credentials(joinedCredentials.getCredentials());
}
public Credentials getCredentials() {
return credentials;
}
......
......@@ -38,6 +38,8 @@ public class SeparatedCredentials extends TapCredentials {
private Credentials tapSchemaCredentials;
public SeparatedCredentials() {
this.sourceCredentials = new Credentials();
this.tapSchemaCredentials = new Credentials();
}
public SeparatedCredentials(Credentials sourceCredentials, Credentials tapSchemaCredentials) {
......@@ -45,6 +47,13 @@ public class SeparatedCredentials extends TapCredentials {
this.tapSchemaCredentials = tapSchemaCredentials;
}
// Copy constructor
public SeparatedCredentials(SeparatedCredentials separatedCredentials) {
super(separatedCredentials);
this.sourceCredentials = new Credentials(separatedCredentials.getSourceCredentials());
this.tapSchemaCredentials = new Credentials(separatedCredentials.getTapSchemaCredentials());
}
@XmlElement(name = "source-credentials")
public Credentials getSourceCredentials() {
return sourceCredentials;
......
......@@ -37,6 +37,16 @@ public abstract class TapCredentials implements Serializable {
private String tapSchemaVersion;
private boolean hasObscore;
public TapCredentials() {
}
// Copy constructor
public TapCredentials(TapCredentials tapCredentials) {
this.tapSchemaName = tapCredentials.getTapSchemaName();
this.tapSchemaVersion = tapCredentials.getTapSchemaVersion();
this.hasObscore = tapCredentials.isHasObscore();
}
@XmlElement(name = "tap_schema_name")
public String getTapSchemaName() {
return tapSchemaName;
......
(function () {
function checkSeparateCredentials() {
var separateCredentials = $('#main\\:separate-credentials').is(':checked');
$('#main\\:credentials-modal .modal-dialog').toggleClass('modal-lg', separateCredentials);
}
window.credentials = {
editClicked: function (event) {
if (event.status === 'success') {
$('#credentials-modal').modal('show');
$('#main\\:credentials-modal').modal('show');
}
},
credentialsSaved: function (event) {
if (event.status === 'success') {
if ($('#credentials-modal .text-danger').length === 0) {
$('#credentials-modal').modal('hide');
if ($('#main\\:credentials-modal .text-danger').length === 0) {
$('#main\\:credentials-modal').modal('hide');
}
}
},
separateCredentialsChanged: function (event) {
if (event.status === 'success') {
checkSeparateCredentials();
}
}
};
$(document).ready(function () {
$('body').on('shown.bs.modal', '#credentials-modal', function ( ) {
$.post(TSM.getRestPath("credentialsDialog?opened=true"));
});
$('body').on('hidden.bs.modal', '#credentials-modal', function ( ) {
$.post(TSM.getRestPath("credentialsDialog?opened=false"));
$('body').on('show.bs.modal', '#main\\:credentials-modal', function ( ) {
checkSeparateCredentials();
});
// $('body').on('shown.bs.modal', '#main\\:credentials-modal', function ( ) {
// $.post(TSM.getRestPath("credentialsDialog?opened=true"));
// });
// $('body').on('hidden.bs.modal', '#main\\:credentials-modal', function ( ) {
// $.post(TSM.getRestPath("credentialsDialog?opened=false"));
// });
$('body').on('keyup', '#credentials-modal input', function (event) {
$('body').on('keyup', '#main\\:credentials-modal input', function (event) {
if (event.keyCode === 13) {
$('#main\\:save-credentials').click();
event.preventDefault();
......
Supports Markdown
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