Commit 5fcaa93b authored by Gianluca Filippone's avatar Gianluca Filippone
Browse files

Added first implementation for Enactment Engine add and edit

parent 35e51edb
......@@ -52,17 +52,6 @@ public class EnactmentEnginePage extends BaseExtPage {
utilityModal.size(Modal.Size.Large);
utilityModal.addSubmitButton();
/*utilityModal.setWindowClosedCallback(new WindowClosedCallback() {
private static final long serialVersionUID = 2372096723782367810L;
@Override
public void onClose(final AjaxRequestTarget target) {
target.add(content);
utilityModal.show(false);
}
});*/
content.add(new AjaxLink("addLink") {
private static final long serialVersionUID = 4879178530891785513L;
......@@ -80,4 +69,11 @@ public class EnactmentEnginePage extends BaseExtPage {
body.add(content);
}
@Override
public void setWindowClosedCallback(final BaseModal<?> modal, final WebMarkupContainer container) {
this.renderPage();
}
}
......@@ -15,12 +15,14 @@
*/
package org.apache.syncope.client.console.panels;
import eu.chorevolution.idm.common.to.EnactmentEngineTO;
import java.io.Serializable;
import org.apache.commons.lang3.StringUtils;
import org.apache.syncope.client.console.SyncopeConsoleSession;
import org.apache.syncope.client.console.commons.Constants;
import org.apache.syncope.client.console.pages.BasePage;
import static org.apache.syncope.client.console.panels.AbstractModalPanel.LOG;
import org.apache.syncope.client.console.rest.EnactmentEngineRestClient;
import org.apache.syncope.client.console.wicket.markup.html.bootstrap.dialog.BaseModal;
import org.apache.syncope.common.lib.SyncopeClientException;
import org.apache.wicket.PageReference;
......@@ -28,15 +30,24 @@ import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.markup.html.form.Form;
public class AddEnactmentEngineModalPanel extends AbstractEnactmentEngineModalPanel {
private final EnactmentEngineRestClient restClient;
public AddEnactmentEngineModalPanel(final BaseModal<Serializable> modal, final PageReference pageRef) {
super(modal, pageRef);
restClient = new EnactmentEngineRestClient();
}
@Override
public void onSubmit(final AjaxRequestTarget target, final Form<?> form) {
try {
//Define action!
EnactmentEngineTO enactmentEngineTO = new EnactmentEngineTO();
enactmentEngineTO.setName(nameInput.getModelObject());
enactmentEngineTO.setUsername(usernameInput.getModelObject());
enactmentEngineTO.setPassword(passwordInput.getModelObject());
enactmentEngineTO.setBaseUrl(urlInput.getModelObject());
restClient.create(enactmentEngineTO);
modal.close(target);
SyncopeConsoleSession.get().info(getString(Constants.OPERATION_SUCCEEDED));
} catch (SyncopeClientException e) {
......
......@@ -15,6 +15,7 @@
*/
package org.apache.syncope.client.console.panels;
import eu.chorevolution.idm.common.to.EnactmentEngineTO;
import java.io.Serializable;
import org.apache.commons.lang3.StringUtils;
import org.apache.syncope.client.console.SyncopeConsoleSession;
......@@ -23,20 +24,41 @@ import org.apache.syncope.client.console.pages.BasePage;
import static org.apache.syncope.client.console.panels.AbstractModalPanel.LOG;
import org.apache.syncope.client.console.wicket.markup.html.bootstrap.dialog.BaseModal;
import org.apache.syncope.common.lib.SyncopeClientException;
import org.apache.syncope.common.lib.to.AnyObjectTO;
import org.apache.wicket.PageReference;
import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.markup.html.form.Form;
public class EditEnactmentEngineModalPanel extends AbstractEnactmentEngineModalPanel {
public EditEnactmentEngineModalPanel(final BaseModal<Serializable> modal, final PageReference pageRef) {
private final AnyObjectTO enactmentEngine;
public EditEnactmentEngineModalPanel(
final BaseModal<Serializable> modal,
final PageReference pageRef,
final AnyObjectTO enactmentEngine) {
super(modal, pageRef);
this.enactmentEngine = enactmentEngine;
nameInput.setModelObject(enactmentEngine.getName());
urlInput.setModelObject(enactmentEngine.getPlainAttrMap().get("enactmentEngineBaseURL").getValues().get(0));
usernameInput.setModelObject(enactmentEngine.
getPlainAttrMap().get("enactmentEngineUsername").getValues().get(0));
/*passwordInput.setModelObject(enactmentEngine.
getPlainAttrMap().get("enactmentEnginePassword").getValues().get(0));*/
passwordInput.setRequired(false);
passwordInput.setEnabled(false);
}
@Override
public void onSubmit(final AjaxRequestTarget target, final Form<?> form) {
try {
//Define action!
EnactmentEngineTO enactmentEngineTO = new EnactmentEngineTO();
enactmentEngineTO.setKey((enactmentEngine.getKey()));
enactmentEngineTO.setName(nameInput.getModelObject());
enactmentEngineTO.setBaseUrl(urlInput.getModelObject());
enactmentEngineTO.setUsername(usernameInput.getModelObject());
enactmentEngineTO.setPassword(passwordInput.getModelObject());
modal.close(target);
SyncopeConsoleSession.get().info(getString(Constants.OPERATION_SUCCEEDED));
} catch (SyncopeClientException e) {
......
......@@ -121,7 +121,8 @@ public class EnactmentEngineDirectoryPanel extends AnyObjectDirectoryPanel {
@Override
public void onClick(final AjaxRequestTarget target) {
utilityModal.header(Model.of("Edit Enactment Engine"));
utilityModal.setContent(new EditEnactmentEngineModalPanel(utilityModal, pageRef));
utilityModal.setContent(new EditEnactmentEngineModalPanel(
utilityModal, pageRef, model.getObject()));
utilityModal.show(true);
target.add(utilityModal);
}
......
......@@ -16,6 +16,7 @@
package org.apache.syncope.client.console.rest;
import eu.chorevolution.idm.common.to.EnactmentEngineStatusTO;
import eu.chorevolution.idm.common.to.EnactmentEngineTO;
import eu.chorevolution.idm.common.to.VirtualMachineInfoTO;
import java.util.List;
import static org.apache.syncope.client.console.rest.BaseRestClient.getService;
......@@ -34,7 +35,11 @@ public class EnactmentEngineRestClient extends BaseRestClient {
return getService(MonitorInterfaceService.class).getEEVmList(enactmentEngineKey);
}
public void create() {
getService(EEService.class).create();
public void create(final EnactmentEngineTO enactmentEngineTO) {
getService(EEService.class).create(enactmentEngineTO);
}
public void update(final EnactmentEngineTO enactmentEngineTO) {
getService(EEService.class).update(enactmentEngineTO);
}
}
/*
* Copyright 2017 The CHOReVOLUTION project.
*
* 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 eu.chorevolution.idm.common.to;
import org.apache.syncope.common.lib.AbstractBaseBean;
public class EnactmentEngineTO extends AbstractBaseBean {
private String key;
private String name;
private String username;
private String password;
private String baseUrl;
public String getKey() {
return key;
}
public void setKey(final String key) {
this.key = key;
}
public String getName() {
return name;
}
public void setName(final String name) {
this.name = name;
}
public String getUsername() {
return username;
}
public void setUsername(final String username) {
this.username = username;
}
public String getPassword() {
return password;
}
public void setPassword(final String password) {
this.password = password;
}
public String getBaseUrl() {
return baseUrl;
}
public void setBaseUrl(final String baseUrl) {
this.baseUrl = baseUrl;
}
}
......@@ -15,10 +15,15 @@
*/
package org.apache.syncope.core.logic;
import eu.chorevolution.idm.common.to.EnactmentEngineTO;
import java.lang.reflect.Method;
import org.apache.syncope.common.lib.AbstractBaseBean;
import org.apache.syncope.common.lib.SyncopeConstants;
import org.apache.syncope.common.lib.patch.AnyObjectPatch;
import org.apache.syncope.common.lib.patch.AttrPatch;
import org.apache.syncope.common.lib.patch.StringReplacePatchItem;
import org.apache.syncope.common.lib.to.AnyObjectTO;
import org.apache.syncope.common.lib.to.AttrTO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
......@@ -27,22 +32,67 @@ public class EELogic extends AbstractTransactionalLogic<AbstractBaseBean> {
private static final String ENACTMENT_ENGINE_TYPE = "ENACTMENT ENGINE";
private static final String ENACTMENT_ENGINE_BASE_URL = "enactmentEngineBaseURL";
private static final String ENACTMENT_ENGINE_BASE_URL_SCHEMA = "enactmentEngineBaseURL";
private static final String ENACTMENT_ENGINE_USERNAME = "enactmentEngineUsername";
private static final String ENACTMENT_ENGINE_USERNAME_SCHEMA = "enactmentEngineUsername";
private static final String ENACTMENT_ENGINE_PASSWORD = "enactmentEnginePassword";
private static final String ENACTMENT_ENGINE_PASSWORD_SCHEMA = "enactmentEnginePassword";
@Autowired
private AnyObjectLogic anyObjectLogic;
public void create(final String name, final String baseURL, final String username, final String password) {
public String create(final EnactmentEngineTO enactmentEngineTO) {
AnyObjectTO ee = new AnyObjectTO();
ee.setName("ciao");
ee.setName(enactmentEngineTO.getName());
ee.setType(ENACTMENT_ENGINE_TYPE);
ee.setRealm(SyncopeConstants.ROOT_REALM);
anyObjectLogic.create(ee, true);
ee.getPlainAttrs().add(new AttrTO.Builder()
.schema(ENACTMENT_ENGINE_BASE_URL_SCHEMA).value(enactmentEngineTO.getBaseUrl()).build());
ee.getPlainAttrs().add(new AttrTO.Builder()
.schema(ENACTMENT_ENGINE_USERNAME_SCHEMA).value(enactmentEngineTO.getUsername()).build());
ee.getPlainAttrs().add(new AttrTO.Builder()
.schema(ENACTMENT_ENGINE_PASSWORD_SCHEMA).value(enactmentEngineTO.getPassword()).build());
return anyObjectLogic.create(ee, false).getEntity().getKey();
}
public void update(final EnactmentEngineTO updatedEEData) {
AnyObjectTO enactmentEngine = anyObjectLogic.read(updatedEEData.getKey());
AnyObjectPatch eePatch = new AnyObjectPatch();
eePatch.setKey(updatedEEData.getKey());
if (!enactmentEngine.getName().equals(updatedEEData.getName())) {
eePatch.setName(new StringReplacePatchItem.Builder().value(updatedEEData.getName()).build());
}
if (updatedEEData.getUsername() != null && !updatedEEData.getUsername()
.equals(enactmentEngine.getPlainAttrMap().get(ENACTMENT_ENGINE_USERNAME_SCHEMA).getValues().get(0))) {
eePatch.getPlainAttrs().add(new AttrPatch.Builder().attrTO(new AttrTO.Builder()
.schema(ENACTMENT_ENGINE_USERNAME_SCHEMA).value(updatedEEData.getUsername()).build()).build());
}
if (updatedEEData.getBaseUrl() != null && !updatedEEData.getBaseUrl()
.equals(enactmentEngine.getPlainAttrMap().get(ENACTMENT_ENGINE_BASE_URL_SCHEMA).getValues().get(0))) {
eePatch.getPlainAttrs().add(new AttrPatch.Builder().attrTO(new AttrTO.Builder()
.schema(ENACTMENT_ENGINE_BASE_URL_SCHEMA).value(updatedEEData.getBaseUrl()).build()).build());
}
if (updatedEEData.getUsername() != null && !updatedEEData.getUsername()
.equals(enactmentEngine.getPlainAttrMap().get(ENACTMENT_ENGINE_USERNAME_SCHEMA).getValues().get(0))) {
eePatch.getPlainAttrs().add(new AttrPatch.Builder().attrTO(new AttrTO.Builder()
.schema(ENACTMENT_ENGINE_USERNAME_SCHEMA).value(updatedEEData.getUsername()).build()).build());
}
if (updatedEEData.getPassword() != null && !updatedEEData.getPassword()
.equals(enactmentEngine.getPlainAttrMap().get(ENACTMENT_ENGINE_PASSWORD_SCHEMA).getValues().get(0))) {
eePatch.getPlainAttrs().add(new AttrPatch.Builder().attrTO(new AttrTO.Builder()
.schema(ENACTMENT_ENGINE_PASSWORD_SCHEMA).value(updatedEEData.getPassword()).build()).build());
}
anyObjectLogic.update(eePatch, false);
}
@Override
......
......@@ -15,8 +15,13 @@
*/
package org.apache.syncope.common.rest.api.service;
import eu.chorevolution.idm.common.to.EnactmentEngineTO;
import javax.ws.rs.Consumes;
import javax.ws.rs.POST;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
/**
* REST operations for managing enactment engines.
......@@ -26,5 +31,11 @@ public interface EEService extends JAXRSService {
@POST
@Path("/create")
void create();
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
Response create(EnactmentEngineTO enactmentEngineTO);
@PUT
@Path("/update")
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
void update(EnactmentEngineTO enactmentEngineTO);
}
......@@ -15,6 +15,9 @@
*/
package org.apache.syncope.core.rest.cxf.service;
import eu.chorevolution.idm.common.to.EnactmentEngineTO;
import javax.ws.rs.core.Response;
import org.apache.syncope.common.rest.api.service.EEService;
import org.apache.syncope.core.logic.EELogic;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -27,7 +30,15 @@ public class EEServiceImpl extends AbstractServiceImpl implements EEService {
private EELogic logic;
@Override
public void create() {
logic.create("", "", "", "");
public Response create(final EnactmentEngineTO enactmentEngineTO) {
return Response.status(Response.Status.CREATED).
header("X-CHOReVOLUTION-EnactmentEngineId", logic.create(enactmentEngineTO)).
build();
}
@Override
public void update(final EnactmentEngineTO enactmentEngineTO) {
logic.update(enactmentEngineTO);
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment