use of com.servoy.j2db.persistence.ISupportUpdateableName in project servoy-client by Servoy.
the class FlattenedSolution method clonePersist.
@SuppressWarnings({ "unchecked", "nls" })
public <T extends AbstractBase> T clonePersist(T persist, String newName, AbstractBase newParent) {
T clone = (T) persist.clonePersist(persist.getParent() == newParent ? null : newParent);
final Map<Object, Object> updatedElementIds = AbstractPersistFactory.resetUUIDSRecursively(clone, getPersistFactory(), false);
if (persist.getParent() == newParent) {
newParent.addChild(clone);
}
// make sure that this persist is not seen as a copy a real persist/form
clone.setRuntimeProperty(CLONE_PROPERTY, null);
if (clone instanceof ISupportUpdateableName) {
try {
((ISupportUpdateableName) clone).updateName(new ScriptNameValidator(this), newName);
} catch (Exception e) {
if (newParent != null) {
newParent.removeChild(clone);
}
throw new RuntimeException("name '" + newName + "' invalid for the clone of " + ((ISupportName) persist).getName() + ", error: " + e.getMessage());
}
}
if (clone instanceof ISupportChilds) {
clone.acceptVisitor(new IPersistVisitor() {
public Object visit(IPersist o) {
if (o instanceof AbstractBase) {
Map<String, Object> propertiesMap = ((AbstractBase) o).getPropertiesMap();
for (Map.Entry<String, Object> entry : propertiesMap.entrySet()) {
Object elementId = updatedElementIds.get(entry.getValue());
if (elementId instanceof Integer) {
Element element = StaticContentSpecLoader.getContentSpec().getPropertyForObjectTypeByName(o.getTypeID(), entry.getKey());
if (element.getTypeID() == IRepository.ELEMENTS)
((AbstractBase) o).setProperty(entry.getKey(), elementId);
} else if (entry.getValue() instanceof JSONObject) {
updateElementReferences((JSONObject) entry.getValue(), updatedElementIds);
}
}
}
return null;
}
});
}
if (securityAccess != null) {
ConcurrentMap<Object, Integer> securityValues = securityAccess.getLeft();
for (Object elementUUID : new HashSet(securityValues.keySet())) {
if (updatedElementIds.containsKey(elementUUID.toString())) {
UUID uuid = Utils.getAsUUID(updatedElementIds.get(elementUUID.toString()), false);
if (uuid != null) {
securityValues.put(uuid, securityValues.get(elementUUID));
}
}
}
}
flush(persist);
getIndex().reload();
return clone;
}
Aggregations