Skip to content

Commit

Permalink
Resource Wizard update - removing creating obsolete attribute and ass…
Browse files Browse the repository at this point in the history
…ociation container in resource wizard that were causing problems. Improved work with Attribute and association references - added new QNameEditor component for editing custom, non-schema reference. Fixed few small (mostly visual) issues on the way
  • Loading branch information
Erik Suta committed Oct 16, 2014
1 parent 5d53b91 commit ac625e2
Show file tree
Hide file tree
Showing 10 changed files with 289 additions and 48 deletions.
@@ -0,0 +1,42 @@
<!--
~ Copyright (c) 2010-2013 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.
-->

<!DOCTYPE html>
<html xmlns:wicket="http://wicket.apache.org">
<wicket:panel>

<dl class="dl-horizontal">
<dt>
<label><wicket:message key="QNameEditor.label.attribute" /></label>
<i wicket:id="attributeTooltip" wicket:message="title:QNameEditor.tooltip.attribute"/>
</dt>
<dd>
<input wicket:id="attribute" type="text" class="form-control input-sm"/>
</dd>
</dl>

<dl class="dl-horizontal">
<dt>
<label><wicket:message key="QNameEditor.label.namespace" /></label>
<i wicket:id="namespaceTooltip" wicket:message="title:QNameEditor.tooltip.namespace"/>
</dt>
<dd>
<select wicket:id="namespace" class="form-control input-sm"></select>
</dd>
</dl>

</wicket:panel>
</html>
@@ -0,0 +1,99 @@
/*
* Copyright (c) 2010-2014 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.component.input;

import com.evolveum.midpoint.web.component.util.SimplePanel;
import com.evolveum.midpoint.web.util.InfoTooltipBehavior;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.form.DropDownChoice;
import org.apache.wicket.markup.html.form.TextField;
import org.apache.wicket.model.IModel;
import org.apache.wicket.model.PropertyModel;

import javax.xml.namespace.QName;
import java.util.ArrayList;
import java.util.List;

/**
* @author shood
* */
public class QNameEditorPanel extends SimplePanel<QName>{

private static final String ID_ATTRIBUTE = "attribute";
private static final String ID_NAMESPACE = "namespace";
private static final String ID_T_ATTRIBUTE = "attributeTooltip";
private static final String ID_T_NAMESPACE = "namespaceTooltip";

public QNameEditorPanel(String id, IModel<QName> model){
super(id, model);
}

@Override
public IModel<QName> getModel() {
IModel<QName> model = super.getModel();
QName modelObject = model.getObject();

if(modelObject == null){
model.setObject(new QName(""));
}

return model;
}

@Override
protected void initLayout(){

TextField attribute = new TextField<>(ID_ATTRIBUTE, new PropertyModel<String>(getModel(), "localPart"));
attribute.setOutputMarkupId(true);
attribute.setOutputMarkupPlaceholderTag(true);
attribute.setRequired(true);
add(attribute);

DropDownChoice namespace = new DropDownChoice<>(ID_NAMESPACE, new PropertyModel<String>(getModel(), "namespaceURI"),
prepareNamespaceList());
namespace.setOutputMarkupId(true);
namespace.setOutputMarkupPlaceholderTag(true);
namespace.setNullValid(false);
namespace.setRequired(true);
add(namespace);

Label attrTooltip = new Label(ID_T_ATTRIBUTE);
attrTooltip.add(new InfoTooltipBehavior());
attrTooltip.setOutputMarkupPlaceholderTag(true);
add(attrTooltip);

Label namespaceTooltip = new Label(ID_T_NAMESPACE);
namespaceTooltip.add(new InfoTooltipBehavior());
namespaceTooltip.setOutputMarkupPlaceholderTag(true);
add(namespaceTooltip);
}

protected List<String> prepareNamespaceList(){
List<String> list = new ArrayList<>();

//icfs
list.add("http://midpoint.evolveum.com/xml/ns/public/connector/icf-1/resource-schema-3");
//ri
list.add("http://midpoint.evolveum.com/xml/ns/public/resource/instance-3");

return list;
}

// public boolean isRequired(){
// return false;
// }
}
@@ -0,0 +1,18 @@
#
# Copyright (c) 2010-2013 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.
#

QNameEditor.label.attribute=Ref. attribute
QNameEditor.label.namespace=Ref. namespace
Expand Up @@ -153,3 +153,6 @@ CapabilityStep.credentials.tooltip.enabled=Tooltip
CapabilityStep.credentials.tooltip.passEnabled=Tooltip
CapabilityStep.credentials.tooltip.passReturned=Tooltip

QNameEditor.tooltip.attribute=Tooltip
QNameEditor.tooltip.namespace=Tooltip

Expand Up @@ -598,52 +598,52 @@ private void dependencyEditPerformed(AjaxRequestTarget target){
new PropertyModel<List<ResourceObjectTypeDependencyType>>(model, SchemaHandlingDto.F_SELECTED + ".dependency"));
getThirdRowContainer().replaceWith(newContainer);

target.add(getThirdRowContainer(), getPageBase().getFeedbackPanel());
target.add(getThirdRowContainer(), get(ID_OBJECT_TYPE_EDITOR), getPageBase().getFeedbackPanel());
}

private void iterationEditPerformed(AjaxRequestTarget target){
WebMarkupContainer newContainer = new ResourceIterationEditor(ID_THIRD_ROW_CONTAINER,
new PropertyModel<IterationSpecificationType>(model, SchemaHandlingDto.F_SELECTED + ".iteration"));
getThirdRowContainer().replaceWith(newContainer);

target.add(getThirdRowContainer(), getPageBase().getFeedbackPanel());
target.add(getThirdRowContainer(), get(ID_OBJECT_TYPE_EDITOR), getPageBase().getFeedbackPanel());
}

private void protectedEditPerformed(AjaxRequestTarget target){
WebMarkupContainer newContainer = new ResourceProtectedEditor(ID_THIRD_ROW_CONTAINER,
new PropertyModel<List<ResourceObjectPatternType>>(model, SchemaHandlingDto.F_SELECTED + "._protected"));
getThirdRowContainer().replaceWith(newContainer);

target.add(getThirdRowContainer(), getPageBase().getFeedbackPanel());
target.add(getThirdRowContainer(), get(ID_OBJECT_TYPE_EDITOR), getPageBase().getFeedbackPanel());
}

private void activationEditPerformed(AjaxRequestTarget target){
WebMarkupContainer newContainer = new ResourceActivationEditor(ID_THIRD_ROW_CONTAINER,
new PropertyModel<ResourceActivationDefinitionType>(model, SchemaHandlingDto.F_SELECTED + ".activation"));
getThirdRowContainer().replaceWith(newContainer);

target.add(getThirdRowContainer(), getPageBase().getFeedbackPanel());
target.add(getThirdRowContainer(), get(ID_OBJECT_TYPE_EDITOR), getPageBase().getFeedbackPanel());
}

private void credentialsEditPerformed(AjaxRequestTarget target){
WebMarkupContainer newContainer = new ResourceCredentialsEditor(ID_THIRD_ROW_CONTAINER,
new PropertyModel<ResourceCredentialsDefinitionType>(model, SchemaHandlingDto.F_SELECTED + ".credentials"));
getThirdRowContainer().replaceWith(newContainer);

target.add(getThirdRowContainer(), getPageBase().getFeedbackPanel());
target.add(getThirdRowContainer(), get(ID_OBJECT_TYPE_EDITOR), getPageBase().getFeedbackPanel());
}

private void editAttributePerformed(AjaxRequestTarget target, ResourceAttributeDefinitionType object){
private void editAttributePerformed(AjaxRequestTarget target, final ResourceAttributeDefinitionType object){
if(model.getObject().getSelected() != null && model.getObject().getSelected().getObjectClass() != null){
WebMarkupContainer newContainer = new ResourceAttributeEditor(ID_THIRD_ROW_CONTAINER, new Model<>(object),
model.getObject().getSelected(), resourceModel.getObject());
getThirdRowContainer().replaceWith(newContainer);

target.add(getThirdRowContainer());
target.add(getThirdRowContainer(), get(ID_OBJECT_TYPE_EDITOR));
} else {
warn(getString("SchemaHandlingStep.message.selectObjectClassAttr"));
getThirdRowContainer().replaceWith(new WebMarkupContainer(ID_THIRD_ROW_CONTAINER));
target.add(getPageBase().getFeedbackPanel(), getThirdRowContainer());
target.add(getPageBase().getFeedbackPanel(), get(ID_OBJECT_TYPE_EDITOR), getThirdRowContainer());
}
}

Expand All @@ -653,11 +653,11 @@ private void editAssociationPerformed(AjaxRequestTarget target, ResourceObjectAs
model.getObject().getSelected(), resourceModel.getObject());
getThirdRowContainer().replaceWith(newContainer);

target.add(getThirdRowContainer(), getPageBase().getFeedbackPanel());
target.add(getThirdRowContainer(), get(ID_OBJECT_TYPE_EDITOR), getPageBase().getFeedbackPanel());
} else {
warn(getString("SchemaHandlingStep.message.selectObjectClassAss"));
getThirdRowContainer().replaceWith(new WebMarkupContainer(ID_THIRD_ROW_CONTAINER));
target.add(getPageBase().getFeedbackPanel(), getThirdRowContainer());
target.add(getPageBase().getFeedbackPanel(), get(ID_OBJECT_TYPE_EDITOR), getThirdRowContainer());
}
}

