Fix empty controller name (#925)

* Truncate target name when name is empty and controllerId exceeds name length limit
* Add check if controllerId is null
* Use seperate method to truncate controllerId + use Array.asList to create list
* Make truncateControllerIdToMaxNameLength a static method
* Additionally check target name by calling target management

Signed-off-by: Sebastian Firsching <sebastian.firsching@bosch-si.com>
This commit is contained in:
Sebastian Firsching
2020-01-27 13:09:43 +01:00
committed by Jeroen Laverman
parent 835757e93a
commit 62c876a435
2 changed files with 27 additions and 1 deletions

View File

@@ -192,10 +192,15 @@ public class JpaTarget extends AbstractJpaNamedEntity implements Target, EventAw
*/
public JpaTarget(final String controllerId, final String securityToken) {
this.controllerId = controllerId;
setName(controllerId);
setName(truncateControllerIdToMaxNameLength(controllerId));
this.securityToken = securityToken;
}
private static String truncateControllerIdToMaxNameLength(final String controllerId) {
return controllerId != null && controllerId.length() > NAME_MAX_SIZE ? controllerId.substring(0, NAME_MAX_SIZE)
: controllerId;
}
JpaTarget() {
// empty constructor for JPA.
}