Skip to content

Commit

Permalink
Snapshot upload error message handling and field validation
Browse files Browse the repository at this point in the history
Signed-off-by: ct-ajovanovic <aleksandra.jovanovic@comtrade.com>
  • Loading branch information
ct-ajovanovic authored and Coduz committed Dec 10, 2018
1 parent 99424bc commit 2687c63
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 3 deletions.
Expand Up @@ -15,6 +15,7 @@
import org.eclipse.kapua.DeviceMenagementException;
import org.eclipse.kapua.KapuaEntityNotFoundException;
import org.eclipse.kapua.KapuaIllegalAccessException;
import org.eclipse.kapua.KapuaIllegalArgumentException;
import org.eclipse.kapua.KapuaUnauthenticatedException;
import org.eclipse.kapua.app.console.module.api.server.KapuaRemoteServiceServlet;
import org.eclipse.kapua.app.console.module.api.setting.ConsoleSetting;
Expand Down Expand Up @@ -127,6 +128,10 @@ private void doPostConfigurationSnapshot(KapuaFormFields kapuaFormFields, HttpSe
logger.error("Device menagement exception", edme);
resp.sendError(404, edme.getMessage());
return;
} catch (KapuaIllegalArgumentException kiae) {
logger.error("Illegal argument exception", kiae);
resp.sendError(400, kiae.getArgumentName());
return;
} catch (Exception e) {
logger.error("Generic error", e);
resp.sendError(500, e.getMessage());
Expand Down
Expand Up @@ -39,6 +39,8 @@
import com.google.gwt.user.client.rpc.AsyncCallback;
import org.eclipse.kapua.app.console.module.api.client.messages.ConsoleMessages;
import org.eclipse.kapua.app.console.module.api.client.util.FailureHandler;
import org.eclipse.kapua.app.console.module.api.client.util.validator.TextFieldValidator;
import org.eclipse.kapua.app.console.module.api.client.util.validator.TextFieldValidator.FieldType;
import org.eclipse.kapua.app.console.module.api.shared.model.GwtXSRFToken;
import org.eclipse.kapua.app.console.module.api.shared.service.GwtSecurityTokenService;
import org.eclipse.kapua.app.console.module.api.shared.service.GwtSecurityTokenServiceAsync;
Expand Down Expand Up @@ -105,7 +107,10 @@ public void handleEvent(FormEvent be) {
int endIndex = htmlResponse.indexOf("</pre>");
if (startIdx != -1 && endIndex != -1) {
errMsg = htmlResponse.substring(startIdx + 5, endIndex);
}
if (("xmlDeviceConfig").equals(errMsg)) {
errMsg = MSGS.fileUploadInvalidShapshotFailure();
}
}
MessageBox.alert(MSGS.error(), MSGS.fileUploadFailure() + ": " + errMsg, null);
}
hide();
Expand All @@ -118,6 +123,8 @@ public void handleEvent(FormEvent be) {
fieldSet.setLayout(layout);

fileUploadField = new FileUploadField();
fileUploadField.setAccept("application/xml");
fileUploadField.setValidator(new TextFieldValidator(fileUploadField, FieldType.SNAPSHOT_FILE));
fileUploadField.setAllowBlank(false);
fileUploadField.setName("uploadedFile");
fileUploadField.setFieldLabel("File");
Expand Down
Expand Up @@ -60,6 +60,7 @@ public enum FieldType {

SIMPLE_NAME("simple_name", "^[a-zA-Z0-9\\-]{3,}$"),
DEVICE_CLIENT_ID("device_client_id", "^[a-zA-Z0-9\\:\\_\\-]{1,}$"),
SNAPSHOT_FILE("snapshot_file", "^([a-zA-Z0-9\\:\\_\\-\\\\]){1,64}(\\.xml)"),
NAME("name", "^[a-zA-Z0-9\\_\\-]{3,}$"),
NAME_SPACE("name_space", "^[a-zA-Z0-9\\ \\_\\-]{3,}$"),
PASSWORD("password", "^.*(?=.{12,})(?=.*\\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[@#$%^&+=!\\~\\|]).*$"),
Expand Down
Expand Up @@ -477,6 +477,7 @@ filteringPanelReset=Reset

fileUploadSuccess=File was successfully uploaded.
fileUploadFailure=File upload failed
fileUploadInvalidShapshotFailure=the file provided is not a valid Kura Snapshot. Please review the file and try again.

commandExecutionFailure=Command execution failed

Expand Down
Expand Up @@ -42,6 +42,8 @@ phoneRegexMsg=Phone number is shorter than 6 digits or it contains invalid chara

editableComboRegexMsg=Invalid provided value. Must be a number or '0 - Disabled'.

snapshot_fileRegexMsg=Only files with .xml extension are allowed. Name can contain only alphanumeric characters combined with dash and/or underscore.

dateRangeValidatorAfter1Jan1970=This date comes before Thursday January 01 01:00:00 CET 1970
dateRangeValidatorEndDateBeforeStartDate=The end date comes before the start date. If not set the start date is automatically set to the current date.

Expand Down
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2011, 2016 Eurotech and/or its affiliates and others
* Copyright (c) 2011, 2018 Eurotech and/or its affiliates and others
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
Expand Down Expand Up @@ -211,7 +211,7 @@ public void put(KapuaId scopeId, KapuaId deviceId, String xmlDeviceConfig, Long
XmlUtil.unmarshal(xmlDeviceConfig, DeviceConfigurationImpl.class),
timeout);
} catch (JAXBException | XMLStreamException | FactoryConfigurationError | SAXException e) {
throw new KapuaIllegalArgumentException(xmlDeviceConfig, xmlDeviceConfig);
throw new KapuaIllegalArgumentException("xmlDeviceConfig", xmlDeviceConfig);
}
}

Expand Down

0 comments on commit 2687c63

Please sign in to comment.