You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openaz.apache.org by pd...@apache.org on 2016/03/17 02:06:46 UTC
[07/23] incubator-openaz git commit: Ported original att source to
openaz
http://git-wip-us.apache.org/repos/asf/incubator-openaz/blob/a1d93100/openaz-xacml-pap-admin/src/main/java/org/apache/openaz/xacml/admin/view/validators/RFC822NameValidator.java
----------------------------------------------------------------------
diff --git a/openaz-xacml-pap-admin/src/main/java/org/apache/openaz/xacml/admin/view/validators/RFC822NameValidator.java b/openaz-xacml-pap-admin/src/main/java/org/apache/openaz/xacml/admin/view/validators/RFC822NameValidator.java
new file mode 100644
index 0000000..4211cd7
--- /dev/null
+++ b/openaz-xacml-pap-admin/src/main/java/org/apache/openaz/xacml/admin/view/validators/RFC822NameValidator.java
@@ -0,0 +1,45 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 org.apache.openaz.xacml.admin.view.validators;
+
+import java.text.ParseException;
+
+import org.apache.openaz.xacml.std.datatypes.RFC822Name;
+import com.vaadin.data.Validator;
+
+public class RFC822NameValidator implements Validator {
+ private static final long serialVersionUID = 1L;
+
+ public RFC822NameValidator() {
+ }
+
+ @Override
+ public void validate(Object value) throws InvalidValueException {
+ if (value instanceof String) {
+ try {
+ RFC822Name.newInstance((String) value);
+ } catch (ParseException e) {
+ throw new InvalidValueException(e.getLocalizedMessage());
+ }
+ } else
+ throw new InvalidValueException("Unrecognized RFC822 Name");
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-openaz/blob/a1d93100/openaz-xacml-pap-admin/src/main/java/org/apache/openaz/xacml/admin/view/validators/StringValidator.java
----------------------------------------------------------------------
diff --git a/openaz-xacml-pap-admin/src/main/java/org/apache/openaz/xacml/admin/view/validators/StringValidator.java b/openaz-xacml-pap-admin/src/main/java/org/apache/openaz/xacml/admin/view/validators/StringValidator.java
new file mode 100644
index 0000000..7d03d38
--- /dev/null
+++ b/openaz-xacml-pap-admin/src/main/java/org/apache/openaz/xacml/admin/view/validators/StringValidator.java
@@ -0,0 +1,38 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 org.apache.openaz.xacml.admin.view.validators;
+
+import com.vaadin.data.Validator;
+
+public class StringValidator implements Validator {
+ private static final long serialVersionUID = 1L;
+
+ public StringValidator() {
+ // TODO Auto-generated constructor stub
+ }
+
+ @Override
+ public void validate(Object value) throws InvalidValueException {
+ // TODO Auto-generated method stub
+
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-openaz/blob/a1d93100/openaz-xacml-pap-admin/src/main/java/org/apache/openaz/xacml/admin/view/validators/TimeValidator.java
----------------------------------------------------------------------
diff --git a/openaz-xacml-pap-admin/src/main/java/org/apache/openaz/xacml/admin/view/validators/TimeValidator.java b/openaz-xacml-pap-admin/src/main/java/org/apache/openaz/xacml/admin/view/validators/TimeValidator.java
new file mode 100644
index 0000000..b93dafe
--- /dev/null
+++ b/openaz-xacml-pap-admin/src/main/java/org/apache/openaz/xacml/admin/view/validators/TimeValidator.java
@@ -0,0 +1,45 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 org.apache.openaz.xacml.admin.view.validators;
+
+import java.text.ParseException;
+
+import org.apache.openaz.xacml.std.datatypes.ISO8601Time;
+import com.vaadin.data.Validator;
+
+public class TimeValidator implements Validator {
+ private static final long serialVersionUID = 1L;
+
+ public TimeValidator() {
+ }
+
+ @Override
+ public void validate(Object value) throws InvalidValueException {
+ if (value instanceof String) {
+ try {
+ ISO8601Time.fromISO8601TimeString((String) value);
+ } catch (ParseException e) {
+ throw new InvalidValueException(e.getLocalizedMessage());
+ }
+ } else
+ throw new InvalidValueException("Unrecognized Time");
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-openaz/blob/a1d93100/openaz-xacml-pap-admin/src/main/java/org/apache/openaz/xacml/admin/view/validators/ValidatorFactory.java
----------------------------------------------------------------------
diff --git a/openaz-xacml-pap-admin/src/main/java/org/apache/openaz/xacml/admin/view/validators/ValidatorFactory.java b/openaz-xacml-pap-admin/src/main/java/org/apache/openaz/xacml/admin/view/validators/ValidatorFactory.java
new file mode 100644
index 0000000..354d662
--- /dev/null
+++ b/openaz-xacml-pap-admin/src/main/java/org/apache/openaz/xacml/admin/view/validators/ValidatorFactory.java
@@ -0,0 +1,71 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 org.apache.openaz.xacml.admin.view.validators;
+
+import org.apache.openaz.xacml.admin.jpa.Datatype;
+import org.apache.openaz.xacml.api.XACML3;
+import com.vaadin.data.Validator;
+
+public class ValidatorFactory {
+
+ public static Validator newInstance(Datatype datatype) {
+
+ if (datatype.getIdentifer().equals(XACML3.ID_DATATYPE_ANYURI)) {
+ return new AnyURIValidator();
+ } else if (datatype.getIdentifer().equals(XACML3.ID_DATATYPE_BASE64BINARY)) {
+ return new Base64BinaryValidator();
+ } else if (datatype.getIdentifer().equals(XACML3.ID_DATATYPE_BOOLEAN)) {
+ return new BooleanValidator();
+ } else if (datatype.getIdentifer().equals(XACML3.ID_DATATYPE_DATE)) {
+ return new DateValidator();
+ } else if (datatype.getIdentifer().equals(XACML3.ID_DATATYPE_DATETIME)) {
+ return new DateTimeValidator();
+ } else if (datatype.getIdentifer().equals(XACML3.ID_DATATYPE_DAYTIMEDURATION)) {
+ return new DayTimeDurationValidator();
+ } else if (datatype.getIdentifer().equals(XACML3.ID_DATATYPE_DNSNAME)) {
+ return new DNSNameValidator();
+ } else if (datatype.getIdentifer().equals(XACML3.ID_DATATYPE_DOUBLE)) {
+ return new DoubleValidator();
+ } else if (datatype.getIdentifer().equals(XACML3.ID_DATATYPE_HEXBINARY)) {
+ return new HexBinaryValidator();
+ } else if (datatype.getIdentifer().equals(XACML3.ID_DATATYPE_INTEGER)) {
+ return new IntegerValidator();
+ } else if (datatype.getIdentifer().equals(XACML3.ID_DATATYPE_IPADDRESS)) {
+ return new IpAddressValidator();
+ } else if (datatype.getIdentifer().equals(XACML3.ID_DATATYPE_RFC822NAME)) {
+ return new RFC822NameValidator();
+ } else if (datatype.getIdentifer().equals(XACML3.ID_DATATYPE_STRING)) {
+ return new StringValidator();
+ } else if (datatype.getIdentifer().equals(XACML3.ID_DATATYPE_TIME)) {
+ return new TimeValidator();
+ } else if (datatype.getIdentifer().equals(XACML3.ID_DATATYPE_X500NAME)) {
+ return new X500NameValidator();
+ /*
+ } else if (datatype.getIdentifer().equals(XACML3.ID_DATATYPE_XPATHEXPRESSION)) {
+
+ */
+ } else if (datatype.getIdentifer().equals(XACML3.ID_DATATYPE_YEARMONTHDURATION)) {
+ return new YearMonthDurationValidator();
+ }
+
+ return null;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-openaz/blob/a1d93100/openaz-xacml-pap-admin/src/main/java/org/apache/openaz/xacml/admin/view/validators/X500NameValidator.java
----------------------------------------------------------------------
diff --git a/openaz-xacml-pap-admin/src/main/java/org/apache/openaz/xacml/admin/view/validators/X500NameValidator.java b/openaz-xacml-pap-admin/src/main/java/org/apache/openaz/xacml/admin/view/validators/X500NameValidator.java
new file mode 100644
index 0000000..977a13d
--- /dev/null
+++ b/openaz-xacml-pap-admin/src/main/java/org/apache/openaz/xacml/admin/view/validators/X500NameValidator.java
@@ -0,0 +1,44 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 org.apache.openaz.xacml.admin.view.validators;
+
+import javax.security.auth.x500.X500Principal;
+
+import com.vaadin.data.Validator;
+
+public class X500NameValidator implements Validator {
+ private static final long serialVersionUID = 1L;
+
+ public X500NameValidator() {
+ }
+
+ @Override
+ public void validate(Object value) throws InvalidValueException {
+ if (value instanceof String) {
+ try {
+ new X500Principal((String) value);
+ } catch (IllegalArgumentException e) {
+ throw new InvalidValueException(e.getLocalizedMessage());
+ }
+ } else
+ throw new InvalidValueException("Unrecognized X500 Name");
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-openaz/blob/a1d93100/openaz-xacml-pap-admin/src/main/java/org/apache/openaz/xacml/admin/view/validators/YearMonthDurationValidator.java
----------------------------------------------------------------------
diff --git a/openaz-xacml-pap-admin/src/main/java/org/apache/openaz/xacml/admin/view/validators/YearMonthDurationValidator.java b/openaz-xacml-pap-admin/src/main/java/org/apache/openaz/xacml/admin/view/validators/YearMonthDurationValidator.java
new file mode 100644
index 0000000..8d53629
--- /dev/null
+++ b/openaz-xacml-pap-admin/src/main/java/org/apache/openaz/xacml/admin/view/validators/YearMonthDurationValidator.java
@@ -0,0 +1,45 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 org.apache.openaz.xacml.admin.view.validators;
+
+import java.text.ParseException;
+
+import org.apache.openaz.xacml.std.datatypes.XPathYearMonthDuration;
+import com.vaadin.data.Validator;
+
+public class YearMonthDurationValidator implements Validator {
+ private static final long serialVersionUID = 1L;
+
+ public YearMonthDurationValidator() {
+ }
+
+ @Override
+ public void validate(Object value) throws InvalidValueException {
+ if (value instanceof String) {
+ try {
+ XPathYearMonthDuration.newInstance((String) value);
+ } catch (ParseException e) {
+ throw new InvalidValueException(e.getLocalizedMessage());
+ }
+ } else
+ throw new InvalidValueException("Unrecognized YearMonthDuration");
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-openaz/blob/a1d93100/openaz-xacml-pap-admin/src/main/java/org/apache/openaz/xacml/admin/view/windows/AdviceEditorWindow.java
----------------------------------------------------------------------
diff --git a/openaz-xacml-pap-admin/src/main/java/org/apache/openaz/xacml/admin/view/windows/AdviceEditorWindow.java b/openaz-xacml-pap-admin/src/main/java/org/apache/openaz/xacml/admin/view/windows/AdviceEditorWindow.java
new file mode 100644
index 0000000..802eb43
--- /dev/null
+++ b/openaz-xacml-pap-admin/src/main/java/org/apache/openaz/xacml/admin/view/windows/AdviceEditorWindow.java
@@ -0,0 +1,208 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 org.apache.openaz.xacml.admin.view.windows;
+
+import oasis.names.tc.xacml._3_0.core.schema.wd_17.AdviceExpressionType;
+import oasis.names.tc.xacml._3_0.core.schema.wd_17.EffectType;
+
+import org.apache.openaz.xacml.admin.XacmlAdminUI;
+import com.vaadin.annotations.AutoGenerated;
+import com.vaadin.data.Buffered.SourceException;
+import com.vaadin.data.Validator.InvalidValueException;
+import com.vaadin.event.ShortcutAction.KeyCode;
+import com.vaadin.ui.Alignment;
+import com.vaadin.ui.Button;
+import com.vaadin.ui.Button.ClickEvent;
+import com.vaadin.ui.Button.ClickListener;
+import com.vaadin.ui.OptionGroup;
+import com.vaadin.ui.TextField;
+import com.vaadin.ui.VerticalLayout;
+import com.vaadin.ui.Window;
+
+public class AdviceEditorWindow extends Window {
+
+ /*- VaadinEditorProperties={"grid":"RegularGrid,20","showGrid":true,"snapToGrid":true,"snapToObject":true,"movingGuides":false,"snappingDistance":10} */
+
+ @AutoGenerated
+ private VerticalLayout mainLayout;
+ @AutoGenerated
+ private Button buttonSave;
+ @AutoGenerated
+ private OptionGroup optionGroupEffect;
+ @AutoGenerated
+ private TextField textFieldAdviceID;
+ /**
+ *
+ */
+ private static final long serialVersionUID = 1L;
+ private final AdviceEditorWindow self = this;
+ private final AdviceExpressionType advice;
+ private boolean isSaved = false;
+ /**
+ * The constructor should first build the main layout, set the
+ * composition root and then do any custom initialization.
+ *
+ * The constructor will not be automatically regenerated by the
+ * visual editor.
+ */
+ public AdviceEditorWindow(AdviceExpressionType advice) {
+ buildMainLayout();
+ //setCompositionRoot(mainLayout);
+ setContent(mainLayout);
+ //
+ // Save
+ //
+ this.advice = advice;
+ //
+ // Set our shortcuts
+ //
+ this.setCloseShortcut(KeyCode.ESCAPE);
+ //
+ // Initialize GUI
+ //
+ this.initialize();
+ this.initializeButton();
+ //
+ // Focus
+ //
+ this.textFieldAdviceID.focus();
+ }
+
+ protected void initialize() {
+ //
+ // The text field for the advice ID
+ //
+ this.textFieldAdviceID.setNullRepresentation("");
+ if (this.advice.getAdviceId() == null) {
+ this.textFieldAdviceID.setValue(XacmlAdminUI.getDomain());
+ } else {
+ this.textFieldAdviceID.setValue(advice.getAdviceId());
+ }
+ this.textFieldAdviceID.setRequiredError("You must have an ID for the advice");
+ //
+ // The option
+ //
+ this.optionGroupEffect.setRequiredError("You must select Permit or Deny for the advice");
+ this.optionGroupEffect.addItem(EffectType.PERMIT);
+ this.optionGroupEffect.addItem(EffectType.DENY);
+ if (this.advice.getAppliesTo() == null) {
+ this.optionGroupEffect.select(EffectType.PERMIT);
+ } else {
+ if (this.advice.getAppliesTo().equals(EffectType.PERMIT)) {
+ this.optionGroupEffect.select(EffectType.PERMIT);
+ } else {
+ this.optionGroupEffect.select(EffectType.DENY);
+ }
+ }
+ }
+
+ protected void initializeButton() {
+ this.buttonSave.setImmediate(true);
+ this.buttonSave.setClickShortcut(KeyCode.ENTER);
+ this.buttonSave.addClickListener(new ClickListener() {
+ private static final long serialVersionUID = 1L;
+
+ @Override
+ public void buttonClick(ClickEvent event) {
+ try {
+ //
+ // Commit
+ //
+ self.textFieldAdviceID.commit();
+ self.optionGroupEffect.commit();
+ //
+ // all good, save everything
+ //
+ self.advice.setAdviceId(self.textFieldAdviceID.getValue());
+ self.advice.setAppliesTo((EffectType) self.optionGroupEffect.getValue());
+ //
+ // Set ourselves as saved
+ //
+ self.isSaved = true;
+ //
+ // Close the window
+ //
+ self.close();
+ } catch (SourceException | InvalidValueException e) { //NOPMD
+ //
+ // Vaadin displays the error
+ //
+ }
+ }
+ });
+ }
+
+ public boolean isSaved() {
+ return this.isSaved;
+ }
+
+ public AdviceExpressionType getAdvice() {
+ return this.advice;
+ }
+
+ @AutoGenerated
+ private VerticalLayout buildMainLayout() {
+ // common part: create layout
+ mainLayout = new VerticalLayout();
+ mainLayout.setImmediate(false);
+ mainLayout.setWidth("-1px");
+ mainLayout.setHeight("-1px");
+ mainLayout.setMargin(true);
+ mainLayout.setSpacing(true);
+
+ // top-level component properties
+ setWidth("-1px");
+ setHeight("-1px");
+
+ // textFieldAdviceID
+ textFieldAdviceID = new TextField();
+ textFieldAdviceID.setCaption("Advice ID");
+ textFieldAdviceID.setImmediate(false);
+ textFieldAdviceID.setWidth("-1px");
+ textFieldAdviceID.setHeight("-1px");
+ textFieldAdviceID.setInvalidAllowed(false);
+ textFieldAdviceID.setRequired(true);
+ textFieldAdviceID.setInputPrompt("Eg. urn:com:foo:advice:sample");
+ mainLayout.addComponent(textFieldAdviceID);
+
+ // optionGroupEffect
+ optionGroupEffect = new OptionGroup();
+ optionGroupEffect.setCaption("Applies To");
+ optionGroupEffect.setImmediate(false);
+ optionGroupEffect.setWidth("-1px");
+ optionGroupEffect.setHeight("-1px");
+ optionGroupEffect.setInvalidAllowed(false);
+ optionGroupEffect.setRequired(true);
+ mainLayout.addComponent(optionGroupEffect);
+
+ // buttonSave
+ buttonSave = new Button();
+ buttonSave.setCaption("Save");
+ buttonSave.setImmediate(true);
+ buttonSave.setWidth("-1px");
+ buttonSave.setHeight("-1px");
+ mainLayout.addComponent(buttonSave);
+ mainLayout.setComponentAlignment(buttonSave, new Alignment(48));
+
+ return mainLayout;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-openaz/blob/a1d93100/openaz-xacml-pap-admin/src/main/java/org/apache/openaz/xacml/admin/view/windows/ApplyEditorWindow.java
----------------------------------------------------------------------
diff --git a/openaz-xacml-pap-admin/src/main/java/org/apache/openaz/xacml/admin/view/windows/ApplyEditorWindow.java b/openaz-xacml-pap-admin/src/main/java/org/apache/openaz/xacml/admin/view/windows/ApplyEditorWindow.java
new file mode 100644
index 0000000..e8496e5
--- /dev/null
+++ b/openaz-xacml-pap-admin/src/main/java/org/apache/openaz/xacml/admin/view/windows/ApplyEditorWindow.java
@@ -0,0 +1,600 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 org.apache.openaz.xacml.admin.view.windows;
+
+import java.util.List;
+import java.util.Map;
+
+import oasis.names.tc.xacml._3_0.core.schema.wd_17.ApplyType;
+import oasis.names.tc.xacml._3_0.core.schema.wd_17.ConditionType;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import org.apache.openaz.xacml.admin.XacmlAdminUI;
+import org.apache.openaz.xacml.admin.jpa.Datatype;
+import org.apache.openaz.xacml.admin.jpa.FunctionArgument;
+import org.apache.openaz.xacml.admin.jpa.FunctionDefinition;
+import org.apache.openaz.xacml.admin.util.JPAUtils;
+import org.apache.openaz.xacml.admin.view.events.ApplyParametersChangedListener;
+import org.apache.openaz.xacml.admin.view.events.ApplyParametersChangedNotifier;
+import org.apache.openaz.xacml.api.XACML3;
+import com.vaadin.annotations.AutoGenerated;
+import com.vaadin.data.Buffered.SourceException;
+import com.vaadin.data.Container;
+import com.vaadin.data.Container.Filter;
+import com.vaadin.data.Item;
+import com.vaadin.data.Property.ValueChangeEvent;
+import com.vaadin.data.Property.ValueChangeListener;
+import com.vaadin.data.Validator.InvalidValueException;
+import com.vaadin.data.util.BeanItemContainer;
+import com.vaadin.data.util.filter.Compare;
+import com.vaadin.data.util.filter.SimpleStringFilter;
+import com.vaadin.event.FieldEvents.TextChangeEvent;
+import com.vaadin.event.FieldEvents.TextChangeListener;
+import com.vaadin.event.ItemClickEvent;
+import com.vaadin.event.ItemClickEvent.ItemClickListener;
+import com.vaadin.event.ShortcutAction.KeyCode;
+import com.vaadin.ui.AbstractSelect.ItemCaptionMode;
+import com.vaadin.ui.Alignment;
+import com.vaadin.ui.Button;
+import com.vaadin.ui.Button.ClickEvent;
+import com.vaadin.ui.Button.ClickListener;
+import com.vaadin.ui.CheckBox;
+import com.vaadin.ui.ComboBox;
+import com.vaadin.ui.HorizontalLayout;
+import com.vaadin.ui.Table;
+import com.vaadin.ui.TextArea;
+import com.vaadin.ui.TextField;
+import com.vaadin.ui.UI;
+import com.vaadin.ui.VerticalLayout;
+import com.vaadin.ui.Window;
+
+public class ApplyEditorWindow extends Window implements ApplyParametersChangedNotifier {
+
+ /*- VaadinEditorProperties={"grid":"RegularGrid,20","showGrid":true,"snapToGrid":true,"snapToObject":true,"movingGuides":false,"snappingDistance":10} */
+
+ @AutoGenerated
+ private VerticalLayout mainLayout;
+ @AutoGenerated
+ private Button buttonSelect;
+ @AutoGenerated
+ private Table tableFunction;
+ @AutoGenerated
+ private HorizontalLayout horizontalLayout_1;
+ @AutoGenerated
+ private CheckBox checkBoxFilterIsBag;
+ @AutoGenerated
+ private ComboBox comboBoxDatatypeFilter;
+ @AutoGenerated
+ private TextField textFieldFilter;
+ @AutoGenerated
+ private TextArea textAreaDescription;
+ /**
+ *
+ */
+ private static final long serialVersionUID = 1L;
+ private static Log logger = LogFactory.getLog(ApplyEditorWindow.class);
+ private final ApplyEditorWindow self = this;
+ private final ApplyParametersChangedNotifier notifier = new ApplyParametersChangedNotifier.BasicNotifier();
+ private final BeanItemContainer<FunctionDefinition> container = new BeanItemContainer<FunctionDefinition>(FunctionDefinition.class);
+ private final ApplyType apply;
+ private final ApplyType applyParent;
+ private final FunctionArgument argument;
+ private final Object parent;
+ private boolean isSaved = false;
+ private FunctionDefinition function = null;
+ /**
+ * The constructor should first build the main layout, set the
+ * composition root and then do any custom initialization.
+ *
+ * The constructor will not be automatically regenerated by the
+ * visual editor.
+ * @param parent
+ * @param parentApply
+ */
+ public ApplyEditorWindow(ApplyType apply, ApplyType parentApply, FunctionArgument argument, Object parent) {
+ buildMainLayout();
+ //setCompositionRoot(mainLayout);
+ setContent(mainLayout);
+ //
+ // Save
+ //
+ this.apply = apply;
+ this.applyParent = parentApply;
+ this.argument = argument;
+ this.parent = parent;
+ logger.info(this.apply + " " + this.applyParent + " " + this.argument + " " + this.parent);
+ //
+ // Set our shortcuts
+ //
+ this.setCloseShortcut(KeyCode.ESCAPE);
+ //
+ // Initialize
+ //
+ this.textAreaDescription.setValue(apply.getDescription());
+ this.textAreaDescription.setNullRepresentation("");
+ this.initializeButton();
+ this.initializeTable();
+ this.initializeFilters();
+ //
+ // focus
+ //
+ this.textFieldFilter.focus();
+ }
+
+ protected void initializeTable() {
+ //
+ // Setup GUI properties
+ //
+ this.tableFunction.setImmediate(true);
+ this.tableFunction.setSelectable(true);
+ this.tableFunction.setNullSelectionAllowed(false);
+ this.tableFunction.setRequired(true);
+ this.tableFunction.setRequiredError("You MUST select a function for the Apply");
+ //
+ // Set its data source
+ //
+ this.tableFunction.setContainerDataSource(this.container);
+ this.tableFunction.setVisibleColumns(new Object[] {"xacmlid", "shortname", "datatypeBean", "isBagReturn"});
+ this.tableFunction.setColumnHeaders(new String[] {"Function Xacml ID", "ID", "Return Data Type", "Return Bag?"});
+ //
+ // Determine appropriate filters
+ //
+ Datatype datatypeId = null;
+ if (this.applyParent == null) {
+ if (this.parent instanceof ConditionType) {
+ //
+ // Only boolean functions allowed
+ //
+ datatypeId = JPAUtils.findDatatype(XACML3.ID_DATATYPE_BOOLEAN);
+ }
+ } else {
+ String parentFunction = this.applyParent.getFunctionId();
+ this.function = JPAUtils.findFunction(parentFunction);
+ if (this.function == null) {
+ throw new IllegalArgumentException("applyParent's function is not found:" + parentFunction);
+ }
+ if (this.argument == null) {
+ throw new IllegalArgumentException("Need to know what argument apply is ");
+ }
+ datatypeId = this.argument.getDatatypeBean();
+ }
+ Map<Datatype, List<FunctionDefinition>> functionMap = JPAUtils.getFunctionDatatypeMap();
+ if (datatypeId == null) {
+ //
+ // All functions are available
+ //
+ for (Datatype id : functionMap.keySet()) {
+ this.addTableEntries(functionMap.get(id));
+ }
+ } else {
+ for (Datatype id : functionMap.keySet()) {
+ if (id == null) {
+ if (datatypeId == null) {
+ this.addTableEntries(functionMap.get(id));
+ break;
+ }
+ continue;
+ }
+ if (id.getId() == datatypeId.getId()) {
+ this.addTableEntries(functionMap.get(id));
+ break;
+ }
+ }
+ }
+ //
+ // Setup double-click
+ //
+ this.tableFunction.addItemClickListener(new ItemClickListener() {
+ private static final long serialVersionUID = 1L;
+
+ @Override
+ public void itemClick(ItemClickEvent event) {
+ if (event.isDoubleClick()) {
+ self.selected();
+ }
+ }
+ });
+ //
+ // Value change listener
+ //
+ this.tableFunction.addValueChangeListener(new ValueChangeListener() {
+ private static final long serialVersionUID = 1L;
+
+ @Override
+ public void valueChange(ValueChangeEvent event) {
+ logger.info("valueChange " + self.tableFunction.getValue());
+ if (self.tableFunction.getValue() != null) {
+ self.buttonSelect.setEnabled(true);
+ } else {
+ self.buttonSelect.setEnabled(false);
+ }
+ }
+ });
+ //
+ // Select current value if possible
+ //
+ if (this.apply != null && this.apply.getFunctionId() != null && this.apply.getFunctionId().isEmpty() == false) {
+ FunctionDefinition current = JPAUtils.findFunction(this.apply.getFunctionId());
+ if (current != null) {
+ this.tableFunction.select(current);
+ this.tableFunction.setCurrentPageFirstItemId(current);
+ } else {
+ logger.warn("Could not find function in table for " + this.apply.getFunctionId());
+ }
+ } else {
+ this.buttonSelect.setEnabled(false);
+ }
+ }
+
+ protected void addTableEntries(List<FunctionDefinition> functions) {
+ if (functions == null) {
+ logger.warn("NULL list of functions, cannot add to table.");
+ return;
+ }
+ for (FunctionDefinition function : functions) {
+ //
+ // Just check if this function is available for this
+ // apply.
+ //
+// if (XACMLFunctionValidator.isFunctionAvailable(function, this.apply, this.argument)) {
+ this.container.addBean(function);
+// } else {
+// if (logger.isDebugEnabled()) {
+// logger.debug("Function not available: " + function);
+// }
+// }
+ }
+ }
+
+ protected void initializeButton() {
+ this.buttonSelect.addClickListener(new ClickListener() {
+ private static final long serialVersionUID = 1L;
+
+ @Override
+ public void buttonClick(ClickEvent event) {
+ self.selected();
+ }
+ });
+ }
+
+ protected void initializeFilters() {
+ this.textFieldFilter.setImmediate(true);
+ this.textFieldFilter.addTextChangeListener(new TextChangeListener() {
+ private static final long serialVersionUID = 1L;
+ SimpleStringFilter currentFilter = null;
+
+ @Override
+ public void textChange(TextChangeEvent event) {
+ //
+ // Remove current filter
+ //
+ if (this.currentFilter != null) {
+ self.container.removeContainerFilter(this.currentFilter);
+ this.currentFilter = null;
+ }
+ //
+ // Get the text
+ //
+ String value = event.getText();
+ if (value != null && value.length() > 0) {
+ //
+ // Add the new filter
+ //
+ this.currentFilter = new SimpleStringFilter("shortname", value, true, false);
+ self.container.addContainerFilter(this.currentFilter);
+ }
+ }
+ });
+
+ this.comboBoxDatatypeFilter.setContainerDataSource(((XacmlAdminUI) UI.getCurrent()).getDatatypes());
+ this.comboBoxDatatypeFilter.setImmediate(true);
+ this.comboBoxDatatypeFilter.setItemCaptionMode(ItemCaptionMode.PROPERTY);
+ this.comboBoxDatatypeFilter.setItemCaptionPropertyId("xacmlId");
+ this.comboBoxDatatypeFilter.setNullSelectionAllowed(true);
+ this.comboBoxDatatypeFilter.addValueChangeListener(new ValueChangeListener() {
+ private static final long serialVersionUID = 1L;
+ Container.Filter currentFilter = null;
+
+ @Override
+ public void valueChange(ValueChangeEvent event) {
+ //
+ // Remove current filter
+ //
+ if (this.currentFilter != null) {
+ self.container.removeContainerFilter(this.currentFilter);
+ this.currentFilter = null;
+ }
+ //
+ // Get the current selection
+ //
+ Object id = self.comboBoxDatatypeFilter.getValue();
+ if (id == null) {
+ return;
+ }
+ //
+ // Setup the filter
+ //
+ final Datatype datatype = ((XacmlAdminUI) UI.getCurrent()).getDatatypes().getItem(id).getEntity();
+ this.currentFilter = new Container.Filter() {
+ private static final long serialVersionUID = 1L;
+
+ @Override
+ public boolean passesFilter(Object itemId, Item item) throws UnsupportedOperationException {
+ if (itemId instanceof FunctionDefinition) {
+ Datatype dt = ((FunctionDefinition) itemId).getDatatypeBean();
+ if (dt == null) {
+ return false;
+ }
+ return dt.getXacmlId().equals(datatype.getXacmlId());
+ }
+ return false;
+ }
+
+ @Override
+ public boolean appliesToProperty(Object propertyId) {
+ if (propertyId != null && propertyId.toString().equals("datatypeBean")) {
+ return true;
+ }
+ return false;
+ }
+ };
+ self.container.addContainerFilter(this.currentFilter);
+ }
+ });
+
+ this.checkBoxFilterIsBag.setImmediate(true);
+ this.checkBoxFilterIsBag.addValueChangeListener(new ValueChangeListener() {
+ private static final long serialVersionUID = 1L;
+ Filter currentFilter = null;
+
+ @Override
+ public void valueChange(ValueChangeEvent event) {
+ //
+ // Remove current filter
+ //
+ if (this.currentFilter != null) {
+ self.container.removeContainerFilter(this.currentFilter);
+ this.currentFilter = null;
+ }
+ //
+ // Is it checked?
+ //
+ if (self.checkBoxFilterIsBag.getValue() == false) {
+ //
+ // Nope, get out of here
+ //
+ return;
+ }
+ //
+ // Add the filter
+ //
+ this.currentFilter = new Compare.Equal("isBagReturn", true);
+ self.container.addContainerFilter(this.currentFilter);
+ }
+ });
+ }
+
+ protected void selected() {
+ //
+ // Is there a selected function?
+ //
+ try {
+ //
+ // Run the commit
+ //
+ this.textAreaDescription.commit();
+ this.tableFunction.commit();
+ //
+ // Commit worked, get the selected function
+ //
+ Object id = this.tableFunction.getValue();
+ //
+ // Sanity check, it *should* never be null
+ // unless someone changed the initialization code.
+ //
+ if (id == null || ! (id instanceof FunctionDefinition)) {
+ throw new InvalidValueException(this.tableFunction.getRequiredError());
+ }
+ //
+ // Get the actual function and save it into the apply
+ //
+ this.function = (FunctionDefinition) id;
+ this.apply.setDescription(this.textAreaDescription.getValue());
+ this.apply.setFunctionId(function.getXacmlid());
+ } catch (SourceException | InvalidValueException e) {
+ //
+ // Vaadin GUI will display message
+ //
+ return;
+ }
+ /**
+ //
+ // Make sure the arguments are good
+ //
+ final ApplyType copyApply = XACMLObjectCopy.copy(this.apply);
+ final ApplyArgumentsEditorWindow window = new ApplyArgumentsEditorWindow(copyApply, this.function);
+ window.setCaption("Define Arguments for " + this.function.getShortname());
+ window.setModal(true);
+ window.addCloseListener(new CloseListener() {
+ private static final long serialVersionUID = 1L;
+
+ @Override
+ public void windowClose(CloseEvent e) {
+ //
+ // Did the user click save?
+ //
+ if (window.isSaved() == false) {
+ return;
+ }
+ //
+ // Save our arguments
+ //
+ self.apply.getExpression().clear();
+ self.apply.getExpression().addAll(copyApply.getExpression());
+ //
+ // We are saved
+ //
+ self.isSaved = true;
+ //
+ // Fire
+ //
+ self.fireEvent(self.apply, self.applyParent, self.argument, self.parent);
+ //
+ // Close the apply editor window
+ //
+ self.close();
+ }
+ });
+ window.center();
+ UI.getCurrent().addWindow(window);
+ **/
+ //
+ // We are saved
+ //
+ self.isSaved = true;
+ //
+ // Fire
+ //
+ self.fireEvent(self.apply, self.applyParent, self.argument, self.parent);
+ //
+ // Close the apply editor window
+ //
+ self.close();
+ }
+
+ @Override
+ public boolean addListener(ApplyParametersChangedListener listener) {
+ return this.notifier.addListener(listener);
+ }
+
+ @Override
+ public boolean removeListener(ApplyParametersChangedListener listener) {
+ return this.notifier.removeListener(listener);
+ }
+
+ @Override
+ public void fireEvent(ApplyType apply, ApplyType parent, FunctionArgument argument, Object container) {
+ this.notifier.fireEvent(apply, parent, argument, container);
+ }
+
+ public boolean isSaved() {
+ return this.isSaved;
+ }
+
+ public FunctionDefinition getSelectedFunction() {
+ return this.function;
+ }
+
+ @AutoGenerated
+ private VerticalLayout buildMainLayout() {
+ // common part: create layout
+ mainLayout = new VerticalLayout();
+ mainLayout.setImmediate(false);
+ mainLayout.setWidth("-1px");
+ mainLayout.setHeight("-1px");
+ mainLayout.setMargin(true);
+ mainLayout.setSpacing(true);
+
+ // top-level component properties
+ setWidth("-1px");
+ setHeight("-1px");
+
+ // horizontalLayout_1
+ horizontalLayout_1 = buildHorizontalLayout_1();
+ mainLayout.addComponent(horizontalLayout_1);
+
+ // tableFunction
+ tableFunction = new Table();
+ tableFunction.setCaption("Select A Function");
+ tableFunction.setImmediate(false);
+ tableFunction.setWidth("100.0%");
+ tableFunction.setHeight("-1px");
+ tableFunction.setInvalidAllowed(false);
+ tableFunction.setRequired(true);
+ mainLayout.addComponent(tableFunction);
+ mainLayout.setExpandRatio(tableFunction, 1.0f);
+
+ // buttonSelect
+ buttonSelect = new Button();
+ buttonSelect.setCaption("Select and Continue");
+ buttonSelect.setImmediate(true);
+ buttonSelect.setWidth("-1px");
+ buttonSelect.setHeight("-1px");
+ mainLayout.addComponent(buttonSelect);
+ mainLayout.setComponentAlignment(buttonSelect, new Alignment(48));
+
+ return mainLayout;
+ }
+
+ @AutoGenerated
+ private HorizontalLayout buildHorizontalLayout_1() {
+ // common part: create layout
+ horizontalLayout_1 = new HorizontalLayout();
+ horizontalLayout_1.setImmediate(false);
+ horizontalLayout_1.setWidth("-1px");
+ horizontalLayout_1.setHeight("-1px");
+ horizontalLayout_1.setMargin(false);
+ horizontalLayout_1.setSpacing(true);
+
+ // textAreaDescription
+ textAreaDescription = new TextArea();
+ textAreaDescription.setCaption("Enter A Description");
+ textAreaDescription.setImmediate(false);
+ textAreaDescription.setWidth("50.0%");
+ textAreaDescription.setHeight("-1px");
+ horizontalLayout_1.addComponent(textAreaDescription);
+
+ // textFieldFilter
+ textFieldFilter = new TextField();
+ textFieldFilter.setCaption("Filter Function By ID");
+ textFieldFilter.setImmediate(false);
+ textFieldFilter.setWidth("-1px");
+ textFieldFilter.setHeight("-1px");
+ horizontalLayout_1.addComponent(textFieldFilter);
+ horizontalLayout_1.setComponentAlignment(textFieldFilter,
+ new Alignment(9));
+
+ // comboBoxDatatypeFilter
+ comboBoxDatatypeFilter = new ComboBox();
+ comboBoxDatatypeFilter.setCaption("Filter By Data Type");
+ comboBoxDatatypeFilter.setImmediate(false);
+ comboBoxDatatypeFilter.setWidth("-1px");
+ comboBoxDatatypeFilter.setHeight("-1px");
+ horizontalLayout_1.addComponent(comboBoxDatatypeFilter);
+ horizontalLayout_1.setComponentAlignment(comboBoxDatatypeFilter,
+ new Alignment(9));
+
+ // checkBoxFilterIsBag
+ checkBoxFilterIsBag = new CheckBox();
+ checkBoxFilterIsBag.setCaption("Is Bag Filter");
+ checkBoxFilterIsBag.setImmediate(false);
+ checkBoxFilterIsBag.setWidth("-1px");
+ checkBoxFilterIsBag.setHeight("-1px");
+ horizontalLayout_1.addComponent(checkBoxFilterIsBag);
+ horizontalLayout_1.setComponentAlignment(checkBoxFilterIsBag,
+ new Alignment(9));
+
+ return horizontalLayout_1;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-openaz/blob/a1d93100/openaz-xacml-pap-admin/src/main/java/org/apache/openaz/xacml/admin/view/windows/AttributeAssignmentExpressionEditorWindow.java
----------------------------------------------------------------------
diff --git a/openaz-xacml-pap-admin/src/main/java/org/apache/openaz/xacml/admin/view/windows/AttributeAssignmentExpressionEditorWindow.java b/openaz-xacml-pap-admin/src/main/java/org/apache/openaz/xacml/admin/view/windows/AttributeAssignmentExpressionEditorWindow.java
new file mode 100644
index 0000000..a9306fa
--- /dev/null
+++ b/openaz-xacml-pap-admin/src/main/java/org/apache/openaz/xacml/admin/view/windows/AttributeAssignmentExpressionEditorWindow.java
@@ -0,0 +1,228 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 org.apache.openaz.xacml.admin.view.windows;
+
+import oasis.names.tc.xacml._3_0.core.schema.wd_17.AttributeAssignmentExpressionType;
+
+import org.apache.openaz.xacml.admin.XacmlAdminUI;
+import org.apache.openaz.xacml.admin.jpa.Category;
+import com.vaadin.addon.jpacontainer.EntityItem;
+import com.vaadin.annotations.AutoGenerated;
+import com.vaadin.data.Buffered.SourceException;
+import com.vaadin.event.ShortcutAction.KeyCode;
+import com.vaadin.ui.Alignment;
+import com.vaadin.ui.Button;
+import com.vaadin.ui.Button.ClickEvent;
+import com.vaadin.ui.Button.ClickListener;
+import com.vaadin.ui.Table;
+import com.vaadin.ui.TextField;
+import com.vaadin.ui.UI;
+import com.vaadin.ui.VerticalLayout;
+import com.vaadin.ui.Window;
+
+public class AttributeAssignmentExpressionEditorWindow extends Window {
+
+ /*- VaadinEditorProperties={"grid":"RegularGrid,20","showGrid":true,"snapToGrid":true,"snapToObject":true,"movingGuides":false,"snappingDistance":10} */
+
+ @AutoGenerated
+ private VerticalLayout mainLayout;
+ @AutoGenerated
+ private Button buttonSave;
+ @AutoGenerated
+ private Table tableCategories;
+ @AutoGenerated
+ private TextField textFieldIssuer;
+ @AutoGenerated
+ private TextField textFieldAttributeID;
+ /**
+ *
+ */
+ private static final long serialVersionUID = 1L;
+ private final AttributeAssignmentExpressionEditorWindow self = this;
+ private final AttributeAssignmentExpressionType assignment;
+ private boolean isSaved = false;
+ /**
+ * The constructor should first build the main layout, set the
+ * composition root and then do any custom initialization.
+ *
+ * The constructor will not be automatically regenerated by the
+ * visual editor.
+ */
+ public AttributeAssignmentExpressionEditorWindow(AttributeAssignmentExpressionType assignment) {
+ buildMainLayout();
+ //setCompositionRoot(mainLayout);
+ setContent(mainLayout);
+ //
+ // Save
+ //
+ this.assignment = assignment;
+ //
+ // Set our shortcuts
+ //
+ this.setCloseShortcut(KeyCode.ESCAPE);
+ //
+ // Initialize GUI
+ //
+ this.initializeText();
+ this.initializeTable();
+ this.initializeButton();
+ //
+ // Focus
+ //
+ this.textFieldAttributeID.focus();
+ }
+
+ protected void initializeText() {
+ //
+ //
+ //
+ this.textFieldAttributeID.setNullRepresentation("");
+ if (this.assignment.getAttributeId() == null) {
+ this.textFieldAttributeID.setValue(XacmlAdminUI.getDomain());
+ } else {
+ this.textFieldAttributeID.setValue(this.assignment.getAttributeId());
+ }
+ this.textFieldAttributeID.setRequiredError("You must have an attribute id for the assignment expression.");
+ //
+ //
+ //
+ this.textFieldIssuer.setNullRepresentation("");
+ this.textFieldIssuer.setValue(this.assignment.getIssuer());
+ }
+
+ protected void initializeTable() {
+ this.tableCategories.setContainerDataSource(((XacmlAdminUI) UI.getCurrent()).getCategories());
+ this.tableCategories.setVisibleColumns(new Object[] {"xacmlId"});
+ this.tableCategories.setColumnHeaders(new String[] {"XACML ID"});
+ this.tableCategories.setSelectable(true);
+ this.tableCategories.setNullSelectionAllowed(true);
+ this.tableCategories.setPageLength(((XacmlAdminUI) UI.getCurrent()).getCategories().size());
+ }
+
+ protected void initializeButton() {
+ this.buttonSave.setClickShortcut(KeyCode.ENTER);
+ this.buttonSave.addClickListener(new ClickListener() {
+ private static final long serialVersionUID = 1L;
+
+ @Override
+ public void buttonClick(ClickEvent event) {
+ try {
+ //
+ // Commit
+ //
+ self.textFieldAttributeID.commit();
+ self.textFieldIssuer.commit();
+ self.tableCategories.commit();
+ //
+ // Save
+ //
+ self.assignment.setAttributeId(self.textFieldAttributeID.getValue());
+ self.assignment.setIssuer(self.textFieldIssuer.getValue());
+ Object cat = self.tableCategories.getValue();
+ if (cat != null) {
+ EntityItem<Category> entity = ((XacmlAdminUI) UI.getCurrent()).getCategories().getItem(cat);
+ if (entity != null && entity.getEntity() != null) {
+ self.assignment.setCategory(entity.getEntity().getXacmlId());
+ } else {
+ self.assignment.setCategory(null);
+ }
+ } else {
+ self.assignment.setCategory(null);
+ }
+ //
+ // Set ourselves as saved
+ //
+ self.isSaved = true;
+ //
+ // close window
+ //
+ self.close();
+ } catch (SourceException e) { //NOPMD
+ //
+ // Vaadin displays error GUI
+ //
+ }
+ }
+ });
+ }
+
+ public boolean isSaved() {
+ return this.isSaved;
+ }
+
+ public AttributeAssignmentExpressionType getAssignment () {
+ return this.assignment;
+ }
+
+ @AutoGenerated
+ private VerticalLayout buildMainLayout() {
+ // common part: create layout
+ mainLayout = new VerticalLayout();
+ mainLayout.setImmediate(false);
+ mainLayout.setWidth("-1px");
+ mainLayout.setHeight("-1px");
+ mainLayout.setMargin(true);
+ mainLayout.setSpacing(true);
+
+ // top-level component properties
+ setWidth("-1px");
+ setHeight("-1px");
+
+ // textFieldAttributeID
+ textFieldAttributeID = new TextField();
+ textFieldAttributeID.setCaption("Attribute Assignment ID");
+ textFieldAttributeID.setImmediate(false);
+ textFieldAttributeID.setWidth("-1px");
+ textFieldAttributeID.setHeight("-1px");
+ textFieldAttributeID.setInvalidAllowed(false);
+ textFieldAttributeID.setRequired(true);
+ mainLayout.addComponent(textFieldAttributeID);
+
+ // textFieldIssuer
+ textFieldIssuer = new TextField();
+ textFieldIssuer.setCaption("Issuer (Optional)");
+ textFieldIssuer.setImmediate(false);
+ textFieldIssuer.setWidth("-1px");
+ textFieldIssuer.setHeight("-1px");
+ textFieldIssuer.setNullSettingAllowed(true);
+ mainLayout.addComponent(textFieldIssuer);
+
+ // tableCategories
+ tableCategories = new Table();
+ tableCategories.setCaption("Category (Optional)");
+ tableCategories.setImmediate(false);
+ tableCategories.setWidth("100.0%");
+ tableCategories.setHeight("-1px");
+ mainLayout.addComponent(tableCategories);
+
+ // buttonSave
+ buttonSave = new Button();
+ buttonSave.setCaption("Save");
+ buttonSave.setImmediate(false);
+ buttonSave.setWidth("-1px");
+ buttonSave.setHeight("-1px");
+ mainLayout.addComponent(buttonSave);
+ mainLayout.setComponentAlignment(buttonSave, new Alignment(48));
+
+ return mainLayout;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-openaz/blob/a1d93100/openaz-xacml-pap-admin/src/main/java/org/apache/openaz/xacml/admin/view/windows/AttributeEditorWindow.java
----------------------------------------------------------------------
diff --git a/openaz-xacml-pap-admin/src/main/java/org/apache/openaz/xacml/admin/view/windows/AttributeEditorWindow.java b/openaz-xacml-pap-admin/src/main/java/org/apache/openaz/xacml/admin/view/windows/AttributeEditorWindow.java
new file mode 100644
index 0000000..62e9c1a
--- /dev/null
+++ b/openaz-xacml-pap-admin/src/main/java/org/apache/openaz/xacml/admin/view/windows/AttributeEditorWindow.java
@@ -0,0 +1,336 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 org.apache.openaz.xacml.admin.view.windows;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import org.apache.openaz.xacml.admin.XacmlAdminUI;
+import org.apache.openaz.xacml.admin.jpa.Attribute;
+import org.apache.openaz.xacml.admin.jpa.ConstraintType;
+import org.apache.openaz.xacml.admin.jpa.Datatype;
+import org.apache.openaz.xacml.admin.view.fields.ConstraintField;
+import org.apache.openaz.xacml.admin.view.fields.DesignatorSelectorField;
+import org.apache.openaz.xacml.api.Identifier;
+import org.apache.openaz.xacml.api.XACML3;
+import com.vaadin.addon.jpacontainer.EntityItem;
+import com.vaadin.addon.jpacontainer.fieldfactory.SingleSelectConverter;
+import com.vaadin.data.Property.ValueChangeEvent;
+import com.vaadin.data.Property.ValueChangeListener;
+import com.vaadin.data.fieldgroup.FieldGroup;
+import com.vaadin.data.fieldgroup.FieldGroup.CommitException;
+import com.vaadin.data.fieldgroup.PropertyId;
+import com.vaadin.data.util.filter.Compare;
+import com.vaadin.data.util.filter.Not;
+import com.vaadin.event.ShortcutAction.KeyCode;
+import com.vaadin.shared.ui.combobox.FilteringMode;
+import com.vaadin.ui.AbstractSelect.ItemCaptionMode;
+import com.vaadin.ui.Alignment;
+import com.vaadin.ui.Button;
+import com.vaadin.ui.Button.ClickEvent;
+import com.vaadin.ui.Button.ClickListener;
+import com.vaadin.ui.ComboBox;
+import com.vaadin.ui.FormLayout;
+import com.vaadin.ui.TextArea;
+import com.vaadin.ui.TextField;
+import com.vaadin.ui.UI;
+import com.vaadin.ui.Window;
+
+public class AttributeEditorWindow extends Window {
+ private static final long serialVersionUID = 1L;
+ private static final Log logger = LogFactory.getLog(AttributeEditorWindow.class);
+ private AttributeEditorWindow self = this;
+
+ private boolean isSaved = false;
+ private Attribute attribute;
+
+ private FormLayout mainLayout = new FormLayout();
+
+ @PropertyId("isDesignator")
+ DesignatorSelectorField selectDesignator;
+
+ @PropertyId("selectorPath")
+ TextField selectorPath = new TextField("Attribute Selector Path");
+
+ @PropertyId("xacmlId")
+ TextField xacmlID = new TextField("XACML ID");
+
+ @PropertyId("categoryBean")
+ ComboBox category = new ComboBox("Category");
+
+ @PropertyId("description")
+ TextArea descriptionField = new TextArea("Description");
+
+ @PropertyId("datatypeBean")
+ ComboBox datatype = new ComboBox("DataType");
+
+ @PropertyId("constraintType")
+ ComboBox constraintTypes = new ComboBox("Constraint Type");
+
+ @PropertyId("constraintValues")
+ ConstraintField constraintValues;
+
+ Button saveButton = new Button("Save");
+
+ FieldGroup fieldGroup = null;
+
+ /**
+ * The constructor should first build the main layout, set the
+ * composition root and then do any custom initialization.
+ *
+ * The constructor will not be automatically regenerated by the
+ * visual editor.
+ */
+ public AttributeEditorWindow(EntityItem<Attribute> entityItem) {
+ //
+ // Save our attribute
+ //
+ this.attribute = entityItem.getEntity();
+ if (logger.isDebugEnabled()) {
+ logger.debug("Editing attribute: " + entityItem.getEntity().toString());
+ }
+ //
+ // Set our shortcuts
+ //
+ this.setCloseShortcut(KeyCode.ESCAPE);
+ //
+ // Create our main layout
+ //
+ this.setContent(mainLayout);
+ //
+ // Finish setting up the main layout
+ //
+ this.mainLayout.setSpacing(true);
+ this.mainLayout.setMargin(true);
+ //
+ // Setup option group, binding the
+ // field group doesn't seem to work.
+ //
+ this.selectDesignator = new DesignatorSelectorField(entityItem);
+ this.selectDesignator.setCaption("Select the Attribute Type");
+ this.selectDesignator.addValueChangeListener(new ValueChangeListener() {
+ private static final long serialVersionUID = 1L;
+
+ @Override
+ public void valueChange(ValueChangeEvent event) {
+ Object value = self.selectDesignator.getValue();
+ if (value == null || ! (value instanceof Character)) {
+ self.selectorPath.setVisible(false);
+ }
+ if (((Character) value) == '1') {
+ self.selectorPath.setVisible(false);
+ } else {
+ self.selectorPath.setVisible(true);
+ }
+ }
+ });
+ //
+ // Setup selector path
+ //
+ this.selectorPath.setImmediate(true);
+ this.selectorPath.setNullRepresentation("");
+ this.selectorPath.setWidth("100%");
+ //
+ // Setup the Category combo
+ //
+ this.category.setContainerDataSource(((XacmlAdminUI) UI.getCurrent()).getCategories());
+ this.category.setItemCaptionMode(ItemCaptionMode.PROPERTY);
+ this.category.setItemCaptionPropertyId("xacmlId");
+ this.category.setFilteringMode(FilteringMode.CONTAINS);
+ this.category.setImmediate(true);
+ this.category.setNullSelectionAllowed(false);
+ this.category.setConverter(new SingleSelectConverter<Object>(this.category));
+ //
+ // Setup the Datatype combo
+ //
+ this.datatype.setContainerDataSource(((XacmlAdminUI) UI.getCurrent()).getDatatypes());
+ this.datatype.setItemCaptionMode(ItemCaptionMode.PROPERTY);
+ this.datatype.setItemCaptionPropertyId("xacmlId");
+ this.datatype.setFilteringMode(FilteringMode.CONTAINS);
+ this.datatype.setImmediate(true);
+ this.datatype.setNullSelectionAllowed(false);
+ this.datatype.setConverter(new SingleSelectConverter<Object>(this.datatype));
+ //
+ // Setup the constraint type combo
+ //
+ this.constraintTypes.setContainerDataSource(((XacmlAdminUI) UI.getCurrent()).getConstraintTypes());
+ this.constraintTypes.setItemCaptionMode(ItemCaptionMode.PROPERTY);
+ this.constraintTypes.setItemCaptionPropertyId("constraintType");
+ this.constraintTypes.setFilteringMode(FilteringMode.CONTAINS);
+ this.constraintTypes.setImmediate(true);
+ this.constraintTypes.setNullSelectionAllowed(true);
+ this.constraintTypes.setConverter(new SingleSelectConverter<Object>(this.constraintTypes));
+ //
+ // Setup the constraint value custom field
+ //
+ this.constraintValues = new ConstraintField(entityItem);
+ //
+ // Finish laying out the main layout
+ //
+ this.mainLayout.addComponent(this.selectDesignator);
+ this.mainLayout.addComponent(this.selectorPath);
+ this.mainLayout.addComponent(this.xacmlID);
+ this.mainLayout.addComponent(this.category);
+ this.mainLayout.addComponent(this.descriptionField);
+ this.mainLayout.addComponent(this.datatype);
+ this.mainLayout.addComponent(this.constraintTypes);
+ this.mainLayout.addComponent(this.constraintValues);
+ //
+ // Now create our field group and bind our bean items
+ // This will populate the components with the attribute's
+ // current value.
+ //
+ this.fieldGroup = new FieldGroup(entityItem);
+ this.fieldGroup.bindMemberFields(this);
+ //
+ // Finishing setting up after the bind. There are some components
+ // where initializing the bind causes some properties to be reset.
+ //
+ this.xacmlID.setWidth("100%");
+ this.descriptionField.setNullRepresentation("");
+ this.descriptionField.setWidth("100%");
+ this.setupDatatype(this.attribute.getDatatypeBean().getIdentifer());
+ this.datatype.addValueChangeListener(new ValueChangeListener() {
+ private static final long serialVersionUID = 1L;
+
+ @Override
+ public void valueChange(ValueChangeEvent event) {
+ Identifier id = self.getCurrentDatatype();
+ if (id != null) {
+ self.setupDatatype(id);
+ }
+ }
+ });
+ //
+ // Listen to when constraint type changes
+ //
+ this.constraintTypes.addValueChangeListener(new ValueChangeListener() {
+ private static final long serialVersionUID = 1L;
+
+ @Override
+ public void valueChange(ValueChangeEvent event) {
+ Object value = self.constraintTypes.getValue();
+ if (value == null) {
+ self.constraintValues.resetContent(null, self.getCurrentDatatype());
+ } else {
+ ConstraintType newValue = ((XacmlAdminUI) UI.getCurrent()).getConstraintTypes().getItem(value).getEntity();
+ self.constraintValues.resetContent(newValue, self.getCurrentDatatype());
+ }
+ }
+ });
+ //
+ // Setup our "SAVE" button to commit the fields
+ //
+ this.mainLayout.addComponent(this.saveButton);
+ this.mainLayout.setComponentAlignment(this.saveButton, Alignment.MIDDLE_CENTER);
+ this.saveButton.addClickListener(new ClickListener() {
+ private static final long serialVersionUID = 1L;
+
+ @Override
+ public void buttonClick(ClickEvent event) {
+ try {
+ //
+ // SAVE the latest values
+ //
+ fieldGroup.commit();
+ //
+ // Set that we did save the attribute
+ //
+ self.isSaved = true;
+ //
+ // Close the window
+ //
+ self.close();
+ } catch (CommitException e) {
+ logger.error("Failed to commit fields", e);
+ }
+ }
+
+ });
+ //
+ // Add our close listener so we can discard anything that was changed.
+ //
+ this.addCloseListener(new CloseListener() {
+ private static final long serialVersionUID = 1L;
+
+ @Override
+ public void windowClose(CloseEvent e) {
+ if (self.isSaved == false) {
+ logger.info("discarding");
+ //
+ // Discard any changes to the existing JPA container entity
+ //
+ self.fieldGroup.discard();
+ //
+ // Make sure there are no filters on the container
+ //
+ ((XacmlAdminUI) UI.getCurrent()).getConstraintTypes().removeAllContainerFilters();
+ }
+ }
+
+ });
+ //
+ // Set focus
+ //
+ this.xacmlID.focus();
+ }
+
+ private void setupDatatype(Identifier datatype) {
+ if (datatype.equals(XACML3.ID_DATATYPE_INTEGER) ||
+ datatype.equals(XACML3.ID_DATATYPE_DOUBLE)) {
+ ((XacmlAdminUI) UI.getCurrent()).getConstraintTypes().removeAllContainerFilters();
+ this.constraintTypes.setEnabled(true);
+ this.constraintValues.resetDatatype(datatype);
+ return;
+ }
+ if (datatype.equals(XACML3.ID_DATATYPE_STRING)) {
+ ((XacmlAdminUI) UI.getCurrent()).getConstraintTypes().addContainerFilter(new Not(new Compare.Equal("constraintType", ConstraintType.RANGE_TYPE)));
+ if (this.attribute.getConstraintType() != null &&
+ this.attribute.getConstraintType().getConstraintType() != null &&
+ this.attribute.getConstraintType().getConstraintType().equals(ConstraintType.RANGE_TYPE)) {
+ this.attribute.setConstraintType(null);
+ }
+ this.constraintValues.resetDatatype(datatype);
+ return;
+ }
+ //
+ // No constraint for all other datatypes
+ //
+ this.attribute.setConstraintType(null);
+ this.constraintTypes.select(null);
+ this.constraintTypes.setEnabled(false);
+ }
+
+ private Identifier getCurrentDatatype() {
+ Object id = self.datatype.getValue();
+ if (id != null) {
+ EntityItem<Datatype> dt = ((XacmlAdminUI) UI.getCurrent()).getDatatypes().getItem(id);
+ if (dt != null) {
+ return dt.getEntity().getIdentifer();
+ }
+ }
+ return null;
+ }
+
+ public boolean isSaved() {
+ return this.isSaved;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-openaz/blob/a1d93100/openaz-xacml-pap-admin/src/main/java/org/apache/openaz/xacml/admin/view/windows/AttributeSelectionWindow.java
----------------------------------------------------------------------
diff --git a/openaz-xacml-pap-admin/src/main/java/org/apache/openaz/xacml/admin/view/windows/AttributeSelectionWindow.java b/openaz-xacml-pap-admin/src/main/java/org/apache/openaz/xacml/admin/view/windows/AttributeSelectionWindow.java
new file mode 100644
index 0000000..b1448bf
--- /dev/null
+++ b/openaz-xacml-pap-admin/src/main/java/org/apache/openaz/xacml/admin/view/windows/AttributeSelectionWindow.java
@@ -0,0 +1,396 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 org.apache.openaz.xacml.admin.view.windows;
+import oasis.names.tc.xacml._3_0.core.schema.wd_17.AttributeDesignatorType;
+import oasis.names.tc.xacml._3_0.core.schema.wd_17.AttributeSelectorType;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import org.apache.openaz.xacml.admin.jpa.Attribute;
+import org.apache.openaz.xacml.admin.jpa.Datatype;
+import org.apache.openaz.xacml.admin.util.JPAUtils;
+import org.apache.openaz.xacml.admin.view.components.AttributeDictionarySelectorComponent;
+import org.apache.openaz.xacml.admin.view.components.AttributeSimpleCreatorComponent;
+import org.apache.openaz.xacml.admin.view.components.AttributeStandardSelectorComponent;
+import org.apache.openaz.xacml.admin.view.events.AttributeChangedEventListener;
+import org.apache.openaz.xacml.admin.view.events.AttributeChangedEventNotifier;
+import com.vaadin.annotations.AutoGenerated;
+import com.vaadin.data.Buffered.SourceException;
+import com.vaadin.data.Property.ValueChangeEvent;
+import com.vaadin.data.Property.ValueChangeListener;
+import com.vaadin.data.Validator.InvalidValueException;
+import com.vaadin.event.ShortcutAction.KeyCode;
+import com.vaadin.ui.Alignment;
+import com.vaadin.ui.Button;
+import com.vaadin.ui.Button.ClickEvent;
+import com.vaadin.ui.Button.ClickListener;
+import com.vaadin.ui.CheckBox;
+import com.vaadin.ui.CustomComponent;
+import com.vaadin.ui.HorizontalLayout;
+import com.vaadin.ui.OptionGroup;
+import com.vaadin.ui.TextField;
+import com.vaadin.ui.VerticalLayout;
+import com.vaadin.ui.Window;
+
+public class AttributeSelectionWindow extends Window implements AttributeChangedEventListener {
+
+ /*- VaadinEditorProperties={"grid":"RegularGrid,20","showGrid":true,"snapToGrid":true,"snapToObject":true,"movingGuides":false,"snappingDistance":10} */
+
+ @AutoGenerated
+ private VerticalLayout mainLayout;
+ @AutoGenerated
+ private Button buttonSave;
+ @AutoGenerated
+ private HorizontalLayout horizontalLayoutAttribute;
+ @AutoGenerated
+ private HorizontalLayout horizontalLayout_1;
+ @AutoGenerated
+ private VerticalLayout verticalLayout_2;
+ @AutoGenerated
+ private CheckBox checkBoxMustBePresent;
+ @AutoGenerated
+ private TextField textFieldIssuer;
+ @AutoGenerated
+ private OptionGroup optionGroupAttribute;
+ /**
+ *
+ */
+ private static final long serialVersionUID = 1L;
+ private static Log logger = LogFactory.getLog(AttributeSelectionWindow.class);
+ private final AttributeSelectionWindow self = this;
+ private final Datatype datatype;
+ private final Attribute defaultAttribute;
+ private AttributeChangedEventNotifier currentComponent = null;
+ private Attribute attribute = null;
+ private boolean isSaved = false;
+
+ public static final String ATTRIBUTE_OPTION_DICTIONARY = "Use Attribute From Dictionary";
+ public static final String ATTRIBUTE_OPTION_STANDARD = "Use A Standard Attribute";
+ public static final String ATTRIBUTE_OPTION_INPUT = "Input A New Attribute";
+ public static final String[] ATTRIBUTE_OPTIONS = new String[] {ATTRIBUTE_OPTION_DICTIONARY, ATTRIBUTE_OPTION_STANDARD, ATTRIBUTE_OPTION_INPUT};
+
+ /**
+ * The constructor should first build the main layout, set the
+ * composition root and then do any custom initialization.
+ *
+ * The constructor will not be automatically regenerated by the
+ * visual editor.
+ */
+ public AttributeSelectionWindow(Datatype datatype, Object defaultAttribute) {
+ buildMainLayout();
+ //setCompositionRoot(mainLayout);
+ setContent(mainLayout);
+ //
+ // Save data
+ //
+ this.datatype = datatype;
+ if (defaultAttribute == null) {
+ this.defaultAttribute = null;
+ } else {
+ //
+ // Given a default attribute
+ //
+ Attribute tempAttribute;
+ if (defaultAttribute instanceof AttributeDesignatorType) {
+ tempAttribute = JPAUtils.createAttribute((AttributeDesignatorType) defaultAttribute);
+ } else if (defaultAttribute instanceof AttributeSelectorType) {
+ tempAttribute = JPAUtils.createAttribute((AttributeSelectorType) defaultAttribute);
+ } else {
+ this.defaultAttribute = null;
+ throw new IllegalArgumentException("Selection window only works with designator or selector objects.");
+ }
+ //
+ // See if the attribute exists in our dictionary
+ //
+ Attribute dictionaryAttribute = JPAUtils.findAttribute(tempAttribute);
+ if (dictionaryAttribute != null) {
+ this.defaultAttribute = dictionaryAttribute;
+ } else {
+ this.defaultAttribute = tempAttribute;
+ }
+ }
+ //
+ // Close shortcut
+ //
+ this.setCloseShortcut(KeyCode.ESCAPE);
+ //
+ // Initialize GUI
+ //
+ this.initializeOption();
+ this.initializeButtons();
+ this.initializeAttribute();
+ //
+ // Setup attribute
+ //
+ this.resetAttributeOption();
+ //
+ // Focus
+ //
+ }
+
+ protected void initializeOption() {
+ //
+ // Setup datasource and GUI properties
+ //
+ this.optionGroupAttribute.setImmediate(true);
+ this.optionGroupAttribute.addItem(ATTRIBUTE_OPTION_DICTIONARY);
+ this.optionGroupAttribute.addItem(ATTRIBUTE_OPTION_STANDARD);
+ this.optionGroupAttribute.addItem(ATTRIBUTE_OPTION_INPUT);
+ //
+ // Respond to events
+ //
+ this.optionGroupAttribute.addValueChangeListener(new ValueChangeListener() {
+ private static final long serialVersionUID = 1L;
+
+ @Override
+ public void valueChange(ValueChangeEvent event) {
+ self.resetAttributeOption();
+ }
+ });
+ }
+
+ protected void initializeButtons() {
+ this.buttonSave.setClickShortcut(KeyCode.ENTER);
+ this.buttonSave.addClickListener(new ClickListener() {
+ private static final long serialVersionUID = 1L;
+
+ @Override
+ public void buttonClick(ClickEvent event) {
+ try {
+ //
+ // Commit everything??
+ //
+ self.textFieldIssuer.commit();
+ self.checkBoxMustBePresent.commit();
+ self.currentComponent.commit();
+ //
+ // Save to the attribute
+ //
+ String issuer = self.textFieldIssuer.getValue();
+ if (issuer == null || issuer.length() == 0) {
+ self.attribute.setIssuer(null);
+ } else {
+ self.attribute.setIssuer(issuer);
+ }
+ self.attribute.setMustBePresent(self.checkBoxMustBePresent.getValue());
+ //
+ // Mark as saved
+ //
+ self.isSaved = true;
+ //
+ // Close the window
+ //
+ self.close();
+ } catch (SourceException | InvalidValueException e) { //NOPMD
+ //
+ // Vaadin displays the error
+ //
+ }
+ }
+ });
+ }
+
+ protected void initializeAttribute() {
+ //
+ // Are we editing something?
+ //
+ if (this.defaultAttribute == null) {
+ //
+ // No, this is a new attribute being created
+ //
+ this.optionGroupAttribute.select(ATTRIBUTE_OPTION_STANDARD);
+ return;
+ }
+ //
+ // Yes, is it in our dictionary?
+ //
+ Attribute attribute = JPAUtils.findAttribute(this.defaultAttribute);
+ if (attribute != null) {
+ //
+ // Yes its in our dictionary
+ //
+ this.attribute = attribute;
+ this.optionGroupAttribute.select(ATTRIBUTE_OPTION_DICTIONARY);
+ return;
+ }
+ //
+ // Is it a standard attribute?
+ //
+ attribute = JPAUtils.isStandardAttribute(this.defaultAttribute);
+ if (attribute == null) {
+ //
+ // No, start editing via custom input attribute
+ //
+ this.attribute = this.defaultAttribute;
+ this.optionGroupAttribute.select(ATTRIBUTE_OPTION_INPUT);
+ return;
+ }
+ //
+ // Yes - its a standard attribute
+ //
+ this.attribute = attribute;
+ this.optionGroupAttribute.select(ATTRIBUTE_OPTION_STANDARD);
+ }
+
+ protected void resetAttributeOption() {
+ //
+ // Remove GUI components from layout
+ //
+ this.horizontalLayoutAttribute.removeAllComponents();
+ this.currentComponent = null;
+ //
+ // Grab our currently selected option value
+ //
+ Object value = self.optionGroupAttribute.getValue();
+ //
+ // What is it set to?
+ //
+ if (value.toString().equals(ATTRIBUTE_OPTION_DICTIONARY)) {
+ this.currentComponent = new AttributeDictionarySelectorComponent(this.datatype, this.defaultAttribute);
+ } else if (value.toString().equals(ATTRIBUTE_OPTION_STANDARD)) {
+ this.currentComponent = new AttributeStandardSelectorComponent(this.datatype, this.defaultAttribute);
+ } else if (value.toString().equals(ATTRIBUTE_OPTION_INPUT)) {
+ this.currentComponent = new AttributeSimpleCreatorComponent(this.datatype, this.defaultAttribute);
+ } else {
+ logger.error("Unknown option" + value);
+ return;
+ }
+ this.currentComponent.addListener(this);
+ this.horizontalLayoutAttribute.addComponent((CustomComponent) this.currentComponent);
+ this.currentComponent.fireAttributeChanged(this.currentComponent.getAttribute());
+ }
+
+ @Override
+ public void attributeChanged(Attribute attribute) {
+ if (logger.isDebugEnabled()) {
+ logger.debug("attributeChanged: " + attribute);
+ }
+ this.attribute = attribute;
+ if (attribute == null) {
+ this.buttonSave.setEnabled(false);
+ } else {
+ this.buttonSave.setEnabled(true);
+ }
+ }
+
+ public boolean isSaved() {
+ return this.isSaved;
+ }
+
+ public Attribute getAttribute() {
+ return this.attribute;
+ }
+
+ @AutoGenerated
+ private VerticalLayout buildMainLayout() {
+ // common part: create layout
+ mainLayout = new VerticalLayout();
+ mainLayout.setImmediate(false);
+ mainLayout.setWidth("-1px");
+ mainLayout.setHeight("-1px");
+ mainLayout.setMargin(true);
+ mainLayout.setSpacing(true);
+
+ // top-level component properties
+ setWidth("-1px");
+ setHeight("-1px");
+
+ // horizontalLayout_1
+ horizontalLayout_1 = buildHorizontalLayout_1();
+ mainLayout.addComponent(horizontalLayout_1);
+
+ // horizontalLayoutAttribute
+ horizontalLayoutAttribute = new HorizontalLayout();
+ horizontalLayoutAttribute.setImmediate(false);
+ horizontalLayoutAttribute.setWidth("-1px");
+ horizontalLayoutAttribute.setHeight("-1px");
+ horizontalLayoutAttribute.setMargin(false);
+ mainLayout.addComponent(horizontalLayoutAttribute);
+ mainLayout.setExpandRatio(horizontalLayoutAttribute, 1.0f);
+
+ // buttonSave
+ buttonSave = new Button();
+ buttonSave.setCaption("Select");
+ buttonSave.setImmediate(true);
+ buttonSave.setWidth("-1px");
+ buttonSave.setHeight("-1px");
+ mainLayout.addComponent(buttonSave);
+ mainLayout.setComponentAlignment(buttonSave, new Alignment(48));
+
+ return mainLayout;
+ }
+
+ @AutoGenerated
+ private HorizontalLayout buildHorizontalLayout_1() {
+ // common part: create layout
+ horizontalLayout_1 = new HorizontalLayout();
+ horizontalLayout_1.setImmediate(false);
+ horizontalLayout_1.setWidth("-1px");
+ horizontalLayout_1.setHeight("-1px");
+ horizontalLayout_1.setMargin(false);
+
+ // optionGroupAttribute
+ optionGroupAttribute = new OptionGroup();
+ optionGroupAttribute.setCaption("Attribute Source");
+ optionGroupAttribute.setImmediate(false);
+ optionGroupAttribute.setWidth("-1px");
+ optionGroupAttribute.setHeight("-1px");
+ optionGroupAttribute.setInvalidAllowed(false);
+ horizontalLayout_1.addComponent(optionGroupAttribute);
+
+ // verticalLayout_2
+ verticalLayout_2 = buildVerticalLayout_2();
+ horizontalLayout_1.addComponent(verticalLayout_2);
+
+ return horizontalLayout_1;
+ }
+
+ @AutoGenerated
+ private VerticalLayout buildVerticalLayout_2() {
+ // common part: create layout
+ verticalLayout_2 = new VerticalLayout();
+ verticalLayout_2.setImmediate(false);
+ verticalLayout_2.setWidth("-1px");
+ verticalLayout_2.setHeight("-1px");
+ verticalLayout_2.setMargin(true);
+ verticalLayout_2.setSpacing(true);
+
+ // textFieldIssuer
+ textFieldIssuer = new TextField();
+ textFieldIssuer.setCaption("Issuer");
+ textFieldIssuer.setImmediate(false);
+ textFieldIssuer.setWidth("-1px");
+ textFieldIssuer.setHeight("-1px");
+ verticalLayout_2.addComponent(textFieldIssuer);
+
+ // checkBoxMustBePresent
+ checkBoxMustBePresent = new CheckBox();
+ checkBoxMustBePresent.setCaption("Attribute Must Be Present");
+ checkBoxMustBePresent.setImmediate(false);
+ checkBoxMustBePresent.setWidth("-1px");
+ checkBoxMustBePresent.setHeight("-1px");
+ verticalLayout_2.addComponent(checkBoxMustBePresent);
+
+ return verticalLayout_2;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-openaz/blob/a1d93100/openaz-xacml-pap-admin/src/main/java/org/apache/openaz/xacml/admin/view/windows/AttributeValueEditorWindow.java
----------------------------------------------------------------------
diff --git a/openaz-xacml-pap-admin/src/main/java/org/apache/openaz/xacml/admin/view/windows/AttributeValueEditorWindow.java b/openaz-xacml-pap-admin/src/main/java/org/apache/openaz/xacml/admin/view/windows/AttributeValueEditorWindow.java
new file mode 100644
index 0000000..13ae0b1
--- /dev/null
+++ b/openaz-xacml-pap-admin/src/main/java/org/apache/openaz/xacml/admin/view/windows/AttributeValueEditorWindow.java
@@ -0,0 +1,320 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 org.apache.openaz.xacml.admin.view.windows;
+
+import oasis.names.tc.xacml._3_0.core.schema.wd_17.AttributeValueType;
+
+import org.apache.openaz.xacml.admin.XacmlAdminUI;
+import org.apache.openaz.xacml.admin.jpa.Datatype;
+import org.apache.openaz.xacml.admin.util.JPAUtils;
+import org.apache.openaz.xacml.admin.view.validators.ValidatorFactory;
+import com.vaadin.addon.jpacontainer.EntityItem;
+import com.vaadin.addon.jpacontainer.fieldfactory.SingleSelectConverter;
+import com.vaadin.annotations.AutoGenerated;
+import com.vaadin.data.Property.ValueChangeEvent;
+import com.vaadin.data.Property.ValueChangeListener;
+import com.vaadin.data.Validator;
+import com.vaadin.data.Validator.InvalidValueException;
+import com.vaadin.event.ShortcutAction.KeyCode;
+import com.vaadin.shared.ui.combobox.FilteringMode;
+import com.vaadin.ui.AbstractSelect.ItemCaptionMode;
+import com.vaadin.ui.Alignment;
+import com.vaadin.ui.Button;
+import com.vaadin.ui.Button.ClickEvent;
+import com.vaadin.ui.Button.ClickListener;
+import com.vaadin.ui.ComboBox;
+import com.vaadin.ui.TextField;
+import com.vaadin.ui.UI;
+import com.vaadin.ui.VerticalLayout;
+import com.vaadin.ui.Window;
+
+public class AttributeValueEditorWindow extends Window {
+ /*- VaadinEditorProperties={"grid":"RegularGrid,20","showGrid":true,"snapToGrid":true,"snapToObject":true,"movingGuides":false,"snappingDistance":10} */
+
+ @AutoGenerated
+ private VerticalLayout mainLayout;
+ @AutoGenerated
+ private Button buttonSave;
+ @AutoGenerated
+ private TextField textFieldValue;
+ @AutoGenerated
+ private ComboBox comboBoxDatatype;
+ private static final long serialVersionUID = 1L;
+ private final AttributeValueEditorWindow self = this;
+ private final Datatype datatypeRestriction;
+ private final AttributeValueType value;
+ private boolean isSaved = false;
+ /**
+ * The constructor should first build the main layout, set the
+ * composition root and then do any custom initialization.
+ *
+ * The constructor will not be automatically regenerated by the
+ * visual editor.
+ */
+ public AttributeValueEditorWindow(AttributeValueType value, Datatype datatypeRestriction) {
+ buildMainLayout();
+ //setCompositionRoot(mainLayout);
+ setContent(mainLayout);
+ //
+ // Save
+ //
+ this.value = value;
+ this.datatypeRestriction = datatypeRestriction;
+ //
+ // Make sure the value has the same datatype as the restriction
+ //
+ if (this.datatypeRestriction != null) {
+ this.value.setDataType(this.datatypeRestriction.getXacmlId());
+ }
+ //
+ // Set our shortcuts
+ //
+ this.setCloseShortcut(KeyCode.ESCAPE);
+ //
+ // Initialize GUI
+ //
+ this.initializeCombo();
+ this.initializeTextField();
+ this.initializeButtons();
+ //
+ // Focus?
+ //
+ if (this.datatypeRestriction == null) {
+ this.comboBoxDatatype.focus();
+ } else {
+ this.textFieldValue.focus();
+ }
+ }
+
+ protected void initializeCombo() {
+ this.comboBoxDatatype.setContainerDataSource(((XacmlAdminUI) UI.getCurrent()).getDatatypes());
+ this.comboBoxDatatype.setItemCaptionMode(ItemCaptionMode.PROPERTY);
+ this.comboBoxDatatype.setItemCaptionPropertyId("xacmlId");
+ this.comboBoxDatatype.setFilteringMode(FilteringMode.CONTAINS);
+ this.comboBoxDatatype.setImmediate(true);
+ this.comboBoxDatatype.setNullSelectionAllowed(false);
+ this.comboBoxDatatype.setConverter(new SingleSelectConverter<Object>(this.comboBoxDatatype));
+ //
+ // Select a value if its defined
+ //
+ if (this.datatypeRestriction != null) {
+ this.comboBoxDatatype.select(this.datatypeRestriction.getId());
+ } else if (this.value.getDataType() != null) {
+ this.comboBoxDatatype.select(JPAUtils.findDatatype(this.value.getDataType()).getId());
+ }
+ //
+ // Can the user change the datatype?
+ //
+ if (this.datatypeRestriction != null) {
+ this.comboBoxDatatype.setEnabled(false);
+ return;
+ }
+ //
+ // Listen to events
+ //
+ this.comboBoxDatatype.addValueChangeListener(new ValueChangeListener() {
+ private static final long serialVersionUID = 1L;
+
+ @Override
+ public void valueChange(ValueChangeEvent event) {
+ Object id = self.comboBoxDatatype.getValue();
+ assert id != null;
+ //
+ // Get the entity and save it
+ //
+ EntityItem<Datatype> entity = ((XacmlAdminUI) UI.getCurrent()).getDatatypes().getItem(id);
+ self.value.setDataType(entity.getEntity().getXacmlId());
+ //
+ // Reset the validator
+ //
+ self.textFieldValue.removeAllValidators();
+ Validator validator = ValidatorFactory.newInstance(entity.getEntity());
+ if (validator != null) {
+ self.textFieldValue.addValidator(validator);
+ }
+ }
+ });
+ }
+
+ protected void initializeTextField() {
+ //
+ // GUI properties
+ //
+ this.textFieldValue.setImmediate(true);
+ this.textFieldValue.setNullRepresentation("");
+ //
+ // Setup validator
+ //
+ if (this.datatypeRestriction != null) {
+ Validator validator = ValidatorFactory.newInstance(this.datatypeRestriction);
+ if (validator != null) {
+ this.textFieldValue.addValidator(validator);
+ }
+ }
+ //
+ // Text change or Value Change?
+ //
+ this.textFieldValue.addValueChangeListener(new ValueChangeListener() {
+ private static final long serialVersionUID = 1L;
+
+ @Override
+ public void valueChange(ValueChangeEvent event) {
+ //
+ // Save the new value. TODO - assuming position 0 of content list.
+ //
+ self.saveValue(0, self.textFieldValue.getValue());
+ //
+ // Setup the save button
+ //
+ if (self.textFieldValue.getValue() == null || self.textFieldValue.getValue().isEmpty()) {
+ self.buttonSave.setEnabled(false);
+ } else {
+ self.buttonSave.setEnabled(true);
+ }
+ }
+ });
+ //
+ // Initialize the value
+ //
+ if (this.value != null && this.value.getContent().isEmpty() == false) {
+ //
+ // TODO - If there are multiple Content objects...Right now we work with the first one only.
+ //
+ this.textFieldValue.setValue(this.value.getContent().get(0).toString());
+ }
+ }
+
+ protected void saveValue(int i, String value) {
+ //
+ // Get the content - TODO
+ //
+ if (this.value.getContent().isEmpty()) {
+ this.value.getContent().add(value);
+ return;
+ }
+ Object o = this.value.getContent().get(i);
+ if (o == null) {
+ //
+ // Add it into the list - ensure its a
+ //
+ assert this.value.getContent().size() == i;
+ this.value.getContent().add(value);
+ } else {
+ //
+ // Overwrite the previous object
+ //
+ this.value.getContent().set(i, value);
+ }
+ }
+
+ protected void initializeButtons() {
+ this.buttonSave.setClickShortcut(KeyCode.ENTER);
+ this.buttonSave.addClickListener(new ClickListener() {
+ private static final long serialVersionUID = 1L;
+
+ @Override
+ public void buttonClick(ClickEvent event) {
+ try {
+ //
+ // Make sure it validates (i.e. call the Validators)
+ //
+ self.comboBoxDatatype.validate();
+ self.textFieldValue.validate();
+ //
+ // Yes
+ //
+ self.isSaved = true;
+ //
+ // Close
+ //
+ self.close();
+ } catch (InvalidValueException e) { //NOPMD
+ //
+ // Vaadin with update GUI displaying the error
+ //
+ }
+ }
+ });
+ }
+
+ public boolean isSaved() {
+ return this.isSaved;
+ }
+
+ public String getValue() {
+ return this.textFieldValue.getValue();
+ }
+
+ public AttributeValueType getAttribute() {
+ return this.value;
+ }
+
+ public Datatype getDatatype() {
+ return JPAUtils.findDatatype(this.value.getDataType());
+ }
+
+ @AutoGenerated
+ private VerticalLayout buildMainLayout() {
+ // common part: create layout
+ mainLayout = new VerticalLayout();
+ mainLayout.setImmediate(false);
+ mainLayout.setWidth("-1px");
+ mainLayout.setHeight("-1px");
+ mainLayout.setMargin(true);
+ mainLayout.setSpacing(true);
+
+ // top-level component properties
+ setWidth("-1px");
+ setHeight("-1px");
+
+ // comboBoxDatatype
+ comboBoxDatatype = new ComboBox();
+ comboBoxDatatype.setCaption("Select Datatype");
+ comboBoxDatatype.setImmediate(false);
+ comboBoxDatatype.setWidth("-1px");
+ comboBoxDatatype.setHeight("-1px");
+ comboBoxDatatype.setInvalidAllowed(false);
+ comboBoxDatatype.setRequired(true);
+ mainLayout.addComponent(comboBoxDatatype);
+
+ // textFieldValue
+ textFieldValue = new TextField();
+ textFieldValue.setCaption("Attribute Value");
+ textFieldValue.setImmediate(false);
+ textFieldValue.setWidth("100.0%");
+ textFieldValue.setHeight("-1px");
+ textFieldValue.setInvalidAllowed(false);
+ textFieldValue.setRequired(true);
+ mainLayout.addComponent(textFieldValue);
+
+ // buttonSave
+ buttonSave = new Button();
+ buttonSave.setCaption("Save");
+ buttonSave.setImmediate(true);
+ buttonSave.setWidth("-1px");
+ buttonSave.setHeight("-1px");
+ mainLayout.addComponent(buttonSave);
+ mainLayout.setComponentAlignment(buttonSave, new Alignment(48));
+
+ return mainLayout;
+ }
+
+}