Expand All @@ -673,6 +673,8 @@ private void savePerformed(){
ModelService modelService = getPageBase().getModelService();
ObjectDelta delta;

removeEmptyContainers(newResource);

try{
oldResource = WebModelUtils.loadObject(ResourceType.class, newResource.getOid(), result, getPageBase());
if(oldResource != null){
Expand Down Expand Up @@ -701,6 +703,15 @@ private void savePerformed(){
private void editObjectTypePerformed(AjaxRequestTarget target, ResourceObjectTypeDefinitionTypeDto objectType){
resetSelected();
objectType.setSelected(true);

if(objectType.getObjectType().getAssociation().isEmpty()){
objectType.getObjectType().getAssociation().add(new ResourceObjectAssociationType());
}

if(objectType.getObjectType().getAttribute().isEmpty()){
objectType.getObjectType().getAttribute().add(new ResourceAttributeDefinitionType());
}

model.getObject().setSelected(objectType.getObjectType());

insertEmptyThirdRow();
Expand Down Expand Up @@ -743,4 +754,41 @@ private void addObjectTypePerformed(AjaxRequestTarget target){
insertEmptyThirdRow();
target.add(getObjectListTable(), getNavigator(), getObjectTypeEditor(), getThirdRowContainer());
}

private void removeEmptyContainers(PrismObject<ResourceType> resourcePrism){
if(resourcePrism == null){
return;
}

ResourceType resource = resourcePrism.asObjectable();

if(resource != null && resource.getSchemaHandling() != null){
SchemaHandlingType schemaHandling = resource.getSchemaHandling();

for(ResourceObjectTypeDefinitionType objectType: schemaHandling.getObjectType()){

//Clear obsolete containers from attributes
List<ResourceAttributeDefinitionType> newAttributeList = new ArrayList<>();
newAttributeList.addAll(objectType.getAttribute());
for(ResourceAttributeDefinitionType attribute: objectType.getAttribute()){
if(attribute.getRef() == null){
newAttributeList.remove(attribute);
}
}
objectType.getAttribute().clear();
objectType.getAttribute().addAll(newAttributeList);

//Clear obsolete containers from associations
List<ResourceObjectAssociationType> newAssociationList = new ArrayList<>();
newAssociationList.addAll(objectType.getAssociation());
for(ResourceObjectAssociationType association: objectType.getAssociation()){
if(association.getKind() == null){
newAssociationList.remove(association);
}
}
objectType.getAssociation().clear();
objectType.getAssociation().addAll(newAssociationList);
}
}
}
}
Expand Up @@ -115,17 +115,18 @@ <h4 class="panel-title">
<div id="other" class="panel-collapse collapse">
<div class="panel-body">

<dl class="dl-horizontal">
<dl wicket:id="schemaRefPanel" class="dl-horizontal">
<dt>
<label><wicket:message key="ResourceAssociationEditor.label.reference" /></label>
<i wicket:id="referenceTooltip" wicket:message="title:SchemaHandlingStep.attribute.tooltip.reference"/>
</dt>
<dd>
<select wicket:id="referenceSelect" class="form-control input-sm"></select>
<input wicket:id="referenceField" type="text" class="form-control input-sm" value=""/>
</dd>
</dl>

<div wicket:id="nonSchemaReferencePanel" />

<dl class="dl-horizontal">
<dt>
<label><wicket:message key="ResourceAssociationEditor.label.allow" /></label>
Expand Down

0 comments on commit ac625e2

Please sign in to comment.