Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MID-2117 - validation plugin interface initial implementation.
- Loading branch information
Erik Suta
committed
Mar 2, 2015
1 parent
2fbe37e
commit b5f40b6
Showing
3 changed files
with
209 additions
and
0 deletions.
There are no files selected for viewing
87 changes: 87 additions & 0 deletions
87
...n-gui/src/main/java/com/evolveum/midpoint/web/util/validation/IMidpointFormValidator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
/* | ||
* Copyright (c) 2010-2015 Evolveum | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.evolveum.midpoint.web.util.validation; | ||
|
||
import com.evolveum.midpoint.prism.PrismObject; | ||
import com.evolveum.midpoint.prism.delta.ObjectDelta; | ||
import com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType; | ||
|
||
import java.util.Collection; | ||
|
||
/** | ||
* <p> | ||
* A simple interface that aims to work as a custom validation plugin used in GUI. | ||
* This plugin should be used BEFORE the changes made by user are sent for processing | ||
* to model component. | ||
* </p> | ||
* | ||
* <p> | ||
* This plugin serves as another form of validation process and can be used, when | ||
* standard validation mechanism of GUI forms (usually aimed to validate one field | ||
* at a time) is not enough. A classic use case may be a situation, when we need to | ||
* examine the relationship between attributes edited via GUI before sending them | ||
* for processing to model component. | ||
* </p> | ||
* | ||
* @author shood | ||
* */ | ||
public interface IMidpointFormValidator { | ||
|
||
/** | ||
* <p> | ||
* Performs validation on an instance of object. Entire data | ||
* of object are accessible for validation purposes | ||
* </p> | ||
* | ||
* @param object | ||
* An object to validate | ||
* | ||
* @return A collection of SimpleValidationError instances | ||
* | ||
* */ | ||
Collection<SimpleValidationError> validateObject(PrismObject<? extends ObjectType> object); | ||
|
||
/** | ||
* <p> | ||
* Performs validation on a collection of ObjectDelta objects | ||
* </p> | ||
* | ||
* @param deltas | ||
* A collection of ObjectDelta instances - a representation of changes made by user | ||
* | ||
* @return A collection of SimpleValidationError instances | ||
* | ||
* */ | ||
Collection<SimpleValidationError> validateObject(Collection<ObjectDelta<? extends ObjectType>> deltas); | ||
|
||
/** | ||
* Performs a validation on an instance of object. Entire data of the object | ||
* are accessible for validation purposes as well as a collection of ObjectDelta | ||
* instances - the collection of current changes made by user prior to | ||
* validation. | ||
* | ||
* @param object | ||
* An object to validate | ||
* | ||
* @param deltas | ||
* A collection of ObjectDelta instances - a representation of changes made by user | ||
* | ||
* @return A collection of SimpleValidationError instances | ||
* | ||
* */ | ||
Collection<SimpleValidationError> validateObject(PrismObject<? extends ObjectType> object, Collection<ObjectDelta<? extends ObjectType>> deltas); | ||
} |
44 changes: 44 additions & 0 deletions
44
...in-gui/src/main/java/com/evolveum/midpoint/web/util/validation/MidpointFormValidator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/* | ||
* Copyright (c) 2010-2015 Evolveum | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.evolveum.midpoint.web.util.validation; | ||
|
||
import com.evolveum.midpoint.prism.PrismObject; | ||
import com.evolveum.midpoint.prism.delta.ObjectDelta; | ||
import com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType; | ||
|
||
import java.util.Collection; | ||
|
||
/** | ||
* TODO - implement | ||
* */ | ||
public class MidpointFormValidator implements IMidpointFormValidator{ | ||
|
||
@Override | ||
public Collection<SimpleValidationError> validateObject(PrismObject<? extends ObjectType> object) { | ||
return null; | ||
} | ||
|
||
@Override | ||
public Collection<SimpleValidationError> validateObject(Collection<ObjectDelta<? extends ObjectType>> deltas) { | ||
return null; | ||
} | ||
|
||
@Override | ||
public Collection<SimpleValidationError> validateObject(PrismObject<? extends ObjectType> object, Collection<ObjectDelta<? extends ObjectType>> deltas) { | ||
return null; | ||
} | ||
} |
78 changes: 78 additions & 0 deletions
78
...in-gui/src/main/java/com/evolveum/midpoint/web/util/validation/SimpleValidationError.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
/* | ||
* Copyright (c) 2010-2015 Evolveum | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.evolveum.midpoint.web.util.validation; | ||
|
||
import com.evolveum.prism.xml.ns._public.types_3.ItemPathType; | ||
|
||
import java.io.Serializable; | ||
|
||
/** | ||
* This is just a simple representation of custom form validation error. Currently, it holds | ||
* only a simple String 'message' attribute as an information about validation error and | ||
* an ItemPathType 'attribute' as a path to the source of error. Feel free | ||
* to add any information about validation errors that yout custom validator requires. | ||
* | ||
* @author shood | ||
* */ | ||
public class SimpleValidationError implements Serializable{ | ||
|
||
private String message; | ||
private ItemPathType attribute; | ||
|
||
public SimpleValidationError() {} | ||
|
||
public SimpleValidationError(String message, ItemPathType attribute) { | ||
this.message = message; | ||
this.attribute = attribute; | ||
} | ||
|
||
public String getMessage() { | ||
return message; | ||
} | ||
|
||
public void setMessage(String message) { | ||
this.message = message; | ||
} | ||
|
||
public ItemPathType getAttribute() { | ||
return attribute; | ||
} | ||
|
||
public void setAttribute(ItemPathType attribute) { | ||
this.attribute = attribute; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) return true; | ||
if (!(o instanceof SimpleValidationError)) return false; | ||
|
||
SimpleValidationError that = (SimpleValidationError) o; | ||
|
||
if (attribute != null ? !attribute.equals(that.attribute) : that.attribute != null) return false; | ||
if (message != null ? !message.equals(that.message) : that.message != null) return false; | ||
|
||
return true; | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
int result = message != null ? message.hashCode() : 0; | ||
result = 31 * result + (attribute != null ? attribute.hashCode() : 0); | ||
return result; | ||
} | ||
} |