Author: [email protected] Date: Tue Nov 1 17:02:08 2011 New Revision: 1701 Log:
Added: sandbox/ivol/tenant-management-gadget/ sandbox/ivol/tenant-management-gadget/LICENSE sandbox/ivol/tenant-management-gadget/NOTICE sandbox/ivol/tenant-management-gadget/pom.xml sandbox/ivol/tenant-management-gadget/src/ sandbox/ivol/tenant-management-gadget/src/main/ sandbox/ivol/tenant-management-gadget/src/main/java/ sandbox/ivol/tenant-management-gadget/src/main/java/org/ sandbox/ivol/tenant-management-gadget/src/main/java/org/amdatu/ sandbox/ivol/tenant-management-gadget/src/main/java/org/amdatu/opensocial/ sandbox/ivol/tenant-management-gadget/src/main/java/org/amdatu/opensocial/tenant/ sandbox/ivol/tenant-management-gadget/src/main/java/org/amdatu/opensocial/tenant/gadget/ sandbox/ivol/tenant-management-gadget/src/main/java/org/amdatu/opensocial/tenant/gadget/osgi/ sandbox/ivol/tenant-management-gadget/src/main/java/org/amdatu/opensocial/tenant/gadget/osgi/Activator.java sandbox/ivol/tenant-management-gadget/src/main/java/org/amdatu/opensocial/tenant/gadget/service/ sandbox/ivol/tenant-management-gadget/src/main/java/org/amdatu/opensocial/tenant/gadget/service/TenantBean.java sandbox/ivol/tenant-management-gadget/src/main/java/org/amdatu/opensocial/tenant/gadget/service/TenantGadgetDefinition.java sandbox/ivol/tenant-management-gadget/src/main/java/org/amdatu/opensocial/tenant/gadget/service/TenantGadgetImpl.java sandbox/ivol/tenant-management-gadget/src/main/java/org/amdatu/opensocial/tenant/gadget/service/TenantRESTServiceImpl.java sandbox/ivol/tenant-management-gadget/src/main/java/org/amdatu/opensocial/tenant/gadget/service/TenantsBean.java sandbox/ivol/tenant-management-gadget/src/main/resources/ sandbox/ivol/tenant-management-gadget/src/main/resources/jsp/ sandbox/ivol/tenant-management-gadget/src/main/resources/jsp/TenantGadget.jsp sandbox/ivol/tenant-management-gadget/src/main/resources/static/ sandbox/ivol/tenant-management-gadget/src/main/resources/static/css/ sandbox/ivol/tenant-management-gadget/src/main/resources/static/css/tenant.css sandbox/ivol/tenant-management-gadget/src/main/resources/static/images/ sandbox/ivol/tenant-management-gadget/src/main/resources/static/images/remove.gif (contents, props changed) sandbox/ivol/tenant-management-gadget/src/main/resources/static/images/tenant.jpg (contents, props changed) sandbox/ivol/tenant-management-gadget/src/main/resources/static/js/ sandbox/ivol/tenant-management-gadget/src/main/resources/static/js/tenant.js sandbox/ivol/tenant-management-gadget/src/main/resources/static/labels/ sandbox/ivol/tenant-management-gadget/src/main/resources/static/labels/tenantmgmt_ALL_ALL.xml Added: sandbox/ivol/tenant-management-gadget/LICENSE ============================================================================== --- (empty file) +++ sandbox/ivol/tenant-management-gadget/LICENSE Tue Nov 1 17:02:08 2011 @@ -0,0 +1,202 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + 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. Added: sandbox/ivol/tenant-management-gadget/NOTICE ============================================================================== --- (empty file) +++ sandbox/ivol/tenant-management-gadget/NOTICE Tue Nov 1 17:02:08 2011 @@ -0,0 +1,27 @@ +Amdatu Auth - Login Gadget +Copyright 2010, 2011 The Amdatu Foundation + + +I. Included Software + +This product includes software developed by The Amdatu Foundation (http://www.amdatu.org/). +Copyright 2010, 2011 The Amdatu Foundation +For more information, see http://amdatu.org. +License: Apache Software License 2.0 (see http://www.apache.org/licenses/LICENSE-2.0.html). +- +This product includes JSON in JAVA, developed by JSON.org (http://www.json.org). +Copyright 2002 JSON.org +For more information, see http://www.json.org/ +License: JSON (see http://www.json.org/license.html) + + +II. Used Software + +This product uses software developed at The OSGi Alliance (http://www.osgi.org/). +Copyright (c) OSGi Alliance (2000, 2007). +License: Apache Software License 2.0 (see http://www.apache.org/licenses/LICENSE-2.0.html). + + +III. License Summary +This products is licensed under the Apache Software License 2.0, +see the LICENSE file included in this distribution. Added: sandbox/ivol/tenant-management-gadget/pom.xml ============================================================================== --- (empty file) +++ sandbox/ivol/tenant-management-gadget/pom.xml Tue Nov 1 17:02:08 2011 @@ -0,0 +1,134 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + Copyright (c) 2010, 2011 The Amdatu Foundation + + 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.verning permissions and limitations + under the License. +--> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <groupId>org.amdatu.opensocial</groupId> + <artifactId>org.amdatu.opensocial</artifactId> + <version>0.2.0-SNAPSHOT</version> + </parent> + <artifactId>org.amdatu.opensocial.tenant.gadget</artifactId> + <packaging>bundle</packaging> + <name>Amdatu OpenSocial - Tenant management gadget</name> + <description>Provides a tenant management gadget</description> + + <properties> + <amdatu.opensocial.version>0.2.0-SNAPSHOT</amdatu.opensocial.version> + </properties> + + <dependencies> + <dependency> + <groupId>org.amdatu.web</groupId> + <artifactId>org.amdatu.web.dispatcher</artifactId> + <type>bundle</type> + </dependency> + <dependency> + <groupId>org.amdatu.web</groupId> + <artifactId>org.amdatu.web.httpcontext</artifactId> + <type>bundle</type> + </dependency> + <dependency> + <groupId>org.amdatu.web</groupId> + <artifactId>org.amdatu.web.jsp</artifactId> + <type>bundle</type> + </dependency> + <dependency> + <groupId>org.amdatu.web</groupId> + <artifactId>org.amdatu.web.resource</artifactId> + <type>bundle</type> + </dependency> + <dependency> + <groupId>org.amdatu.web</groupId> + <artifactId>org.amdatu.web.jaxrs</artifactId> + <type>bundle</type> + </dependency> + <dependency> + <groupId>org.amdatu.core</groupId> + <artifactId>org.amdatu.core.tenant</artifactId> + <type>bundle</type> + </dependency> + <dependency> + <groupId>org.amdatu.libraries</groupId> + <artifactId>org.amdatu.libraries.utilities</artifactId> + <scope>compile</scope> + </dependency> + <dependency> + <groupId>org.amdatu.opensocial</groupId> + <artifactId>org.amdatu.opensocial.shindig</artifactId> + <version>${amdatu.opensocial.version}</version> + <scope>provided</scope> + <type>bundle</type> + </dependency> + <dependency> + <groupId>org.amdatu.opensocial</groupId> + <artifactId>org.amdatu.opensocial.gadgetmanagement</artifactId> + <version>${amdatu.opensocial.version}</version> + <scope>provided</scope> + <type>bundle</type> + </dependency> + <dependency> + <groupId>org.json</groupId> + <artifactId>json</artifactId> + <version>20090211</version> + <scope>compile</scope> + </dependency> + <dependency> + <groupId>javax.servlet</groupId> + <artifactId>servlet-api</artifactId> + <scope>provided</scope> + </dependency> + </dependencies> + + <build> + <plugins> + <plugin> + <groupId>org.apache.felix</groupId> + <artifactId>maven-bundle-plugin</artifactId> + <configuration> + <instructions> + <Bundle-Activator>org.amdatu.opensocial.tenant.gadget.osgi.Activator</Bundle-Activator> + <Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName> + <Embed-Dependency>*;scope=compile</Embed-Dependency> + <Embed-Transitive>true</Embed-Transitive> + <Export-Package></Export-Package> + </instructions> + </configuration> + </plugin> + </plugins> + </build> + + <profiles> + <profile> + <!-- Profile that will copy the jar to the configured amdatu.deploy.directory when + the deploy profile is activated --> + <id>deploy</id> + <activation> + <activeByDefault>false</activeByDefault> + </activation> + <build> + <defaultGoal>install</defaultGoal> + <plugins> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-antrun-plugin</artifactId> + </plugin> + </plugins> + </build> + </profile> + </profiles> +</project> Added: sandbox/ivol/tenant-management-gadget/src/main/java/org/amdatu/opensocial/tenant/gadget/osgi/Activator.java ============================================================================== --- (empty file) +++ sandbox/ivol/tenant-management-gadget/src/main/java/org/amdatu/opensocial/tenant/gadget/osgi/Activator.java Tue Nov 1 17:02:08 2011 @@ -0,0 +1,99 @@ +/* + * Copyright (c) 2010, 2011 The Amdatu Foundation + * + * 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 org.amdatu.opensocial.tenant.gadget.osgi; + +import java.util.Dictionary; +import java.util.Hashtable; + +import org.amdatu.core.tenant.Tenant; +import org.amdatu.libraries.utilities.osgi.ServiceDependentActivator; +import org.amdatu.opensocial.gadgetmanagement.GadgetDefinitionProvider; +import org.amdatu.opensocial.tenant.gadget.service.TenantGadgetDefinition; +import org.amdatu.opensocial.tenant.gadget.service.TenantGadgetImpl; +import org.amdatu.opensocial.tenant.gadget.service.TenantRESTServiceImpl; +import org.amdatu.web.dispatcher.DispatcherService; +import org.amdatu.web.httpcontext.ResourceProvider; +import org.amdatu.web.jsp.JspSupport; +import org.amdatu.web.resource.ResourceSupport; +import org.amdatu.web.rest.jaxrs.JaxRsSpi; +import org.amdatu.web.rest.jaxrs.RESTService; +import org.apache.felix.dm.DependencyManager; +import org.osgi.framework.BundleContext; +import org.osgi.service.cm.ConfigurationAdmin; +import org.osgi.service.log.LogService; +import org.osgi.service.useradmin.UserAdmin; + +/** + * This is the OSGi activator for this gadget bundle. + * + * @author ivol + */ +public class Activator extends ServiceDependentActivator { + /** + * Context id of the Authorization HTTP Context. + */ + public static final String CONTEXTID = "amdatu-opensocial-tenant"; + + /** + * URL alias hosting the login gadget. + */ + public static final String ALIAS = "/tenant"; + + /** + * URL alias hosting the JSPs. + */ + public static final String JSP_ALIAS = ALIAS + "/jsp"; + + /** + * URL alias hosting the statics. + */ + public static final String RES_ALIAS = ALIAS + "/static"; + + protected Class<?>[] getRequiredServices() { + return new Class<?>[] {JaxRsSpi.class}; + } + + @Override + public void initWithDependencies(final BundleContext context, final DependencyManager manager) throws Exception { + + Dictionary<String, Object> properties = new Hashtable<String, Object>(); + properties.put(DispatcherService.CONTEXT_ID_KEY, CONTEXTID); + properties.put(JspSupport.JSP_ALIAS_KEY, JSP_ALIAS); + properties.put(ResourceSupport.RESOURCE_ALIAS_KEY, RES_ALIAS); + + manager.add(createComponent().setInterface(ResourceProvider.class.getName(), properties) + .setImplementation(TenantGadgetImpl.class) + .add(createServiceDependency().setService(LogService.class).setRequired(true)) + .add(createServiceDependency().setService(UserAdmin.class).setRequired(true))); + + // Register a login gadget definition for each tenant + manager.add(createAdapterService(Tenant.class, null) + .setInterface(GadgetDefinitionProvider.class.getName(), null) + .setImplementation(TenantGadgetDefinition.class)); + + // Create and register the REST tenant service + manager.add( + createAdapterService(Tenant.class, null) + .setInterface(new String[] {RESTService.class.getName()}, null) + .setImplementation(TenantRESTServiceImpl.class) + .add(createServiceDependency().setService(LogService.class).setRequired(true)) + .add(createServiceDependency().setService(ConfigurationAdmin.class).setRequired(true))); + } + + @Override + public void destroy(final BundleContext arg0, final DependencyManager arg1) throws Exception { + } +} Added: sandbox/ivol/tenant-management-gadget/src/main/java/org/amdatu/opensocial/tenant/gadget/service/TenantBean.java ============================================================================== --- (empty file) +++ sandbox/ivol/tenant-management-gadget/src/main/java/org/amdatu/opensocial/tenant/gadget/service/TenantBean.java Tue Nov 1 17:02:08 2011 @@ -0,0 +1,61 @@ +package org.amdatu.opensocial.tenant.gadget.service; + +import java.util.ArrayList; +import java.util.List; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlRootElement; + +import org.amdatu.libraries.utilities.rest.AtomSyndicationLink; + +@XmlRootElement(name = "tenant") +@XmlAccessorType(XmlAccessType.PUBLIC_MEMBER) +public class TenantBean { + private String m_id; + private String m_name; + private String m_hostname; + private AtomSyndicationLink m_link; + + public TenantBean() { + } + + public TenantBean(String id, String name, String hostname) { + m_id = id; + m_name = name; + m_hostname = hostname; + } + + public String getId() { + return m_id; + } + + public void setId(String id) { + m_id = id; + } + + public String getName() { + return m_name; + } + + public void setName(String name) { + m_name = name; + } + + public String getHostname() { + return m_hostname; + } + + public void setHostname(String hostname) { + m_hostname = hostname; + } + + public AtomSyndicationLink getLink() { + return m_link; + } + + public void setLink(final AtomSyndicationLink link) { + m_link = link; + } +} Added: sandbox/ivol/tenant-management-gadget/src/main/java/org/amdatu/opensocial/tenant/gadget/service/TenantGadgetDefinition.java ============================================================================== --- (empty file) +++ sandbox/ivol/tenant-management-gadget/src/main/java/org/amdatu/opensocial/tenant/gadget/service/TenantGadgetDefinition.java Tue Nov 1 17:02:08 2011 @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2010, 2011 The Amdatu Foundation + * + * 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 org.amdatu.opensocial.tenant.gadget.service; + +import org.amdatu.opensocial.gadgetmanagement.GadgetCategory; +import org.amdatu.opensocial.gadgetmanagement.GadgetDefinition; +import org.amdatu.opensocial.gadgetmanagement.GadgetDefinitionProvider; +import org.amdatu.opensocial.tenant.gadget.osgi.Activator; + +public class TenantGadgetDefinition implements GadgetDefinitionProvider { + public GadgetDefinition[] getDefinitions() { + return new GadgetDefinition[] {new GadgetDefinition( + Activator.ALIAS + "/jsp/TenantGadget.jsp", // gadget URL + GadgetCategory.AMDATU_PLATFORM, // category + true)}; // default visible on the dashboard + } +} Added: sandbox/ivol/tenant-management-gadget/src/main/java/org/amdatu/opensocial/tenant/gadget/service/TenantGadgetImpl.java ============================================================================== --- (empty file) +++ sandbox/ivol/tenant-management-gadget/src/main/java/org/amdatu/opensocial/tenant/gadget/service/TenantGadgetImpl.java Tue Nov 1 17:02:08 2011 @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2010, 2011 The Amdatu Foundation + * + * 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 org.amdatu.opensocial.tenant.gadget.service; + +import java.net.URL; + +import org.amdatu.opensocial.tenant.gadget.osgi.Activator; +import org.amdatu.web.httpcontext.ResourceProvider; +import org.osgi.framework.BundleContext; +import org.osgi.service.log.LogService; + +/** + * This service provides the login gadget. + * + * @author ivol + */ +public class TenantGadgetImpl implements ResourceProvider { + + // Service dependencies, injected by the Felix dependency manager + private volatile LogService m_logService; + private volatile BundleContext m_bundleContext; + + /** + * The init() method is invoked by the Felix dependency manager. + */ + public void start() { + m_logService.log(LogService.LOG_INFO, getClass().getName() + " service started"); + } + + public URL getResource(final String name) { + final String pathPrefix = Activator.ALIAS + "/"; + if (name != null && name.startsWith(pathPrefix)) { + return m_bundleContext.getBundle().getResource(name.substring(pathPrefix.length())); + } + return null; + } +} Added: sandbox/ivol/tenant-management-gadget/src/main/java/org/amdatu/opensocial/tenant/gadget/service/TenantRESTServiceImpl.java ============================================================================== --- (empty file) +++ sandbox/ivol/tenant-management-gadget/src/main/java/org/amdatu/opensocial/tenant/gadget/service/TenantRESTServiceImpl.java Tue Nov 1 17:02:08 2011 @@ -0,0 +1,139 @@ +/* + * Copyright (c) 2010, 2011 The Amdatu Foundation + * + * 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 org.amdatu.opensocial.tenant.gadget.service; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.Dictionary; +import java.util.Enumeration; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import javax.servlet.http.HttpServletRequest; +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; +import javax.ws.rs.WebApplicationException; +import javax.ws.rs.core.CacheControl; +import javax.ws.rs.core.Context; +import javax.ws.rs.core.HttpHeaders; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; + +import org.amdatu.core.tenant.Tenant; +import org.amdatu.core.tenant.TenantManagementService; +import org.amdatu.libraries.utilities.rest.AtomSyndicationLink; +import org.amdatu.web.rest.jaxrs.RESTService; +import org.osgi.service.cm.Configuration; +import org.osgi.service.cm.ConfigurationAdmin; +import org.osgi.service.log.LogService; + +@Path("tenants") +public class TenantRESTServiceImpl implements RESTService { + // HTTP caching for this REST interface + protected static CacheControl NO_CACHE_CONTROL; + static { + NO_CACHE_CONTROL = new CacheControl(); + NO_CACHE_CONTROL.setNoCache(true); // No cache + } + + private ConfigurationAdmin m_configAdmin; + private LogService m_logService; + + public void start() { + m_logService.log(LogService.LOG_INFO, "Tenant management REST service started"); + } + + @GET + @Produces({ MediaType.APPLICATION_JSON }) + public Response getTenants(@Context final HttpHeaders headers, @Context final HttpServletRequest request) { + TenantsBean tenantsBean = new TenantsBean(); + try { + for (Tenant tenant : getTenants()) { + TenantBean tenantBean = new TenantBean(); + tenantBean.setId(tenant.getId()); + tenantBean.setName(tenant.getName()); + tenantBean.setHostname(tenant.getProperties().get(Tenant.HOSTNAME_PROPERTY)); + String href = request.getContextPath() + "/rest/tenant/" + tenant.getId(); + tenantBean.setLink(new AtomSyndicationLink().setHref(href).setRel("Alternate") + .setType("application/json")); + tenantsBean.addTenant(tenantBean); + } + } + catch (Exception e) { + throw new WebApplicationException(e, Response.Status.INTERNAL_SERVER_ERROR); + } + + return Response.ok(tenantsBean, MediaType.APPLICATION_JSON_TYPE).cacheControl(NO_CACHE_CONTROL) + .build(); + } + + @GET + @Path("/{id}") + @Produces({ MediaType.APPLICATION_JSON }) + public Response getTenant(@Context final HttpHeaders headers, @Context final HttpServletRequest request) { + TenantBean tenant = null; + try { + Configuration config = m_configAdmin.getConfiguration(TenantManagementService.PID); + Dictionary properties = config.getProperties(); + Enumeration keys = properties.keys(); + while (keys.hasMoreElements()) { + String key = keys.nextElement().toString(); + if (key.endsWith(".id")) { + tenant = getTenant(key.substring(0, key.lastIndexOf(".id"))); + } + } + } + catch (Exception e) { + throw new WebApplicationException(e, Response.Status.INTERNAL_SERVER_ERROR); + } + + if (tenant == null) { + return Response.noContent().cacheControl(NO_CACHE_CONTROL).build(); + } + + return Response.ok(tenant, MediaType.APPLICATION_JSON_TYPE).cacheControl(NO_CACHE_CONTROL) + .build(); + } + + private List<TenantBean> getTenants() throws IOException { + Configuration config = m_configAdmin.getConfiguration(TenantManagementService.PID); + Dictionary properties = config.getProperties(); + List<TenantBean> tenants = new ArrayList<TenantBean>(); + int keyId = 1; + String key = "tenant" + keyId; + boolean exists = properties.get(key + ".id") != null; + while (exists) { + tenants.add(getTenant(key)); + keyId++; + key = "tenant" + keyId; + exists = properties.get(key + ".id") != null; + } + return tenants; + } + + private TenantBean getTenant(String key) throws IOException { + Configuration config = m_configAdmin.getConfiguration(TenantManagementService.PID); + Dictionary properties = config.getProperties(); + String id = properties.get(key + ".id").toString(); + String name = properties.get(key + ".name").toString(); + String hostname = properties.get(key + ".properties.hostname").toString(); + Map<String, String> dic = new HashMap<String, String>(); + dic.put(Tenant.HOSTNAME_PROPERTY, hostname); + return new TenantBean(id, name, hostname); + } +} Added: sandbox/ivol/tenant-management-gadget/src/main/java/org/amdatu/opensocial/tenant/gadget/service/TenantsBean.java ============================================================================== --- (empty file) +++ sandbox/ivol/tenant-management-gadget/src/main/java/org/amdatu/opensocial/tenant/gadget/service/TenantsBean.java Tue Nov 1 17:02:08 2011 @@ -0,0 +1,31 @@ +package org.amdatu.opensocial.tenant.gadget.service; + +import java.util.ArrayList; +import java.util.List; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlRootElement; + +@XmlRootElement(name = "tenants") +@XmlAccessorType(XmlAccessType.PUBLIC_MEMBER) +public class TenantsBean { + private List<TenantBean> m_tenants; + + @XmlElement(name = "tenant") + public List<TenantBean> getTenants() { + return m_tenants; + } + + public void setTenants(final List<TenantBean> tenant) { + m_tenants = tenant; + } + + public void addTenant(TenantBean tenant) { + if (m_tenants == null) { + m_tenants = new ArrayList<TenantBean>(); + } + m_tenants.add(tenant); + } +} Added: sandbox/ivol/tenant-management-gadget/src/main/resources/jsp/TenantGadget.jsp ============================================================================== --- (empty file) +++ sandbox/ivol/tenant-management-gadget/src/main/resources/jsp/TenantGadget.jsp Tue Nov 1 17:02:08 2011 @@ -0,0 +1,60 @@ +<%-- + Copyright (c) 2010, 2011 The Amdatu Foundation + + 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.verning permissions and limitations + under the License. +--%> + +<%@ page language="java" session="false" buffer="none" %> +<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> + +<c:set var="contextPath" value="${pageContext.request.contextPath}"/> +<c:set var="baseRestUrl" value="${contextPath}/rest/tenant"/> +<c:set var="gadgetBaseUrl" value="${contextPath}/tenant"/> + +<?xml version="1.0" encoding="UTF-8" ?> +<Module> + <ModulePrefs + title="Amdatu Tenant Management Gadget" + description="Tenant manager for Administrators" + author="Ivo Ladage-van Doorn" + screenshot="${gadgetBaseUrl}/static/images/tenant.jpg" + icon="${gadgetBaseUrl}/static/images/tenant.jpg" + height="400"> + <Require feature="osapi"/> + <Require feature="dynamic-height"/> + + <Locale messages="${gadgetBaseUrl}/static/labels/tenantmgmt_ALL_ALL.xml" /> + </ModulePrefs> + <Content type="html"> + <![CDATA[ + <link rel="stylesheet" href="${contextPath}/dashboard/static/css/dashboard.css"> + <link rel="stylesheet" href="${gadgetBaseUrl}/static/css/tenant.css"> + + <script type="text/javascript" src="${contextPath}/dashboard/static/js/lib/jquery-1.4.2.min.js"></script> + <script type="text/javascript" src="${contextPath}/dashboard/static/js/lib/jquery-ui-1.8.2.custom.min.js"></script> + <script type="text/javascript" src="${gadgetBaseUrl}/static/js/tenant.js"></script> + + <fieldset id="tenants"> + <legend id="tenants_legend">__MSG_tenants__</legend> + <div id="tenants"></div> + </fieldset> + + <script type="text/javascript"> + var contextPath = "${contextPath}"; + + loadTenants(); + </script> + ]]> + </Content> +</Module> Added: sandbox/ivol/tenant-management-gadget/src/main/resources/static/css/tenant.css ============================================================================== --- (empty file) +++ sandbox/ivol/tenant-management-gadget/src/main/resources/static/css/tenant.css Tue Nov 1 17:02:08 2011 @@ -0,0 +1,81 @@ +/* + Copyright (c) 2010, 2011 The Amdatu Foundation + + 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.verning permissions and limitations + under the License. +*/ + +body { + background: #fff; +} + +table td { + vertical-align: top; + max-width: 280px; + _width: 280px; /* IE */ + white-space: pre; /* CSS 2.0 */ + white-space: pre-wrap; /* CSS 2.1 */ + white-space: pre-line; /* CSS 3.0 */ + white-space: -pre-wrap; /* Opera 4-6 */ + white-space: -o-pre-wrap; /* Opera 7 */ + white-space: -moz-pre-wrap; /* Mozilla */ + white-space: -hp-pre-wrap; /* HP Printers */ + word-wrap: break-word; /* IE 5+ */ +} + +table.stripeMe { + border-collapse: collapse; + font-size: 1.1em; + width: 100%; +} + +table.stripeMe th { + background: #3e83c9; + color: #fff; + font-weight: bold; + padding: 2px 11px; + text-align: left; + border-right: 1px solid #fff; + line-height: 1.2; +} + +table.stripeMe td { + padding: 2px 1px; + border-bottom: 1px solid #95bce2; + vertical-align: top; +} + +table.stripeMe td * { + padding: 2px 1px; + vertical-align: top; +} + +table.stripeMe tr.alt td { + background: #ecf6fc; +} + +table.stripeMe tr.over td { + background: #bcd4ec; +} + +fieldset { + border: 1px solid #d0ccc9; +} + +fieldset legend { + font-size: 0.8em; +} + +img.mouseover { + cursor:hand; +} Added: sandbox/ivol/tenant-management-gadget/src/main/resources/static/images/remove.gif ============================================================================== Binary file. No diff available. Added: sandbox/ivol/tenant-management-gadget/src/main/resources/static/images/tenant.jpg ============================================================================== Binary file. No diff available. Added: sandbox/ivol/tenant-management-gadget/src/main/resources/static/js/tenant.js ============================================================================== --- (empty file) +++ sandbox/ivol/tenant-management-gadget/src/main/resources/static/js/tenant.js Tue Nov 1 17:02:08 2011 @@ -0,0 +1,94 @@ +var prefs = new gadgets.Prefs(); + +function loadTenants() { + var url = "/rest/tenants"; + var params = {}; + params[gadgets.io.RequestParameters.CONTENT_TYPE] = gadgets.io.ContentType.JSON; + params[gadgets.io.RequestParameters.METHOD] = gadgets.io.MethodType.GET; + + url = getBaseUrl() + addNoCache(url); + gadgets.io.makeRequest(url, onTenantsLoaded, params); +} + +function loadTenant(url, callback) { + var params = {}; + params[gadgets.io.RequestParameters.CONTENT_TYPE] = gadgets.io.ContentType.JSON; + params[gadgets.io.RequestParameters.METHOD] = gadgets.io.MethodType.GET; + url = getBaseUrl() + addNoCache(unescape(url)); + gadgets.io.makeRequest(url, callback, params); +} + +function addNoCache(url) { + var ts = new Date().getTime(); + if (url.indexOf("?") == -1) { + url += "?nocache=" + ts; + } else { + url += "&nocache=" + ts; + } + return url; +} + +function getBaseUrl() { + return window.location.protocol +"//" + window.location.hostname + ":" + window.location.port; +} + +function onTenantsLoaded(response) { + if (response.rc == 200) { + var html = "<p><center><table class='stripeMe'>"; + html += "<tr><th width='80%'>" + prefs.getMsg('tenant') + "</th><th width='20%'>" + prefs.getMsg('delete') + "</th></tr>"; + + var tenantHolder = response.data["tenants"]; + var tenants = ensureArray(tenantHolder["tenant"]); + + for (i=0; i<tenants.length; i++) { + var id = tenants[i]["id"]; + var name = tenants[i]["name"]; + var hostname = tenants[i]["hostname"]; + var link = tenants[i]["link"].href; + + var editTenant = " onclick=\"javascript:editTenant('" + escape(link) + "');\""; + var deleteTentant = " onclick=\"javascript:confirmDeleteTenant('" + escape(link) + "', '" + escape(name) + "');\""; + + html += "<tr><td><a href='#'" + "" + ">" + name + " (" + hostname + ")</a></td>"; + html += "<td align='center'><a href='#'><img src='" + contextPath + "/tenant/static/images/remove.gif'" + deleteTenant + "/></a></td></tr>"; + } + html += "</table></center></p>"; + + var tenantsDiv = document.getElementById("tenants"); + tenantsDiv.innerHTML = html; + + // make the table zebra-style + $(".stripeMe tr").mouseover(function() {$(this).addClass("over");}); + $(".stripeMe tr").mouseout(function() {$(this).removeClass("over");}); + $(".stripeMe tr:even").addClass("alt"); + } + gadgets.window.adjustHeight(); +} + + + +function editTenant(link) { + loadTenant(escape(unescape(link)), onTenantLoaded); + showEditTenant(); +} + + +function deleteTenant() { + +} + +function confirmDeleteTenant(tenant) { + alert('confirm'); +} + +function ensureArray(input) { + // check if this result is an array + if (jQuery.isArray(input)) { + return input; + } + var result = []; + if (input != null) { + result.push(input); + } + return result; +} \ No newline at end of file Added: sandbox/ivol/tenant-management-gadget/src/main/resources/static/labels/tenantmgmt_ALL_ALL.xml ============================================================================== --- (empty file) +++ sandbox/ivol/tenant-management-gadget/src/main/resources/static/labels/tenantmgmt_ALL_ALL.xml Tue Nov 1 17:02:08 2011 @@ -0,0 +1,34 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + Copyright (c) 2010, 2011 The Amdatu Foundation + + 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.verning permissions and limitations + under the License. +--> +<messagebundle> + <msg name="tenants">Tenants</msg> + <msg name="tenant">Tenant</msg> + + <msg name="new_tenant">New tenant</msg> + <msg name="details">Details</msg> + + <msg name="save">Save</msg> + <msg name="cancel">Cancel</msg> + <msg name="delete">Delete</msg> + + <msg name="unauthorized">You do not have authorization to manage users and groups.</msg> + <msg name="accessdenied">You do not have proper authorization to perform this action.</msg> + <msg name="unexpected_error">An unexpected error has occurred: </msg> + + <msg name="confirm_delete">Are you sure you want to delete '%s'?</msg> +</messagebundle> \ No newline at end of file _______________________________________________ Amdatu-commits mailing list [email protected] http://lists.amdatu.org/mailman/listinfo/amdatu-commits
