Skip to content

Commit

Permalink
Merge branch 'master' into feature/groovy-sandbox
Browse files Browse the repository at this point in the history
  • Loading branch information
semancik committed Mar 20, 2019
2 parents f5a06f0 + a323bbc commit 366299c
Show file tree
Hide file tree
Showing 24 changed files with 770 additions and 31 deletions.
Expand Up @@ -155,6 +155,7 @@ protected void configure(HttpSecurity http) throws Exception {
}

http.headers().disable();
http.headers().frameOptions().deny();

if (Arrays.stream(environment.getActiveProfiles()).anyMatch(p -> p.equalsIgnoreCase("cas"))) {
http.addFilterAt(casFilter(), CasAuthenticationFilter.class);
Expand Down
@@ -0,0 +1,40 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Copyright (c) 2010-2019 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.
-->

<html xmlns="http://www.w3.org/1999/xhtml" xmlns:wicket="http://wicket.apache.org">
<wicket:panel>
<div class="row">
<div wicket:id="defaultValuePanel"/>
</div>
<div wicket:id="fullDataContainer">
<div class="row">
<div class="col-md-4"><wicket:message key="PolyStringEditorPanel.defaultLabel" /></div>
<div class="col-md-8" wicket:id="origValue"/>
</div>
<div class="row">
<div class="col-md-4"><wicket:message key="PolyStringEditorPanel.keyLabel" /></div>
<div class="col-md-8" wicket:id="keyValue"/>
</div>
<div wicket:id="languagesRepeater" class="row">
<div class="col-md-4" wicket:id="languageName" />
<div class="col-md-8" wicket:id="translation"/>
</div>
</div>
<div class="show-empty-button" wicket:id="showHideLanguages"/>

</wicket:panel>
</html>
@@ -0,0 +1,136 @@
/*
* Copyright (c) 2010-2019 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.prism;

import com.evolveum.midpoint.gui.api.component.BasePanel;
import com.evolveum.midpoint.web.component.AjaxButton;
import com.evolveum.midpoint.web.component.input.TextPanel;
import com.evolveum.midpoint.web.component.util.VisibleBehaviour;
import com.evolveum.midpoint.web.component.util.VisibleEnableBehaviour;
import com.evolveum.prism.xml.ns._public.types_3.PolyStringTranslationArgumentType;
import com.evolveum.prism.xml.ns._public.types_3.PolyStringType;
import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.behavior.AttributeAppender;
import org.apache.wicket.markup.html.WebMarkupContainer;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.list.ListItem;
import org.apache.wicket.markup.html.list.ListView;
import org.apache.wicket.model.IModel;
import org.apache.wicket.model.Model;

import java.util.ArrayList;
import java.util.List;

/**
* Created by honchar
*/
public class PolyStringEditorPanel extends BasePanel<PolyStringType>{
private static final long serialVersionUID = 1L;

private static final String ID_DEFAULT_VALUE_PANEL = "defaultValuePanel";
private static final String ID_FULL_DATA_CONTAINER = "fullDataContainer";
private static final String ID_ORIG_VALUE = "origValue";
private static final String ID_KEY_VALUE = "keyValue";
private static final String ID_LANGUAGES_REPEATER = "languagesRepeater";
private static final String ID_LANGUAGE_NAME = "languageName";
private static final String ID_TRANSLATION = "translation";
private static final String ID_SHOW_HIDE_LANGUAGES = "showHideLanguages";

private boolean showFullData = false;

public PolyStringEditorPanel(String id, IModel<PolyStringType> model){
super(id, model);
}

@Override
protected void onInitialize(){
initLayout();
}

private void initLayout(){
TextPanel<String> defaultValuePanel = new TextPanel<String>(ID_DEFAULT_VALUE_PANEL, Model.of(getDefaultPolyStringValue()));
defaultValuePanel.setOutputMarkupId(true);
defaultValuePanel.add(new VisibleBehaviour(() -> !showFullData));
add(defaultValuePanel);

WebMarkupContainer fullDataContainer = new WebMarkupContainer(ID_FULL_DATA_CONTAINER);
fullDataContainer.setOutputMarkupId(true);
fullDataContainer.add(new VisibleBehaviour(() -> showFullData));
add(fullDataContainer);

TextPanel<String> origValue = new TextPanel<String>(ID_ORIG_VALUE, Model.of(getDefaultPolyStringValue()));
origValue.setOutputMarkupId(true);
fullDataContainer.add(origValue);

TextPanel<String> keyValue = new TextPanel<String>(ID_KEY_VALUE, Model.of(getKeyValue()));
keyValue.setOutputMarkupId(true);
fullDataContainer.add(keyValue);

ListView<PolyStringTranslationArgumentType> languagesContainer =
new ListView<PolyStringTranslationArgumentType>(ID_LANGUAGES_REPEATER, Model.ofList(getTranslationArgumentList())) {
private static final long serialVersionUID = 1L;

@Override
protected void populateItem(ListItem<PolyStringTranslationArgumentType> listItem) {
Label languageName = new Label(ID_LANGUAGE_NAME, Model.of(listItem.getModelObject().getValue()));
languageName.setOutputMarkupId(true);
listItem.add(languageName);

//TODO what value do we need to display?
TextPanel<String> translation = new TextPanel<String>(ID_TRANSLATION, Model.of(listItem.getModelObject().getTranslation().toString()));
translation.setOutputMarkupId(true);
listItem.add(translation);

}
};
languagesContainer.setOutputMarkupId(true);
fullDataContainer.add(languagesContainer);


AjaxButton showHideLanguagesButton = new AjaxButton(ID_SHOW_HIDE_LANGUAGES, showFullData ? createStringResource("PolyStringEditorPanel.hideLanguages") :
createStringResource("PolyStringEditorPanel.showLanguages")) {

private static final long serialVersionUID = 1L;

@Override
public void onClick(AjaxRequestTarget target) {
showFullData = !showFullData;
target.add(PolyStringEditorPanel.this);
}
};
showHideLanguagesButton.setOutputMarkupId(true);
showHideLanguagesButton.add(AttributeAppender.append("style", "cursor: pointer;"));
add(showHideLanguagesButton);

}

private String getDefaultPolyStringValue(){
return "";
}

private String getKeyValue(){
return "";
}

private List<PolyStringTranslationArgumentType> getTranslationArgumentList(){
if (getModel() == null || getModelObject() == null || getModelObject().getTranslation() == null ||
getModelObject().getTranslation().getArgument() == null){
return new ArrayList<>();
}
return getModelObject().getTranslation().getArgument();
}

}
Expand Up @@ -4378,4 +4378,8 @@ operation.com.evolveum.midpoint.web.page.admin.configuration.InternalsThreadsPan
InternalsCountersPanel.thresholds=Thresholds
PageInternals.title.thresholds.counters=Thresholds counters
InternalsCountersPanel.reset.confirm.message=Do you really want to remove counters for {0} ({1})
InternalsCountersPanel.threshold.reset.button=Reset
InternalsCountersPanel.threshold.reset.button=Reset
PolyStringEditorPanel.defaultLabel=default
PolyStringEditorPanel.keyLabel=key
PolyStringEditorPanel.showLanguages=Show languages
PolyStringEditorPanel.hideLanguages=Hide languages
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2010-2018 Evolveum
* Copyright (c) 2010-2019 Evolveum
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -30,6 +30,7 @@
import com.evolveum.prism.xml.ns._public.types_3.PolyStringType;

import java.io.Serializable;
import java.util.Map;
import java.util.regex.Pattern;

import javax.xml.namespace.QName;
Expand All @@ -53,10 +54,12 @@ public class PolyString implements Matchable<PolyString>, Recomputable, Structur
public static final ItemName F_ORIG = new ItemName(PrismConstants.NS_TYPES, "orig");
public static final ItemName F_NORM = new ItemName(PrismConstants.NS_TYPES, "norm");
public static final ItemName F_TRANSLATION = new ItemName(PrismConstants.NS_TYPES, "translation");
public static final ItemName F_LANG = new ItemName(PrismConstants.NS_TYPES, "lang");

private final String orig;
private String norm = null;
private PolyStringTranslationType translation;
private Map<String,String> lang;

public PolyString(String orig) {
super();
Expand All @@ -75,10 +78,24 @@ public PolyString(String orig, String norm) {
this.norm = norm;
}

// TODO: we may need a builder for this ... hopefully I do not expect that there will be
// any more properties in a near future

public PolyString(String orig, String norm, PolyStringTranslationType translation) {
this(orig, norm);
this.translation = translation;
}

public PolyString(String orig, String norm, Map<String,String> lang) {
this(orig, norm);
this.lang = lang;
}

public PolyString(String orig, String norm, PolyStringTranslationType translation, Map<String,String> lang) {
this(orig, norm);
this.translation = translation;
this.lang = lang;
}

public String getOrig() {
return orig;
Expand All @@ -92,6 +109,10 @@ public PolyStringTranslationType getTranslation() {
return translation;
}

public Map<String, String> getLang() {
return lang;
}

/**
* Do NOT rely on this method too much. It may disappear later, e.g. when we align PolyString and PolyString type and
* make PolyString really immutable.
Expand All @@ -100,6 +121,15 @@ public PolyStringTranslationType getTranslation() {
public void setTranslation(PolyStringTranslationType translation) {
this.translation = translation;
}

/**
* Do NOT rely on this method too much. It may disappear later, e.g. when we align PolyString and PolyString type and
* make PolyString really immutable.
*/
@Experimental
public void setLang(Map<String, String> lang) {
this.lang = lang;
}

public boolean isEmpty() {
if (orig == null) {
Expand Down Expand Up @@ -135,6 +165,8 @@ public Object resolve(ItemPath subpath) {
return norm;
} else if (QNameUtil.match(F_TRANSLATION, itemName)) {
return translation;
} else if (QNameUtil.match(F_LANG, itemName)) {
return lang;
} else {
throw new IllegalArgumentException("Unknown path segment "+itemName);
}
Expand Down Expand Up @@ -206,6 +238,7 @@ public boolean endsWith(String value) {
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((lang == null) ? 0 : lang.hashCode());
result = prime * result + ((norm == null) ? 0 : norm.hashCode());
result = prime * result + ((orig == null) ? 0 : orig.hashCode());
result = prime * result + ((translation == null) ? 0 : translation.hashCode());
Expand All @@ -214,28 +247,44 @@ public int hashCode() {

@Override
public boolean equals(Object obj) {
if (this == obj)
if (this == obj) {
return true;
if (obj == null)
}
if (obj == null) {
return false;
if (getClass() != obj.getClass())
}
if (getClass() != obj.getClass()) {
return false;
}
PolyString other = (PolyString) obj;
if (lang == null) {
if (other.lang != null) {
return false;
}
} else if (!lang.equals(other.lang)) {
return false;
}
if (norm == null) {
if (other.norm != null)
if (other.norm != null) {
return false;
} else if (!norm.equals(other.norm))
}
} else if (!norm.equals(other.norm)) {
return false;
}
if (orig == null) {
if (other.orig != null)
if (other.orig != null) {
return false;
} else if (!orig.equals(other.orig))
}
} else if (!orig.equals(other.orig)) {
return false;
}
if (translation == null) {
if (other.translation != null)
if (other.translation != null) {
return false;
} else if (!translation.equals(other.translation))
}
} else if (!translation.equals(other.translation)) {
return false;
}
return true;
}

Expand Down Expand Up @@ -275,6 +324,10 @@ public String debugDump(int indent) {
sb.append(";translation=");
sb.append(translation.getKey());
}
if (lang != null) {
sb.append(";lang=");
sb.append(lang);
}
sb.append(")");
return sb.toString();
}
Expand Down

0 comments on commit 366299c

Please sign in to comment.