Merge branch 'application-mgt' of github.com:wso2/carbon-device-mgt into application-mgt

feature/appm-store/pbac
Chatura Dilan 8 years ago
commit c957894acb

@ -1,6 +1,8 @@
# carbon-device-mgt
<a href='https://wso2.org/jenkins/job/platform-builds/job/carbon-device-mgt/'><img src='https://wso2.org/jenkins/job/platform-builds/job/carbon-device-mgt/badge/icon'></a>
<a href='https://opensource.org/licenses/Apache-2.0'><img src='https://img.shields.io/badge/License-Apache%202.0-blue.svg'></a><br/>
<a href='https://wso2.org/jenkins/job/platform-builds/job/carbon-device-mgt/'><img src='https://wso2.org/jenkins/job/platform-builds/job/carbon-device-mgt/badge/icon'></a> - Java7<br/>
<a href='https://wso2.org/jenkins/job/platform-builds/job/carbon-device-mgt__java8/'><img src='https://wso2.org/jenkins/job/platform-builds/job/carbon-device-mgt__java8/badge/icon'></a> - Java8
WSO2 CONNECTED DEVICE MANAGEMENT COMPONENTS

@ -22,13 +22,13 @@
<parent>
<artifactId>apimgt-extensions</artifactId>
<groupId>org.wso2.carbon.devicemgt</groupId>
<version>2.0.45-SNAPSHOT</version>
<version>2.0.63-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>org.wso2.carbon.apimgt.annotations</artifactId>
<version>2.0.45-SNAPSHOT</version>
<version>2.0.63-SNAPSHOT</version>
<packaging>bundle</packaging>
<name>WSO2 Carbon - API Management Annotations</name>
<description>WSO2 Carbon - API Management Custom Annotation Module</description>

@ -21,12 +21,12 @@
<parent>
<artifactId>apimgt-extensions</artifactId>
<groupId>org.wso2.carbon.devicemgt</groupId>
<version>2.0.45-SNAPSHOT</version>
<version>2.0.63-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
<version>2.0.45-SNAPSHOT</version>
<version>2.0.63-SNAPSHOT</version>
<artifactId>org.wso2.carbon.apimgt.application.extension.api</artifactId>
<packaging>war</packaging>
<name>WSO2 Carbon - API Application Management API</name>

@ -47,6 +47,7 @@ public class ApiPermissionFilter implements Filter {
private static final String PERMISSION_PREFIX = "/permission/admin";
private static List<Permission> permissions;
private static final String WEBAPP_CONTEXT = "/api-application-registration";
private static final String DEFAULT_ADMIN_ROLE = "admin";
@Override
public void init(FilterConfig filterConfig) throws ServletException {
InputStream permissionStream = filterConfig.getServletContext().getResourceAsStream(PERMISSION_CONFIG_PATH);
@ -122,7 +123,17 @@ public class ApiPermissionFilter implements Filter {
UserRealm userRealm = APIUtil.getRealmService().getTenantUserRealm(PrivilegedCarbonContext
.getThreadLocalCarbonContext().getTenantId());
String tenantAwareUsername = MultitenantUtils.getTenantAwareUsername(username);
return userRealm.getAuthorizationManager().isUserAuthorized(tenantAwareUsername, permission, action);
boolean status = userRealm.getAuthorizationManager()
.isUserAuthorized(tenantAwareUsername, permission, action);
if (!status) {
String[] roles = userRealm.getUserStoreManager().getRoleListOfUser(tenantAwareUsername);
for (String role : roles) {
if (role.equals(DEFAULT_ADMIN_ROLE)) {
return true;
}
}
}
return status;
} catch (UserStoreException e) {
String errorMsg = String.format("Unable to authorize the user : %s", username);
log.error(errorMsg, e);

@ -59,6 +59,43 @@
<filter-name>ApiPermissionFilter</filter-name>
<filter-class>org.wso2.carbon.apimgt.application.extension.api.filter.ApiPermissionFilter</filter-class>
</filter>
<filter>
<filter-name>HttpHeaderSecurityFilter</filter-name>
<filter-class>org.apache.catalina.filters.HttpHeaderSecurityFilter</filter-class>
<init-param>
<param-name>hstsEnabled</param-name>
<param-value>false</param-value>
</init-param>
</filter>
<filter>
<filter-name>ContentTypeBasedCachePreventionFilter</filter-name>
<filter-class>org.wso2.carbon.ui.filters.cache.ContentTypeBasedCachePreventionFilter</filter-class>
<init-param>
<param-name>patterns</param-name>
<param-value>text/html" ,application/json" ,text/plain</param-value>
</init-param>
<init-param>
<param-name>filterAction</param-name>
<param-value>enforce</param-value>
</init-param>
<init-param>
<param-name>httpHeaders</param-name>
<param-value>Cache-Control: no-store, no-cache, must-revalidate, private</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>HttpHeaderSecurityFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>ContentTypeBasedCachePreventionFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>ApiPermissionFilter</filter-name>
<url-pattern>/*</url-pattern>

@ -22,12 +22,12 @@
<parent>
<artifactId>apimgt-extensions</artifactId>
<groupId>org.wso2.carbon.devicemgt</groupId>
<version>2.0.45-SNAPSHOT</version>
<version>2.0.63-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
<version>2.0.45-SNAPSHOT</version>
<version>2.0.63-SNAPSHOT</version>
<artifactId>org.wso2.carbon.apimgt.application.extension</artifactId>
<packaging>bundle</packaging>
<name>WSO2 Carbon - API Application Management</name>

@ -26,6 +26,12 @@ import org.wso2.carbon.apimgt.application.extension.exception.APIManagerExceptio
*/
public interface APIManagementProviderService {
/**
* Check whether the tier is loaded for the tenant.
* @return
*/
boolean isTierLoaded();
/**
* Generate and retreive application keys. if the application does exist then
* create it and subscribe to apis that are grouped with the tags.

@ -45,8 +45,22 @@ public class APIManagementProviderServiceImpl implements APIManagementProviderSe
private static final String CONTENT_TYPE = "application/json";
private static final int MAX_API_PER_TAG = 200;
private static final String APP_TIER_TYPE = "application";
private static final Map<String, String> tiersMap = new HashMap<>();
private static final int MAX_ATTEMPTS = 20;
public boolean isTierLoaded() {
StoreClient storeClient = APIApplicationManagerExtensionDataHolder.getInstance().getIntegrationClientService()
.getStoreClient();
String tenantDomain = PrivilegedCarbonContext.getThreadLocalCarbonContext()
.getTenantDomain();
try {
storeClient.getIndividualTier().tiersTierLevelTierNameGet(ApiApplicationConstants.DEFAULT_TIER,
APP_TIER_TYPE,
tenantDomain, CONTENT_TYPE, null, null);
return true;
} catch (FeignException e) {
return false;
}
}
@Override
public void removeAPIApplication(String applicationName, String username) throws APIManagerException {
@ -72,31 +86,8 @@ public class APIManagementProviderServiceImpl implements APIManagementProviderSe
throws APIManagerException {
StoreClient storeClient = APIApplicationManagerExtensionDataHolder.getInstance().getIntegrationClientService()
.getStoreClient();
//This is a fix to avoid race condition and trying to load tenant related tiers before invocation.
String tenantDomain = PrivilegedCarbonContext.getThreadLocalCarbonContext()
.getTenantDomain();
String tiersLoadedForTenant = tiersMap.get(tenantDomain);
if (tiersLoadedForTenant == null) {
boolean tierLoaded = false;
int attempts = 0;
do {
try {
storeClient.getIndividualTier()
.tiersTierLevelTierNameGet(ApiApplicationConstants.DEFAULT_TIER, APP_TIER_TYPE,
tenantDomain, CONTENT_TYPE, null, null);
tiersMap.put(tenantDomain, "exist");
tierLoaded = true;
} catch (FeignException e) {
attempts++;
try {
Thread.sleep(500);
} catch (InterruptedException ex) {
log.warn("Interrupted the waiting for tier availability.");
}
}
} while ((!tierLoaded) && attempts < MAX_ATTEMPTS);
}
ApplicationList applicationList = storeClient.getApplications()
.applicationsGet("", applicationName, 1, 0, CONTENT_TYPE, null);

@ -21,13 +21,13 @@
<parent>
<artifactId>apimgt-extensions</artifactId>
<groupId>org.wso2.carbon.devicemgt</groupId>
<version>2.0.45-SNAPSHOT</version>
<version>2.0.63-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>org.wso2.carbon.apimgt.handlers</artifactId>
<version>2.0.45-SNAPSHOT</version>
<version>2.0.63-SNAPSHOT</version>
<packaging>bundle</packaging>
<name>WSO2 Carbon - API Security Handler Component</name>
<description>WSO2 Carbon - API Management Security Handler Module</description>
@ -76,6 +76,7 @@
<Bundle-Description>WSO2 Carbon - API Security Handler Component</Bundle-Description>
<Import-Package>
org.apache.axiom.*,
javax.security.cert.*,
javax.xml.parsers;version="${javax.xml.parsers.import.pkg.version}";resolution:=optional,
javax.xml.*,
org.apache.axis2.*,
@ -90,7 +91,8 @@
org.w3c.dom,
org.apache.synapse,
org.apache.synapse.core.axis2,
org.apache.synapse.rest
org.apache.synapse.rest,
org.wso2.carbon.certificate.mgt.core.impl
</Import-Package>
</instructions>
</configuration>

@ -31,11 +31,17 @@ import org.wso2.carbon.apimgt.handlers.invoker.RESTInvoker;
import org.wso2.carbon.apimgt.handlers.invoker.RESTResponse;
import org.wso2.carbon.apimgt.handlers.utils.AuthConstants;
import org.wso2.carbon.apimgt.handlers.utils.Utils;
import org.wso2.carbon.certificate.mgt.core.impl.CertificateGenerator;
import org.wso2.carbon.context.PrivilegedCarbonContext;
import javax.security.cert.CertificateEncodingException;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.security.cert.CertificateException;
import java.security.cert.CertificateFactory;
import java.security.cert.X509Certificate;
import java.util.HashMap;
import java.util.Map;
import java.util.StringTokenizer;
@ -140,6 +146,21 @@ public class AuthenticationHandler extends AbstractHandler {
if (log.isDebugEnabled()) {
log.debug("Verify response:" + response.getContent());
}
} else if (headers.containsKey(AuthConstants.MUTUAL_AUTH_HEADER)) {
javax.security.cert.X509Certificate[] certs =
(javax.security.cert.X509Certificate[]) axisMC.getProperty(AuthConstants.CLIENT_CERTIFICATE);
CertificateFactory cf = CertificateFactory.getInstance("X.509");
ByteArrayInputStream bais = new ByteArrayInputStream(certs[0].getEncoded());
X509Certificate x509 = (X509Certificate) cf.generateCertificate(bais);
if (bais != null) {
bais.close();
}
if (x509 != null) {
headers.put(AuthConstants.PROXY_MUTUAL_AUTH_HEADER, CertificateGenerator.getCommonName(x509));
return true;
} else {
response = null;
}
} else if (headers.containsKey(AuthConstants.ENCODED_PEM)) {
String encodedPem = headers.get(AuthConstants.ENCODED_PEM).toString();
if (log.isDebugEnabled()) {
@ -178,8 +199,13 @@ public class AuthenticationHandler extends AbstractHandler {
} catch (APIMCertificateMGTException e) {
log.error("Error while processing certificate.", e);
return false;
} catch (CertificateException e) {
log.error("Certificate issue occurred when generating converting PEM to x509Certificate", e);
return false;
} catch (CertificateEncodingException e) {
log.error("Error while attempting to encode certificate.", e);
return false;
}
}
@Override
@ -205,4 +231,4 @@ public class AuthenticationHandler extends AbstractHandler {
map.put(CONTENT_TYPE, "application/json");
return map;
}
}
}

@ -24,14 +24,12 @@ package org.wso2.carbon.apimgt.handlers.beans;
*/
public class DCR {
// Owner of the application
private String callbackUrl;
private String owner;
// Client name
private String clientName;
// Oauth Grant type
private String grantType;
// Scope of the token
private String tokenScope;
private boolean isSaasApp;
public String getOwner() {
return owner;
@ -64,5 +62,27 @@ public class DCR {
public void setTokenScope(String tokenScope) {
this.tokenScope = tokenScope;
}
public boolean getIsSaasApp() {
return isSaasApp;
}
public void setIsSaasApp(boolean isSaasApp) {
this.isSaasApp = isSaasApp;
}
public String getCallbackUrl() {
return callbackUrl;
}
public void setCallbackUrl(String callbackUrl) {
this.callbackUrl = callbackUrl;
}
public String toJSON() {
return "{\"callbackUrl\": \"" + callbackUrl + "\",\"clientName\": \"" + clientName + "\", \"tokenScope\": " +
"\"" + tokenScope + "\", \"owner\": \"" + owner + "\"," + "\"grantType\": \"" + grantType +
"\", \"saasApp\" :" + isSaasApp + " }\n";
}
}

@ -35,5 +35,17 @@ public class AuthConstants {
// public static final String ANDROID_VERIFY_ENDPOINT = "android-verify-endpoint";
public static final String MDM_SIGNATURE = "mdm-signature";
public static final String PROXY_MUTUAL_AUTH_HEADER = "proxy-mutual-auth-header";
public static final String MUTUAL_AUTH_HEADER = "mutual-auth-header";
public static final String ENCODED_PEM = "encoded-pem";
public static final String CALLBACK_URL = "";
public static final String CLIENT_NAME = "IOT-API-MANAGER";
public static final String GRANT_TYPE = "refresh_token password client_credentials";
public static final String TOKEN_SCOPE = "default";
public static final String CONTENT_TYPE_HEADER = "Content-Type";
public static final String CONTENT_TYPE = "application/json";
public static final String AUTHORIZATION_HEADER = "Authorization";
public static final String BASIC_AUTH_PREFIX = "Basic ";
public static final String CLIENT_ID = "clientId";
public static final String CLIENT_SECRET = "clientSecret";
public static final String CLIENT_CERTIFICATE = "ssl.client.auth.cert.X509";
}

@ -19,7 +19,6 @@
package org.wso2.carbon.apimgt.handlers.utils;
import com.google.gson.Gson;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.ws.security.util.Base64;
@ -118,8 +117,7 @@ public class Utils {
tokenHeaders.put("Content-Type", "application/x-www-form-urlencoded");
RESTInvoker restInvoker = new RESTInvoker();
RESTResponse response = restInvoker.invokePOST(tokenUrl, tokenHeaders, null,
null, tokenContent);
RESTResponse response = restInvoker.invokePOST(tokenUrl, tokenHeaders, null, null, tokenContent);
if(log.isDebugEnabled()) {
log.debug("Token response:" + response.getContent());
}
@ -144,31 +142,32 @@ public class Utils {
private static void getClientSecretes(IOTServerConfiguration iotServerConfiguration)
throws APIMCertificateMGTException {
try {
String username = iotServerConfiguration.getUsername();
String password = iotServerConfiguration.getPassword();
DCR dcr = new DCR();
dcr.setOwner(iotServerConfiguration.getUsername());
dcr.setClientName("IOT-API-MANAGER");
dcr.setGrantType("refresh_token password client_credentials");
dcr.setTokenScope("default");
Gson gson = new Gson();
String dcrContent = gson.toJson(dcr);
Map<String, String> drcHeaders = new HashMap<String, String>();
drcHeaders.put("Content-Type", "application/json");
dcr.setClientName(AuthConstants.CLIENT_NAME);
dcr.setGrantType(AuthConstants.GRANT_TYPE);
dcr.setTokenScope(AuthConstants.TOKEN_SCOPE);
dcr.setCallbackUrl(AuthConstants.CALLBACK_URL);
dcr.setIsSaasApp(true);
String dcrContent = dcr.toJSON();
Map<String, String> dcrHeaders = new HashMap<String, String>();
String basicAuth = Base64.encode((username + ":" + password).getBytes());
dcrHeaders.put(AuthConstants.CONTENT_TYPE_HEADER, AuthConstants.CONTENT_TYPE);
dcrHeaders.put(AuthConstants.AUTHORIZATION_HEADER, AuthConstants.BASIC_AUTH_PREFIX + basicAuth);
URI dcrUrl = new URI(iotServerConfiguration.getDynamicClientRegistrationEndpoint());
RESTInvoker restInvoker = new RESTInvoker();
RESTResponse response = restInvoker.invokePOST(dcrUrl, drcHeaders, null,
null, dcrContent);
RESTResponse response = restInvoker.invokePOST(dcrUrl, dcrHeaders, null, null, dcrContent);
if (log.isDebugEnabled()) {
log.debug("DCR response :" + response.getContent());
}
JSONObject jsonResponse = new JSONObject(response.getContent());
clientId = jsonResponse.getString("client_id");
clientSecret = jsonResponse.getString("client_secret");
clientId = jsonResponse.getString(AuthConstants.CLIENT_ID);
clientSecret = jsonResponse.getString(AuthConstants.CLIENT_SECRET);
} catch (JSONException e) {
throw new APIMCertificateMGTException("Error occurred while converting the json to object", e);
} catch (IOException e) {
throw new APIMCertificateMGTException("Error occurred while trying to call DCR endpoint", e);
} catch (URISyntaxException e) {
} catch (IOException | URISyntaxException e) {
throw new APIMCertificateMGTException("Error occurred while trying to call DCR endpoint", e);
}

@ -13,13 +13,13 @@
<parent>
<artifactId>apimgt-extensions</artifactId>
<groupId>org.wso2.carbon.devicemgt</groupId>
<version>2.0.45-SNAPSHOT</version>
<version>2.0.63-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>org.wso2.carbon.apimgt.integration.client</artifactId>
<version>2.0.45-SNAPSHOT</version>
<version>2.0.63-SNAPSHOT</version>
<packaging>bundle</packaging>
<name>WSO2 Carbon - API Management Integration Client</name>
<description>WSO2 Carbon - API Management Integration Client</description>

@ -19,7 +19,9 @@ package org.wso2.carbon.apimgt.integration.client.store;
import feign.Feign;
import feign.Logger;
import feign.Request;
import feign.RequestInterceptor;
import feign.Retryer;
import feign.gson.GsonDecoder;
import feign.gson.GsonEncoder;
import feign.slf4j.Slf4jLogger;
@ -28,6 +30,8 @@ import org.wso2.carbon.apimgt.integration.client.configs.APIMConfigReader;
import org.wso2.carbon.apimgt.integration.generated.client.store.api.*;
import org.wso2.carbon.core.util.Utils;
import java.util.concurrent.TimeUnit;
/**
* API Store client, created using swagger gen.
*/
@ -62,8 +66,10 @@ public class StoreClient {
individualSubscription = builder.target(SubscriptionIndividualApi.class, basePath);
subscriptionMultitpleApi = builder.target(SubscriptionMultitpleApi.class, basePath);
tags = builder.target(TagCollectionApi.class, basePath);
tiers = builder.target(ThrottlingTierCollectionApi.class, basePath);
individualTier = builder.target(ThrottlingTierIndividualApi.class, basePath);
tiers = builder.retryer(new Retryer.Default(100L, TimeUnit.SECONDS.toMillis(1L), 1))
.options(new Request.Options(10000, 5000))
.target(ThrottlingTierCollectionApi.class, basePath);
}

@ -13,13 +13,13 @@
<parent>
<artifactId>apimgt-extensions</artifactId>
<groupId>org.wso2.carbon.devicemgt</groupId>
<version>2.0.45-SNAPSHOT</version>
<version>2.0.63-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>org.wso2.carbon.apimgt.integration.generated.client</artifactId>
<version>2.0.45-SNAPSHOT</version>
<version>2.0.63-SNAPSHOT</version>
<packaging>bundle</packaging>
<name>WSO2 Carbon - API Management Integration Generated Client</name>
<description>WSO2 Carbon - API Management Integration Client</description>

@ -22,13 +22,13 @@
<parent>
<artifactId>apimgt-extensions</artifactId>
<groupId>org.wso2.carbon.devicemgt</groupId>
<version>2.0.45-SNAPSHOT</version>
<version>2.0.63-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>org.wso2.carbon.apimgt.webapp.publisher</artifactId>
<version>2.0.45-SNAPSHOT</version>
<version>2.0.63-SNAPSHOT</version>
<packaging>bundle</packaging>
<name>WSO2 Carbon - API Management Webapp Publisher</name>
<description>WSO2 Carbon - API Management Webapp Publisher</description>

@ -22,13 +22,13 @@
<parent>
<groupId>org.wso2.carbon.devicemgt</groupId>
<artifactId>carbon-devicemgt</artifactId>
<version>2.0.45-SNAPSHOT</version>
<version>2.0.63-SNAPSHOT</version>
<relativePath>../../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>apimgt-extensions</artifactId>
<version>2.0.45-SNAPSHOT</version>
<version>2.0.63-SNAPSHOT</version>
<packaging>pom</packaging>
<name>WSO2 Carbon - API Management Extensions Component</name>
<url>http://wso2.org</url>

@ -22,12 +22,13 @@
<parent>
<artifactId>application-mgt</artifactId>
<groupId>org.wso2.carbon.devicemgt</groupId>
<version>2.0.45-SNAPSHOT</version>
<version>2.0.63-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>org.wso2.carbon.device.application.mgt.api</artifactId>
<version>2.0.63-SNAPSHOT</version>
<packaging>war</packaging>
<name>WSO2 Carbon - Mobile Application Management API</name>
<description>WSO2 Carbon - Mobile Application Management API</description>
@ -46,7 +47,7 @@
<artifactId>maven-war-plugin</artifactId>
<configuration>
<packagingExcludes>WEB-INF/lib/*cxf*.jar</packagingExcludes>
<warName>api#application-mgt#v2.0</warName>
<warName>api#application-mgt#v1.0</warName>
</configuration>
</plugin>
</plugins>

@ -16,7 +16,7 @@
* under the License.
*
*/
package org.wso2.carbon.device.application.mgt.api.v2.beans;
package org.wso2.carbon.device.application.mgt.api.beans;
import com.fasterxml.jackson.annotation.JsonProperty;
import io.swagger.annotations.ApiModel;

@ -16,7 +16,7 @@
* under the License.
*
*/
package org.wso2.carbon.device.application.mgt.api.v2.beans;
package org.wso2.carbon.device.application.mgt.api.beans;
import com.fasterxml.jackson.annotation.JsonProperty;
import io.swagger.annotations.ApiModel;

@ -16,7 +16,7 @@
* under the License.
*/
package org.wso2.carbon.device.application.mgt.api.v2.common;
package org.wso2.carbon.device.application.mgt.api.common;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Response;

@ -16,7 +16,7 @@
* under the License.
*/
package org.wso2.carbon.device.application.mgt.api.v2.common;
package org.wso2.carbon.device.application.mgt.api.common;
/**
* Custom exception class for handling CDM API related exceptions.

@ -16,11 +16,11 @@
* under the License.
*
*/
package org.wso2.carbon.device.application.mgt.api.v2.apis;
package org.wso2.carbon.device.application.mgt.api.services;
import io.swagger.annotations.*;
import org.wso2.carbon.device.application.mgt.api.v2.beans.ErrorResponse;
import org.wso2.carbon.device.application.mgt.core.dto.lists.ApplicationList;
import org.wso2.carbon.device.application.mgt.api.beans.ErrorResponse;
import org.wso2.carbon.device.application.mgt.core.dto.ApplicationList;
import javax.ws.rs.*;
import javax.ws.rs.core.MediaType;
@ -30,7 +30,7 @@ import javax.ws.rs.core.Response;
"such as get all the available devices, etc.")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
public interface ApplicationManagementAPI {
public interface ApplicationManagementService {
public final static String SCOPE = "scope";
@ -90,4 +90,5 @@ public interface ApplicationManagementAPI {
);
}

@ -16,25 +16,25 @@
* under the License.
*
*/
package org.wso2.carbon.device.application.mgt.api.v2.apis.impl;
package org.wso2.carbon.device.application.mgt.api.services.impl;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.device.application.mgt.core.dto.lists.ApplicationList;
import org.wso2.carbon.device.application.mgt.core.dto.Filter;
import org.wso2.carbon.device.application.mgt.core.services.ApplicationManager;
import org.wso2.carbon.device.application.mgt.core.dto.lists.ApplicationList;
import org.wso2.carbon.device.application.mgt.core.util.ApplicationManagementUtil;
import org.wso2.carbon.device.application.mgt.core.services.ApplicationManager;
import javax.ws.rs.*;
import javax.ws.rs.core.Response;
@Produces({ "application/json"})
@Consumes({ "application/json"})
public class ApplicationManagementAPIImpl {
public class ApplicationManagementServiceImpl {
public static final int DEFAULT_LIMIT = 20;
private static Log log = LogFactory.getLog(ApplicationManagementAPIImpl.class);
private static Log log = LogFactory.getLog(ApplicationManagementServiceImpl.class);
@GET
@ -43,7 +43,6 @@ public class ApplicationManagementAPIImpl {
public Response getApplications(@QueryParam("offset") int offset, @QueryParam("limit") int limit,
@QueryParam("q") String searchQuery) {
ApplicationManager applicationManager = ApplicationManagementUtil.getApplicationManagementService();
try {
if(limit == 0){
@ -57,7 +56,6 @@ public class ApplicationManagementAPIImpl {
ApplicationList applications = applicationManager.getApplications(filter);
return Response.status(Response.Status.OK).entity(applications).build();
} catch (Exception e) {
String msg = "Error occurred while getting the application list";
log.error(msg, e);

@ -16,7 +16,7 @@ http://cxf.apache.org/jaxrs http://cxf.apache.org/schemas/jaxrs.xsd">
</jaxrs:providers>
</jaxrs:server>
<bean id="applicationMgtServiceBean" class="org.wso2.carbon.device.application.mgt.api.v2.apis.impl.ApplicationManagementAPIImpl"/>
<bean id="jsonProvider" class="org.wso2.carbon.device.application.mgt.api.v2.common.GsonMessageBodyHandler"/>
<bean id="applicationMgtServiceBean" class="org.wso2.carbon.device.application.mgt.api.services.impl.ApplicationManagementServiceImpl"/>
<bean id="jsonProvider" class="org.wso2.carbon.device.application.mgt.api.common.GsonMessageBodyHandler"/>
</beans>

@ -21,13 +21,13 @@
<parent>
<groupId>org.wso2.carbon.devicemgt</groupId>
<artifactId>application-mgt</artifactId>
<version>2.0.45-SNAPSHOT</version>
<version>2.0.63-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>org.wso2.carbon.device.application.mgt.core</artifactId>
<version>2.0.45-SNAPSHOT</version>
<version>2.0.63-SNAPSHOT</version>
<packaging>bundle</packaging>
<name>WSO2 Carbon - Application Management Core</name>
<description>WSO2 Carbon - Application Management Core</description>

@ -0,0 +1,44 @@
/*
* Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 Inc. 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.wso2.carbon.device.application.mgt.core.dto;
import java.util.List;
public class ApplicationList {
private List<Application> applications;
private Pagination pagination;
public List<Application> getApplications() {
return applications;
}
public void setApplications(List<Application> applications) {
this.applications = applications;
}
public Pagination getPagination() {
return pagination;
}
public void setPagination(Pagination pagination) {
this.pagination = pagination;
}
}

@ -0,0 +1,65 @@
/*
* Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 Inc. 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.wso2.carbon.device.application.mgt.core.dto;
import org.wso2.carbon.device.application.mgt.core.jaxrs.Exclude;
public class ApplicationType {
@Exclude
private int id;
private String name;
private String code;
private String parameters;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getCode() {
return code;
}
public void setCode(String code) {
this.code = code;
}
public String getParameters() {
return parameters;
}
public void setParameters(String parameters) {
this.parameters = parameters;
}
}

@ -0,0 +1,34 @@
#
# Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
#
# WSO2 Inc. 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.
#
#
# This is the log4j configuration file used by WSO2 Carbon
#
# IMPORTANT : Please do not remove or change the names of any
# of the Appender defined here. The layout pattern & log file
# can be changed using the WSO2 Carbon Management Console, and those
# settings will override the settings in this file.
#
log4j.rootLogger=DEBUG, STD_OUT
# Redirect log messages to console
log4j.appender.STD_OUT=org.apache.log4j.ConsoleAppender
log4j.appender.STD_OUT.Target=System.out
log4j.appender.STD_OUT.layout=org.apache.log4j.PatternLayout
log4j.appender.STD_OUT.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n

@ -0,0 +1,23 @@
<!--
~ Copyright (c) 2014, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
~
~ WSO2 Inc. 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.
-->
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
<suite name="ApplicationManagementCore">
</suite>

@ -0,0 +1,62 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Copyright (c) 2014, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
~
~ WSO2 Inc. 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.
-->
<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/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>application-mgt</artifactId>
<groupId>org.wso2.carbon.devicemgt</groupId>
<version>2.0.63-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>org.wso2.carbon.device.application.mgt.ui</artifactId>
<packaging>pom</packaging>
<version>2.0.63-SNAPSHOT</version>
<name>WSO2 Carbon - Application Management Base UI</name>
<description>WSO2 Carbon - Application Management Base UI</description>
<url>http://wso2.org</url>
<build>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.5.5</version>
<configuration>
<finalName>${project.artifactId}-${carbon.device.mgt.version}</finalName>
<appendAssemblyId>false</appendAssemblyId>
<descriptors>
<descriptor>src/assembly/src.xml</descriptor>
</descriptors>
</configuration>
<executions>
<execution>
<id>create-archive</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

@ -0,0 +1,48 @@
<!--
~ Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
~
~ WSO2 Inc. 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.
-->
<assembly
xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0 http://maven.apache.org/xsd/assembly-1.1.0.xsd">
<id>src</id>
<formats>
<format>zip</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<baseDirectory>${basedir}/src</baseDirectory>
<fileSets>
<fileSet>
<!-- CDMF base app -->
<directory>${basedir}/src/main/resources/jaggeryapps/application-mgt</directory>
<outputDirectory>/jaggeryapps/application-mgt/</outputDirectory>
<useDefaultExcludes>true</useDefaultExcludes>
</fileSet>
<fileSet>
<!-- UUF framework app -->
<directory>${basedir}/src/main/resources/jaggeryapps/uuf-template-app</directory>
<outputDirectory>/jaggeryapps/appmgt-uuf-template-app/</outputDirectory>
<useDefaultExcludes>true</useDefaultExcludes>
</fileSet>
<fileSet>
<directory>${basedir}/src/main/resources/jaggery-modules</directory>
<outputDirectory>/jaggery-modules/</outputDirectory>
<useDefaultExcludes>true</useDefaultExcludes>
</fileSet>
</fileSets>
</assembly>

@ -0,0 +1,38 @@
<module name="utils" xmlns="http://wso2.org/projects/jaggery/module.xml">
<script>
<name>reflection</name>
<path>scripts/reflection/reflection.js</path>
</script>
<script>
<name>file</name>
<path>scripts/file/file.js</path>
</script>
<script>
<name>patterns</name>
<path>scripts/patterns/patterns.js</path>
</script>
<script>
<name>xml</name>
<path>scripts/xml/xml.js</path>
</script>
<script>
<name>request</name>
<path>scripts/request/request.js</path>
</script>
<script>
<name>response</name>
<path>scripts/response/response.js</path>
</script>
<script>
<name>time</name>
<path>scripts/time/time.js</path>
</script>
<script>
<name>url</name>
<path>scripts/url/url.js</path>
</script>
<script>
<name>exception</name>
<path>scripts/exception/exception.js</path>
</script>
</module>

@ -0,0 +1,62 @@
/*
* Copyright (c) WSO2 Inc. (http://wso2.com) All Rights Reserved.
*
* 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.
*/
/**
* Description: The response of the currently invoked api enpoint is organized
*/
var exception = {};
var log = new Log('exception_module');
(function(exception) {
/**
*
* @param message The exception description
* @param code HTTP STATUS CODE related to the exception
* @return The error object
*/
exception.buildExceptionObject = function(message, code) {
var error = {};
error.message = message;
error.code = code;
return error;
};
exception.handleError = function (exception, type, code){
var constants = require('rxt').constants;
if (type == constants.THROW_EXCEPTION_TO_CLIENT) {
log.debug(exception);
var e = exceptionModule.buildExceptionObject(exception, code);
throw e;
} else if (type == constants.LOG_AND_THROW_EXCEPTION) {
log.error(exception);
throw exception;
} else if (type == constants.LOG_EXCEPTION_AND_TERMINATE) {
log.error(exception);
var msg = 'An error occurred while serving the request!';
var e = exceptionModule.buildExceptionObject(msg, constants.STATUS_CODES.INTERNAL_SERVER_ERROR);
throw e;
} else if (type == constants.LOG_EXCEPTION_AND_CONTINUE) {
log.debug(exception);
}
else {
log.error(exception);
throw e;
}
};
}(exception))

@ -0,0 +1,167 @@
/*
* Copyright (c) 2005-2014, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 Inc. 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.
*
*/
var file = {};
(function() {
var log = new Log('utils-file');
var CONTENT_MAP = {
'js': 'application/javascript',
'css': 'text/css',
'csv': 'text/csv',
'html': 'text/html',
'json': 'application/json',
'png': 'image/png',
'jpeg': 'image/jpeg',
'gif': 'image/gif',
'svg': 'image/svg+xml',
'ttf': 'application/x-font-ttf',
'eot': 'application/vnd.ms-fontobject',
'woff': 'application/font-woff',
'otf': 'application/x-font-otf',
'zip': 'application/zip',
'xml': 'text/xml',
'xhtml': 'application/xhtml+xml',
'pdf': 'application/pdf'
};
/**
* The function checks whether a directory contains a particular file
* @param dir The directory in which the file must be checked
* @param file A File object if the file exists,else null
*/
file.getFileInDir = function(dir, fileName) {
var isFilePresent = false;
var files = dir.listFiles();
for (var index in files) {
if (files[index].getName() == fileName) {
return files[index];
}
}
return null;
};
/**
* The function returns the file extension of a filename
* @param file
* @return: The extension of the file
*/
file.getExtension = function(file) {
var baseFileName = file.getName();
//Break up the name by .
var baseNameComponents = baseFileName.split('.');
var extension = baseNameComponents[baseNameComponents.length - 1];
return extension;
};
/**
* The function obtains the MIME type based on the extension
* @param The extension
* @return The mime type
*/
file.getMimeType = function(extension) {
return CONTENT_MAP[extension];
};
/**
* The function returns the name of the file without the file extension
* @param file A file object
* @return: The name of the file without the extension
*/
file.getFileName = function(file) {
//Get the name of the file
var baseFileName = file.getName();
//Break up the name by .
var baseNameComponents = baseFileName.split('.');
//Get all of the components except the last one
baseNameComponents.splice(baseNameComponents.length - 1, 1);
return baseNameComponents.join('.');
};
/**
* The function returns the contents of a directory as a JSON object.The name of the
* file is used as the property names without the extensions.
* NOTE: The method will not traverse sub folders.
* @param The directory to be inspected
* @return A JSON object which contains the files in the directory
*/
file.getDirectoryContents = function(dir) {
var dirContents = {};
//Check if it is a directory
if (!dir.isDirectory()) {
log.info('Not a directory');
return dirContents;
}
//Obtain a list of all files
var files = this.getAllFiles(dir);
var name;
log.info('Files: ' + files);
//Create the directory object with each file been a property
for (var index in files) {
dirContents[this.getFileName(files[index])] = files[index];
}
return dirContents;
};
/**
* The function obtains a list of files that are not directories
* @param dir The directory to be inspected
* @return An array with all of the files in the directory
*/
file.getAllFiles = function(dir) {
var filesInDir = [];
if (!dir.isDirectory()) {
return filesInDir;
}
//Obtain a list of all files
var files = dir.listFiles();
for (var index in files) {
log.info('Checking file: ' + files[index].getName());
//Check if the file is a directory
if (!files[index].isDirectory()) {
filesInDir.push(files[index]);
}
}
return filesInDir;
};
/**
* The function returns a list of all file names in a directory
* @param dir The directory to be inspected
* @return {An array containing the name of all files in a directory
*/
file.getAllFileNames = function(dir) {
var files = dir.listFiles();
var list = [];
var fileName;
for (var index in files) {
if (files[index].isDirectory()) {
fileName=this.getFileName(files[index].getName());
list.push(fileName);
}
}
return list;
};
/**
* The function returns a list of all sub directories in a given directory
* @param dir The root directory
* @return: An array containing all sub directories
*/
file.getAllSubDirs = function(dir) {
var files = dir.listFiles();
var subDirs = [];
for (var index in files) {
if (files[index].isDirectory()) {
subDirs.push(files[index]);
}
}
return subDirs;
};
}());

@ -0,0 +1,128 @@
/*
* Copyright (c) 2005-2014, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 Inc. 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.
*
*/
var patterns = {};
(function () {
var DEF_ERR_ARITY = 3;
var DEF_HANDLE_ARITY = 2;
var log = new Log('utils.patterns.GenericPipe');
function GenericPipe(options) {
this.errHandlerArity = DEF_ERR_ARITY || options.errArity;
this.handlerArity = DEF_HANDLE_ARITY || options.handlerArity;
this.plugins = [];
this.finalHandler = function () {
};
}
/**
*The function registers the provided plugin
*/
GenericPipe.prototype.plug = function (plugin, options) {
var options = options || {};
//Only a function
if (plugin instanceof Function) {
this.plugins.push({
handle: plugin,
options: options
});
}
//Is it a plugin object
else if (plugin instanceof Object) {
plugin.options = options;
this.plugins.push(plugin);
}
return this;
};
GenericPipe.prototype.finally = function (plugin) {
this.finalHandler = plugin;
return this;
};
GenericPipe.prototype.resolve = function (data, req, res, session) {
var context = {};
context.req = req;
context.res = res;
context.session = session;
context.data = data;
handle(context, this.plugins, this.errHandlerArity, this.handlerArity, this.finalHandler);
};
var handle = function (context, plugins, errArity, handlerArity, finallyHandler) {
var index = 0;
var currentPlugin;
var recursiveHandle = function (err) {
currentPlugin = plugins[index];
index++;
//Check if there is a plugin
if (!currentPlugin) {
//log.warn('No plugin found at index: ' + index);
return;
}
//Populate the options object for the plugin
context.options=currentPlugin.options;;
//Check if an error has been provided
if (err) {
//Can the current plugin handle the err
if (currentPlugin.handle.length == errArity) {
try {
currentPlugin.handle(err, context,recursiveHandle);
}
catch (e) {
recursiveHandle(e);
}
}
else {
recursiveHandle(err);
}
}
//There is no error so try to invoke the current plugin
else {
if (currentPlugin.handle.length == handlerArity) {
try {
currentPlugin.handle(context,recursiveHandle);
} catch (e) {
recursiveHandle(e);
}
}
else {
recursiveHandle();
}
}
};
recursiveHandle();
finallyHandler(context);
};
patterns.GenericPipe = GenericPipe;
}());

@ -0,0 +1,230 @@
/*
* Copyright (c) 2005-2014, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 Inc. 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.
*
*/
var reflection = {};
/**
* Description: The script encapsulates any reflection related utility functions
*/
(function() {
var log = new Log('utils-reflection');
reflection.copyPropKeys = function(from, to) {
for (var key in from) {
if (from.hasOwnProperty(key)) {
to[key] = '';
}
}
return to;
};
/**
* The function recursively copies all property keys in an object
* @param from
* @param to
*/
reflection.copyAllPropKeys = function(from, to) {
recurse(from, to, function(from, to, key) {
if (from[key] instanceof Object) {
to[key] = from[key];
} else {
to[key] = null;
}
});
};
reflection.copyAllPropValues = function(from, to) {
recurse(from, to, function(from, to, key) {
//Create an instance if the property does not exist
if (!to[key]) {
to[key] = {};
}
//Copy the values over
if (!(from[key] instanceof Object)) {
to[key] = from[key];
} else {
log.debug('Not copying values of key: ' + key);
}
});
};
/**
* The function will only copy public properties
* @param from
* @param to
*/
reflection.copyPublicPropValues = function(from, to) {
recurse(from, to, function(from, to, key) {
//Ignore any hidden properties
if (key.charAt(0) == '_') {
log.warn('Drop key: ' + key);
return;
}
//Create an instance if the property does not exist
if (!to[key]) {
to[key] = {};
}
//Copy the values over
if (!(from[key] instanceof Object)) {
to[key] = from[key];
} else {
log.warn('Not copying values of key: ' + key);
}
});
};
reflection.inspect = function(from, to, cb) {
recurse(from, to, cb);
};
/**
* The function recursively traverses an object and then invokes the provided
* callback
* @param root
* @param clone
* @param cb
*/
var recurse = function(root, clone, cb) {
var key;
//Check if the root is an object
if (!(root instanceof Object)) {
return;
} else {
var keys = Object.keys(root);
//Go through all the other keys in the current root
for (var index in keys) {
key = keys[index];
cb(root, clone, key);
recurse(root[key], clone[key], cb);
}
}
};
reflection.copyProps = function(from, to) {
for (var key in from) {
if (from.hasOwnProperty(key)) {
to[key] = from[key];
}
}
return to;
};
reflection.getProps = function(obj) {
var props = {};
for (var key in obj) {
if (!(obj[key] instanceof Function)) {
props[key] = obj[key];
}
}
return props;
};
reflection.printProps = function(obj) {
for (var key in obj) {
if (obj.hasOwnProperty(key)) {
log.info('key: ' + key);
}
}
};
/**
* The function determines if a property is hidden based on _
* @param key
* @returns {boolean}
*/
reflection.isHiddenProp = function(key) {
if (key == '') {
return false;
}
return (key.charAt(0) == '_') ? true : false;
};
var getDiff = function(a, b, diff) {};
/**
* The function calculates the differences between two simple JSON objects
* @param a The object with which b is compared
* @param b The target of the comparison
* @return An object which records the differences between the two objects
*/
reflection.diff = function(a, b) {};
/**
* The function merges the two provided objects to create a new
* object.In the case where b has the same property as a; the property of b
* will have precedence
* @param {[type]} a [description]
* @param {[type]} b [description]
* @return A new object having the properties of both object a and b
*/
reflection.merge = function(a, b) {
var newObj = {};
//Copy the properties of a first
for (var key in a) {
newObj[key] = b[key];
}
//Override with the properties of b
for (var key in b) {
newObj[key] = b[key];
}
return newObj;
};
/**
* The function allows a child class to override a select set of methods of
* a parent class.The original methods of the parent can be accessed
* using the this._super keyword
* @param {[type]} parent The parent class instance to be overriden
* @param {[type]} child The child class instance containing methods which will override the parent
*/
reflection.override = function(parent, child) {
//Make a clone of the parent
var super = parse(stringify(parent));
for (var childKey in child) {
for (var parentKey in parent) {
//Only override those methods that are common
if (childKey === parentKey) {
var parentPtr = parent[parentKey];
var childPtr = child[childKey];
//Update the clone with the old parent method
super[parentKey] = parentPtr;
parent[parentKey] = childPtr;
/*parent[parentKey] = function() {
var result=childPtr.apply(this, arguments)||null;
return result;
};*/
}
}
}
//Allow the child object to call methods of the parent
parent._super = super;
};
reflection.overrideAll=function(parent,child){
//Make a clone of the parent
var super = parse(stringify(parent));
for (var childKey in child) {
for (var parentKey in parent) {
//Only override those methods that are common
if ( (child.hasOwnProperty(childKey))&&(parent.hasOwnProperty(parentKey)) ) {
var parentPtr = parent[parentKey];
var childPtr = child[childKey];
//Update the clone with the old parent method
super[parentKey] = parentPtr;
parent[parentKey] = childPtr;
/*parent[parentKey] = function() {
var result=childPtr.apply(this, arguments)||null;
return result;
};*/
}
}
}
//Allow the child object to call methods of the parent
parent._super = super;
};
reflection.isArray = function(object) {
if (Object.prototype.toString.call(object) === '[object Array]') {
return true;
}
return false;
};
}());

@ -0,0 +1,57 @@
/*
* Copyright (c) 2005-2014, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 Inc. 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.
*
*/
var request = {};
(function(request) {
var hasOwnProperty = function(obj, element) {
return Object.prototype.hasOwnProperty.call(obj, element);
};
var isObject = function(object) {;
return typeof object === 'object';
};
/*
* ECMA Standard (ECMA-262 : 5.1 Edition)*/
var decodes = function(encodedURI) {
return decodeURIComponent(encodedURI);
};
request.getQueryOptions = function(queryString) {
var opt={};
var sep = opt.sep || '&',
assign = opt.assign || '=',
compoArray = [];
var obj = {};
var decodedURI = decodes(queryString);
decodedURI.split(sep).forEach(function(comp) {
comp.split(assign).some(function(element, index, array) {
if (hasOwnProperty(obj, element.toString())) {
compoArray.push(obj[element]);
compoArray.push(array[1]);
obj[element] = compoArray;
} else {
Object.defineProperty(obj, element, {
enumerable: true,
writable: true,
value: array[1]
});
}
return true;
});
});
return obj;
};
}(request))

@ -0,0 +1,96 @@
/*
* Copyright (c) WSO2 Inc. (http://wso2.com) All Rights Reserved.
*
* 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.
*/
/**
* Description: The response of the currently invoked api endpoint is organized
*/
var response = {};
var log = new Log("response");
(function(response) {
/**
* Build Error response
* @param resp jaggery-response object to retrieve to client
* @param code status code
* @param message message to the client side
* @return return response
*/
response.buildErrorResponse = function(resp,code,message) {
var content={};
content.error = message;
resp = processResponse(resp,code,content);
return resp;
};
/**
* Build success response
* @param resp jaggery response object
* @param code status code
* @param data the result to client
* @return return response
*/
response.buildSuccessResponse= function(resp, code, data){
var content={};
content.data = data;
resp = processResponse(resp,code,content);
return resp;
};
/**
* process General response
* @param resp jaggery response
* @param code status code
* @param data success result
* @return resp jaggery response
*/
response.buildSuccessResponseForRxt= function(resp, code, data){
resp.status = code;
resp.content = data;
return resp;
};
/**
* General response builder
* @param resp jaggery response
* @param code status code
* @param content what ever the content to be sent as response
* @return resp jaggery response
*/
function processResponse(resp, code, content){
resp.status = code;
resp.contentType = 'application/json';
resp.content = content;
return resp;
};
/**
*
* @param resp
* @param code
* @param data
* @return The http response
*/
response.buildSuccessResponseForRxt= function(resp, code, data){
resp.contentType = 'application/json';
resp.status = code;
resp.content = data;
return resp;
};
}(response))

@ -0,0 +1,35 @@
/*
* Copyright (c) 2005-2014, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 Inc. 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.
*
*/
var time = {};
(function(time) {
time.getCurrentTime = function(dateLength) {
var dateLength=dateLength||20;
var now = new String(new Date().valueOf());
var length = now.length;
var prefix = dateLength;
var onsetVal = '';
if (length != prefix) {
var onset = prefix - length;
for (var i = 0; i < onset; i++) {
onsetVal += '0';
}
}
return onsetVal + now;
};
}(time));

@ -0,0 +1,47 @@
/*
* Copyright (c) 2005-2014, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 Inc. 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.
*
*/
var url = {};
(function() {
var log=new Log('utils-url');
url.popServerDetails = function(obj) {
var process = require('process');
var localIP = process.getProperty('server.host');
var httpPort = process.getProperty('http.port');
var httpsPort = process.getProperty('https.port');
var value = '';
var carbonLocalIP = process.getProperty('carbon.local.ip');
for (var key in obj) {
if (obj.hasOwnProperty(key)) {
value = obj[key];
if ((typeof value === 'string') && value.indexOf('%https.host%') > -1) {
value=value.replace('%https.host%', 'https://' + localIP + ':' + httpsPort);
} else if ((typeof value === 'string') && value.indexOf('%http.host%') > -1) {
value=value.replace('%http.host%', 'http://' + localIP + ':' + httpPort);
} else if ((typeof value === 'string') && value.indexOf('%https.carbon.local.ip%') > -1) {
value=value.replace('%https.carbon.local.ip%', 'https://' + carbonLocalIP + ':' + httpsPort);
} else if ((typeof value === 'string') && value.indexOf('%http.carbon.local.ip%') > -1) {
value=value.replace('%http.carbon.local.ip%', 'http://' + carbonLocalIP + ':' + httpPort);
}
obj[key] = value;
}
}
return obj;
};
}(url));

@ -0,0 +1,138 @@
/*
* Copyright (c) 2005-2014, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 Inc. 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.
*
*/
var xml = {};
(function () {
var log=new Log('util.xml')
/*
The method is used to create a JSON object using
an xml object.
@xmlElement: An xml element object to be processed
@return: A pseudo object containing the properties of the
xml element.
*/
var createJSONObject = function (xmlElement) {
var pseudo = {};
//Extract all attributes
var attributes = xmlElement.@*;
//Fill the pseudo object with the attributes of the element
for (var attributeKey in attributes) {
var attribute = attributes[attributeKey];
pseudo[attribute.localName()] = attribute.toString();
}
return pseudo;
};
/*
The function converts an E4X Xml object to a JSON object
This function has been adapted from the work of Oleg Podsechin available at
https://gist.github.com/olegp/642667
It uses a slightly modified version of his algorithm , therefore
all credit should be attributed to Oleg Podsechin.
IMPORTANT:
1. It does not create a 1..1 mapping due to the differences
between Xml and JSON.It is IMPORTANT that you verify the structure
of the object generated before using it.
2. The input xml object must not contain the xml header information
This is a known bug 336551 (Mozilla Developer Network)
Source: https://developer.mozilla.org/en/docs/E4X
Please remove the header prior to sending the xml object for processing.
@root: A starting element in an E4X Xml object
@return: A JSON object mirroring the provided Xml object
*/
var recursiveConvertE4XtoJSON = function (root) {
log.debug('Root: ' + root.localName());
//Obtain child nodes
var children = root.*;
//The number of children
var numChildren = children.length();
//No children
if (numChildren == 0) {
//Extract contents
return createJSONObject(root);
}
else {
//Create an empty object
var rootObject = createJSONObject(root);
//Could be multiple children
for (var childElementKey in children) {
var child = children[childElementKey];
log.debug('Examining child: ' + child.localName());
//If the child just contains a single value then stop
if (child.localName() == undefined) {
log.debug('Child is undefined: ' + child.toString());
//Change the object to just a key value pair
rootObject[root.localName()] = child.toString();
return rootObject;
}
//Make a recursive call to construct the child element
var createdObject = recursiveConvertE4XtoJSON(child);
log.debug('Converted object: ' + stringify(createdObject));
//Check if the root object has the property
if (rootObject.hasOwnProperty(child.localName())) {
log.debug('key: ' + child.localName() + ' already present.');
rootObject[child.localName()].push(createdObject);
}
else {
log.debug('key: ' + child.localName() + ' not present.');
rootObject[child.localName()] = [];
rootObject[child.localName()].push(createdObject);
}
}
log.debug('root: ' + root.localName());
return rootObject;
}
};
/**
* The function is used to convert an E4X xml to JSON
* @param root
*/
xml.convertE4XtoJSON = function (root) {
return recursiveConvertE4XtoJSON(root);
};
}());

@ -0,0 +1,30 @@
<!DOCTYPE html>
<html>
<head>
<meta charset='UTF-8'>
<link rel="stylesheet" href="https://error.cloud.wso2.com/style/style.css">
<link rel="stylesheet" href="https://error.cloud.wso2.com/style/font-mf.css">
</head>
<body>
<div class="sky">
<section>
<div class="error-400">
<img src="https://error.cloud.wso2.com/images/400-error.svg">
</div>
<div class="text-label">
<h1>Oops something went wrong </h1>
<h2>400 - Bad request</h2>
<div style="clear: both"></div>
<div class="button-label">
<a href="https://cloudmgt.cloud.wso2.com/cloudmgt/site/pages/index.jag"><label class="label-back">Back to Cloud </label></a>
<a href="https://cloudmgt.cloud.wso2.com/cloudmgt/site/pages/contact-us.jag"><label class="label-report"> Report Issue </label></a>
</div>
</div>
</section>
<div class="clouds_one"></div>
<div class="clouds_two"></div>
<div class="clouds_three"></div>
</div>
</body>
</html>

@ -0,0 +1,33 @@
<!--
~ Copyright 2016 WSO2, Inc. (http://wso2.com)
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Bad request - Error 400</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="">
<meta name="author" content="">
</head>
<body>
<i class="icon-unlink error-icon"></i>
<h1>Error 400</h1>
<h3>We are unable to understand the request and process it. Please re-check your request.</h3>
<h4 id="link"><a href="/devicemgt">Go to IoT Home</a></h4>
</body>
</html>

@ -0,0 +1,30 @@
<!DOCTYPE html>
<html>
<head>
<meta charset='UTF-8'>
<link rel="stylesheet" href="https://error.cloud.wso2.com/style/style.css">
<link rel="stylesheet" href="https://error.cloud.wso2.com/style/font-mf.css">
</head>
<body>
<div class="sky">
<section>
<div class="error-400">
<img src="https://error.cloud.wso2.com/images/400-error.svg">
</div>
<div class="text-label">
<h1>Oops something went wrong </h1>
<h2>401 - Unauthorized</h2>
<div style="clear: both"></div>
<div class="button-label">
<a href="https://cloudmgt.cloud.wso2.com/cloudmgt/site/pages/index.jag"><label class="label-back">Back to Cloud </label></a>
<a href="https://cloudmgt.cloud.wso2.com/cloudmgt/site/pages/contact-us.jag"><label class="label-report"> Report Issue </label></a>
</div>
</div>
</section>
<div class="clouds_one"></div>
<div class="clouds_two"></div>
<div class="clouds_three"></div>
</div>
</body>
</html>

@ -0,0 +1,33 @@
<!--
~ Copyright 2016 WSO2, Inc. (http://wso2.com)
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Unauthorized - Error 401</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="">
<meta name="author" content="">
</head>
<body>
<i class="icon-unlink error-icon"></i>
<h1>Error 401</h1>
<h3>You do not have permission to access this page.Please contact your administrator and request permission.</h3>
<h4 id="link"><a href="/devicemgt">Go to IoT Home</a></h4>
</body>
</html>

@ -0,0 +1,30 @@
<!DOCTYPE html>
<html>
<head>
<meta charset='UTF-8'>
<link rel="stylesheet" href="https://error.cloud.wso2.com/style/style.css">
<link rel="stylesheet" href="https://error.cloud.wso2.com/style/font-mf.css">
</head>
<body>
<div class="sky">
<section>
<div class="error-400">
<img src="https://error.cloud.wso2.com/images/400-error.svg">
</div>
<div class="text-label">
<h1>Oops something went wrong </h1>
<h2>403 - Forbidden</h2>
<div style="clear: both"></div>
<div class="button-label">
<a href="https://cloudmgt.cloud.wso2.com/cloudmgt/site/pages/index.jag"><label class="label-back">Back to Cloud </label></a>
<a href="https://cloudmgt.cloud.wso2.com/cloudmgt/site/pages/contact-us.jag"><label class="label-report"> Report Issue </label></a>
</div>
</div>
</section>
<div class="clouds_one"></div>
<div class="clouds_two"></div>
<div class="clouds_three"></div>
</div>
</body>
</html>

@ -0,0 +1,34 @@
<!--
~ Copyright 2016 WSO2, Inc. (http://wso2.com)
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Forbidden - Error 403</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="">
<meta name="author" content="">
</head>
<body>
<i class="icon-unlink error-icon"></i>
<h1>Error 403</h1>
<h3>We cannot process this request.</h3>
<h4 id="link"><a href="/devicemgt">Go to IoT Home</a></h4>
</body>
</html>

@ -0,0 +1,30 @@
<!DOCTYPE html>
<html>
<head>
<meta charset='UTF-8'>
<link rel="stylesheet" href="https://error.cloud.wso2.com/style/style.css">
<link rel="stylesheet" href="https://error.cloud.wso2.com/style/font-mf.css">
</head>
<body>
<div class="sky">
<section>
<div class="error-400">
<img src="https://error.cloud.wso2.com/images/400-error.svg">
</div>
<div class="text-label">
<h1>Oops something went wrong </h1>
<h2>404 - Page Not Found</h2>
<div style="clear: both"></div>
<div class="button-label">
<a href="https://cloudmgt.cloud.wso2.com/cloudmgt/site/pages/index.jag"><label class="label-back">Back to Cloud </label></a>
<a href="https://cloudmgt.cloud.wso2.com/cloudmgt/site/pages/contact-us.jag"><label class="label-report"> Report Issue </label></a>
</div>
</div>
</section>
<div class="clouds_one"></div>
<div class="clouds_two"></div>
<div class="clouds_three"></div>
</div>
</body>
</html>

@ -0,0 +1,33 @@
<!--
~ Copyright 2016 WSO2, Inc. (http://wso2.com)
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Page not found - Error 404</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="">
<meta name="author" content="">
</head>
<body>
<i class="icon-unlink error-icon"></i>
<h1>Error 404</h1>
<h3>We can't find what you are looking for.</h3>
<h4 id="link"><a href="/devicemgt">Go to IoT Home</a></h4>
</body>
</html>

@ -0,0 +1,30 @@
<!DOCTYPE html>
<html>
<head>
<meta charset='UTF-8'>
<link rel="stylesheet" href="https://error.cloud.wso2.com/style/style.css">
<link rel="stylesheet" href="https://error.cloud.wso2.com/style/font-mf.css">
</head>
<body>
<div class="sky">
<section>
<div class="error-400">
<img src="https://error.cloud.wso2.com/images/400-error.svg">
</div>
<div class="text-label">
<h1>Oops something went wrong </h1>
<h2>405 - Method Not Allowed</h2>
<div style="clear: both"></div>
<div class="button-label">
<a href="https://cloudmgt.cloud.wso2.com/cloudmgt/site/pages/index.jag"><label class="label-back">Back to Cloud </label></a>
<a href="https://cloudmgt.cloud.wso2.com/cloudmgt/site/pages/contact-us.jag"><label class="label-report"> Report Issue </label></a>
</div>
</div>
</section>
<div class="clouds_one"></div>
<div class="clouds_two"></div>
<div class="clouds_three"></div>
</div>
</body>
</html>

@ -0,0 +1,33 @@
<!--
~ Copyright 2016 WSO2, Inc. (http://wso2.com)
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Method not allowed - Error 405</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="">
<meta name="author" content="">
</head>
<body>
<i class="icon-unlink error-icon"></i>
<h1>Error 405</h1>
<h3>Method not allowed.</h3>
<h4 id="link"><a href="/devicemgt">Go to IoT Home</a></h4>
</body>
</html>

@ -0,0 +1,30 @@
<!DOCTYPE html>
<html>
<head>
<meta charset='UTF-8'>
<link rel="stylesheet" href="https://error.cloud.wso2.com/style/style.css">
<link rel="stylesheet" href="https://error.cloud.wso2.com/style/font-mf.css">
</head>
<body>
<div class="sky">
<section>
<div class="error-400">
<img src="https://error.cloud.wso2.com/images/400-error.svg">
</div>
<div class="text-label">
<h1>Oops something went wrong </h1>
<h2>500 - Internal Server Error</h2>
<div style="clear: both"></div>
<div class="button-label">
<a href="https://cloudmgt.cloud.wso2.com/cloudmgt/site/pages/index.jag"><label class="label-back">Back to Cloud </label></a>
<a href="https://cloudmgt.cloud.wso2.com/cloudmgt/site/pages/contact-us.jag"><label class="label-report"> Report Issue </label></a>
</div>
</div>
</section>
<div class="clouds_one"></div>
<div class="clouds_two"></div>
<div class="clouds_three"></div>
</div>
</body>
</html>

@ -0,0 +1,32 @@
<!--
~ Copyright 2016 WSO2, Inc. (http://wso2.com)
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Internal Server Error - Error 500</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="">
<meta name="author" content="">
<body>
<i class="icon-ambulance error-icon"></i>
<h1>Error 500</h1>
<h3>Something went wrong and we're trying to fix it.</h3>
<h4 id="link"><a href="/devicemgt">Go to IoT Home</a></h4>
</body>
</html>

@ -0,0 +1,101 @@
{
"displayName": "Carbon Application Management App",
"logLevel": "info",
"initScripts": ["/app/modules/init.js"],
"urlMappings": [
{
"url": "/uuf/login",
"path": "/lib/modules/auth/login.jag"
},
{
"url": "/uuf/logout",
"path": "/lib/modules/auth/logout.jag"
},
{
"url": "/uuf/sso/acs",
"path": "/lib/modules/auth/acs.jag"
},
{
"url": "/public/*",
"path": "/lib/static-files.jag"
},
{
"url": "/unit/*",
"path": "/lib/units.jag"
},
{
"url": "/*",
"path": "/lib/pages.jag"
}
],
"errorPages": {
"500": "/error-pages/error500.html",
"404": "/error-pages/error404.html",
"401": "/error-pages/error401.html",
"405": "/error-pages/error405.html",
"403": "/error-pages/error403.html",
"400": "/error-pages/error400.html"
},
"filters": [
{
"name": "ContentTypeBasedCachePreventionFilter",
"class": "org.wso2.carbon.ui.filters.cache.ContentTypeBasedCachePreventionFilter",
"params" : [
{"name" : "patterns", "value" : "text/html\" ,application/json\" ,text/plain"},
{"name" : "filterAction", "value" : "enforce"},
{"name" : "httpHeaders", "value" : "Cache-Control: no-store, no-cache, must-revalidate, private"}
]
},
{
"name":"HttpHeaderSecurityFilter",
"class":"org.apache.catalina.filters.HttpHeaderSecurityFilter",
"params" : [{"name" : "hstsEnabled", "value" : "false"}]
},
{
"name" : "CSRFGuard",
"class" : "org.owasp.csrfguard.CsrfGuardFilter"
}
],
"filterMappings": [
{
"name":"HttpHeaderSecurityFilter",
"url":"*"
},
{
"name" : "CSRFGuard",
"url" : "/*"
},
{
"name":"ContentTypeBasedCachePreventionFilter",
"url":"*"
}
],
"listeners" : [
{
"class" : "org.owasp.csrfguard.CsrfGuardServletContextListener"
},
{
"class" : "org.owasp.csrfguard.CsrfGuardHttpSessionListener"
}
],
"servlets" : [
{
"name" : "JavaScriptServlet",
"class" : "org.owasp.csrfguard.servlet.JavaScriptServlet"
}
],
"servletMappings" : [
{
"name" : "JavaScriptServlet",
"url" : "/csrf.js"
}
],
"contextParams" : [
{
"name" : "Owasp.CsrfGuard.Config",
"value" : "repository/conf/security/Owasp.CsrfGuard.dashboard.properties"
}
]
}

@ -0,0 +1,45 @@
{
"appName": "UUF Template App",
"cachingEnabled": false,
"debuggingEnabled": false,
"permissionRoot": "/",
"loginPage": "uuf.page.sign-in",
"adminServicesUrl": "https://${server.ip}:${server.https_port}/admin/services/",
"authModule": {
"enabled": true,
"login": {
"onSuccess": {
"script": "/app/modules/login.js",
"page": "uuf.page.home"
},
"onFail": {
"script": "/app/modules/login.js",
"page": "uuf.page.sign-in"
}
},
"logout": {
"onSuccess": {
"script": "/app/modules/logout.js",
"page": "uuf.page.sign-in"
},
"onFail": {
"script": "/app/modules/logout.js",
"page": "uuf.page.home"
}
},
"sso": {
"enabled": false,
"issuer": "uuf",
"responseSigningEnabled": true,
"keyStoreName": "repository/resources/security/wso2carbon.jks",
"keyStorePassword": "wso2carbon",
"identityProviderAlias": "wso2carbon",
"identityProviderUrl": "https://${server.ip}:${server.https_port}/samlsso",
"intermediatePage": "uuf.page.sso-intermediate"
}
},
"errorPages": {
"404": "uuf.page.error",
"default": "uuf.page.error"
}
}

@ -0,0 +1,67 @@
{{!--
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 Inc. 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.
--}}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>{{#defineZone "title"}}WSO2 Template{{/defineZone}}</title>
{{defineZone "favicon"}}
{{defineZone "topCss"}}
{{defineZone "topJs"}}
</head>
<body>
<!-- header -->
{{defineZone "header"}}
<!-- /header -->
<!-- navbars -->
<div class="navbar-wrapper">
{{defineZone "navbars"}}
</div>
<!-- /navbars -->
<!-- sidepanes -->
{{defineZone "sidePanes"}}
<!-- /sidepanes -->
<!-- page-content-wrapper -->
<div class="page-content-wrapper">
{{defineZone "contentTitle"}}
<div class="container-fluid ">
<div class="body-wrapper">
{{defineZone "content"}}
</div>
</div>
</div>
<!-- /page-content-wrapper -->
<!-- footer -->
<footer class="footer">
<div class="container-fluid">
{{defineZone "footer"}}
</div>
</footer>
<!-- /footer -->
{{defineZone "bottomJs"}}
</body>
</html>

@ -0,0 +1,56 @@
{{!--
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 Inc. 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.
--}}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>{{#defineZone "title"}}WSO2 Template{{/defineZone}}</title>
{{defineZone "favicon"}}
{{defineZone "topCss"}}
{{defineZone "topJs"}}
</head>
<body>
<!-- header -->
{{defineZone "header"}}
<!-- /header -->
<!-- page-content-wrapper -->
<div class="page-content-wrapper">
<div class="container-fluid ">
<div class="body-wrapper">
{{defineZone "content"}}
</div>
</div>
</div>
<!-- /page-content-wrapper -->
<!-- footer -->
<footer class="footer">
<div class="container-fluid">
{{defineZone "footer"}}
</div>
</footer>
<!-- /footer -->
{{defineZone "bottomJs"}}
</body>
</html>

@ -0,0 +1,38 @@
{{!
Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
WSO2 Inc. 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.
}}
{{#zone "title"}}Error | {{@app.conf.appName}}{{/zone}}
{{#zone "breadcrumbs"}}
<li>
<a href="{{@app.context}}/">
<i class="icon fw fw-home"></i>
</a>
</li>
{{/zone}}
{{#zone "content"}}
<div class="message message-danger">
<h4><i class="icon fw fw-error"></i>An Error Occurred!</h4>
<div style="padding-left: 25px;">
<h5><b>HTTP Status : {{@page.params.status}}</b></h5>
<p style="white-space: pre-wrap;">{{@page.params.message}}</p>
</div>
</div>
{{/zone}}

@ -0,0 +1,6 @@
{
"version": "1.0.0",
"uri": "/error/default",
"layout": "uuf.layout.default",
"isAnonymous": true
}

@ -0,0 +1,24 @@
$(document).ready(function(){
$("#signInForm").validate({
rules: {
username: {
required: true,
minlength: 3
},
password: {
required: true,
minlength: 3
}
},
messages: {
username: {
required: "Please enter a username",
minlength: "Your username must consist of at least 3 characters"
},
password: {
required: "Please provide a password",
minlength: "Your password must be at least 3 characters long"
}
}
});
});

@ -0,0 +1,63 @@
{{!
Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
WSO2 Inc. 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.
}}
{{#zone "title"}}Sign In | {{@app.conf.appName}}{{/zone}}
{{~#zone "content"}}
<div class="col-sm-7 col-md-4 center-block" style="float: none; margin-top: 10%;">
<div class="panel panel-default">
<div class="panel-heading">
<h4 class="panel-title">
{{#defineZone "signIn-title" scope="protected"}}Sign In to UUF Template App{{/defineZone}}
</h4>
</div>
<div class="panel-body">
{{#if message}}
<div id="_uuf_login-error-msg" class="alert alert-danger">
<i class="icon fw fw-warning"></i> {{message}}!
</div>
{{/if}}
<form id="signInForm" method="POST"
class="{{defineZone "signInForm-class" scope="protected"}}"
action="{{#defineZone "signInForm-action" scope="protected"}}{{@app.context}}/uuf/login{{/defineZone}}">
<div class="form-group">
<input type="text" name="username" class="form-control"
placeholder="User Name" required="required" autofocus="autofocus" />
</div>
<div class="form-group">
<input type="password" name="password" class="form-control" autocomplete="off"
placeholder="Password" required="required" />
</div>
{{#if referer}}
<input type="hidden" name="referer" value="{{referer}}" />
{{/if}}
<div class="form-group" style="padding-top: 10px;">
<input type="submit" name="signInBtn" class="btn btn-primary btn-block"
value="Sign In" />
</div>
{{defineZone "signInForm-below" scope="protected"}}
</form>
</div>
</div>
</div>
{{/zone}}
{{! sign-in form validation}}
{{~unit "uuf.unit.lib.form-validation"}}
{{~#zone "bottomJs"}}
{{~js "js/sign-in-validations.js"}}
{{/zone}}

@ -0,0 +1,30 @@
function onRequest(context) {
var authModuleConfigs = context.app.conf["authModule"];
if (authModuleConfigs && (authModuleConfigs["enabled"].toString() == "true")) {
// Auth module is enabled.
if (context.user) {
// User is already logged in.
response.sendRedirect(context.app.context + "/");
exit();
} else {
// User is not logged in.
var ssoConfigs = authModuleConfigs["sso"];
if (ssoConfigs && (ssoConfigs["enabled"].toString() == "true")) {
// SSO is enabled in Auth module.
var redirectUri = context.app.context + "/uuf/login";
var queryString = request.getQueryString();
if (queryString && (queryString.length > 0)) {
redirectUri = redirectUri + "?" + queryString;
}
response.sendRedirect(encodeURI(redirectUri));
exit();
} else {
// Generic login process is enabled.
return {
message: request.getParameter("error"),
referer: request.getParameter("referer")
};
}
}
}
}

@ -0,0 +1,18 @@
{{!
Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
WSO2 Inc. 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.
}}
{{! This template won't be rendered. So nothing is here }}

@ -0,0 +1,16 @@
function onRequest(context) {
var authModuleConfigs = context.app.conf["authModule"];
if (authModuleConfigs && (authModuleConfigs["enabled"].toString() == "true")) {
// Auth module is enabled.
if (context.user) {
// User is logged in.
response.sendRedirect(context.app.context + "/uuf/logout");
exit();
} else {
// User is already logged out.
response.sendRedirect(context.app.context + "/");
exit();
}
}
}

@ -0,0 +1,45 @@
{{!
Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
WSO2 Inc. 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.
}}
{{#zone "title"}}Sign In | {{@app.conf.appName}}{{/zone}}
{{unit "uuf.unit.theme"}}
{{unit "uuf.unit.header.logo"}}{{unit "uuf.unit.header"}}
{{unit "uuf.unit.footer"}}
{{#zone "content"}}
<div class="jumbotron">
<p>
You are now being redirected to Identity Server. If the redirection fails, please click
on the button below.
</p>
<div>
<form method="post" action="{{@page.params.identityProviderUrl}}">
<input type="hidden" name="SAMLRequest"
value="{{@page.params.encodedSAMLAuthRequest}}" />
<input type="hidden" name="RelayState" value="{{@page.params.relayState}}" />
<input type="hidden" name="SSOAuthSessionID" value="{{@page.params.sessionId}}" />
<button type="submit" class="btn btn-primary">Redirect manually</button>
</form>
</div>
</div>
{{/zone}}
{{#zone "bottomJs"}}
<script type="text/javascript">document.forms[0].submit();</script>
{{/zone}}

@ -0,0 +1,27 @@
{{!
Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
WSO2 Inc. 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.
}}
<div {{#if @unit.params.id}}id="{{@unit.params.id}}" {{/if~}}
class="alert alert-{{@unit.params.type}}" role="alert">
<i class="icon fw fw-{{icon}}"></i>
<strong>{{@unit.params.title}}</strong> {{{@unit.params.message}}}
{{#if @unit.params.dismissable}}
<button type="button" class="close" aria-label="close" data-dismiss="alert">
<span aria-hidden="true"><i class="fw fw-cancel"></i></span>
</button>
{{/if}}
</div>

@ -0,0 +1,15 @@
function onRequest(context) {
var type = context.unit.params.type;
switch (type) {
case "success":
return {icon: "ok"};
case "info":
return {icon: "info"};
case "warning":
return {icon: "warning"};
case "danger":
return {icon: "error"};
default:
return {icon: "ok"};
}
}

@ -0,0 +1,24 @@
{{!
Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
WSO2 Inc. 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.
}}
{{#zone "favicon"}}
{{#if isCloud}}
<link rel="shortcut icon" href="{{@unit.publicUri}}/img/cloud-favicon.png" />
{{else}}
<link rel="shortcut icon" href="{{@unit.publicUri}}/img/favicon.png" />
{{/if}}
{{/zone}}

@ -0,0 +1,8 @@
function onRequest(context) {
var deviceMgtProps = require("/app/modules/conf-reader/main.js")["conf"];
var viewModel = {};
viewModel.isCloud = deviceMgtProps.isCloud;
return viewModel;
}

@ -0,0 +1,23 @@
{{!
Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
WSO2 Inc. 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.
}}
{{#zone "footer"}}
<p>
WSO2 | &copy; 2015
<a href="http://wso2.com/" target="_blank"><i class="icon fw fw-wso2"></i> Inc</a>.
</p>
{{/zone}}

@ -0,0 +1,27 @@
{{!
Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
WSO2 Inc. 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.
}}
{{#zone "brand"}}
<a href="{{#defineZone "productUri"}}{{@app.context}}/{{/defineZone}}">
<img src="{{@unit.publicUri}}/img/logo.png" alt="{{defineZone "productName"}}"
title="{{defineZone "productName"}}" class="logo" />
<h1>
<span class="hidden-xs">{{#defineZone "productName"}}Unified UI Template App{{/defineZone}}</span>
<span class="visible-xs-inline">{{#defineZone "productNameResponsive"}}UUI Tmpl. App{{/defineZone}}</span>
</h1>
</a>
{{/zone}}

@ -0,0 +1,39 @@
{{!
Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
WSO2 Inc. 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.
}}
{{#zone "userMenu"}}
<ul class="nav navbar-right float-remove-xs text-center-xs">
<li class="visible-inline-block">
<a href="#" class="dropdown" data-toggle="dropdown">
<span class="icon fw-stack fw-lg">
<i class="fw fw-circle fw-stack-2x"></i>
<i class="fw fw-user fw-stack-1x fw-inverse"></i>
</span>
<span class="hidden-xs add-padding-left-1x">
{{@user.username}}<span class="caret"></span>
</span>
</a>
<ul class="dropdown-menu dropdown-menu-right slideInDown" role="menu">
{{#defineZone "userMenu-items"}}
<li>
<a href="{{@app.context}}/signout">Sign Out</a>
</li>
{{/defineZone}}
</ul>
</li>
</ul>
{{/zone}}

@ -0,0 +1,32 @@
{{!
Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
WSO2 Inc. 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.
}}
{{#zone "header"}}
<header class="header header-default">
<div class="container-fluid">
<div class="pull-left brand">
{{defineZone "brand"}}
</div>
<div class="pull-left brand">
{{defineZone "cloudMenu"}}
</div>
<div class="pull-right auth">
{{defineZone "userMenu"}}
</div>
</div>
</header>
{{/zone}}

@ -0,0 +1,27 @@
{{!
Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
WSO2 Inc. 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.
}}
{{#zone "topCss"}}
{{~css "data-tables_1.10.7/extensions/Bootstrap/css/dataTables.bootstrap.css"}}
{{~css "data-tables_1.10.7/extensions/Responsive/css/dataTables.responsive.css"}}
{{/zone}}
{{~#zone "bottomJs"}}
{{~js "data-tables_1.10.7/media/js/jquery.dataTables.min.js"}}
{{~js "data-tables_1.10.7/extensions/Bootstrap/js/dataTables.bootstrap.js"}}
{{~js "data-tables_1.10.7/extensions/Responsive/js/dataTables.responsive.js"}}
{{/zone}}

@ -0,0 +1,24 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* AutoFill styles
*/
div.AutoFill_filler {
display: none;
position: absolute;
height: 14px;
width: 14px;
background: url(../images/filler.png) no-repeat center center;
z-index: 1002;
}
div.AutoFill_border {
display: none;
position: absolute;
background-color: #0063dc;
z-index: 1001;
box-shadow: 0px 0px 5px #76b4ff;
-moz-box-shadow: 0px 0px 5px #76b4ff;
-webkit-box-shadow: 0px 0px 5px #76b4ff;
}

@ -0,0 +1 @@
div.AutoFill_filler{display:none;position:absolute;height:14px;width:14px;background:url(../images/filler.png) no-repeat center center;z-index:1002}div.AutoFill_border{display:none;position:absolute;background-color:#0063dc;z-index:1001;box-shadow:0px 0px 5px #76b4ff;-moz-box-shadow:0px 0px 5px #76b4ff;-webkit-box-shadow:0px 0px 5px #76b4ff}

@ -0,0 +1,855 @@
/*! AutoFill 1.2.1
* ©2008-2014 SpryMedia Ltd - datatables.net/license
*/
/**
* @summary AutoFill
* @description Add Excel like click and drag auto-fill options to DataTables
* @version 1.2.1
* @file dataTables.autoFill.js
* @author SpryMedia Ltd (www.sprymedia.co.uk)
* @contact www.sprymedia.co.uk/contact
* @copyright Copyright 2010-2014 SpryMedia Ltd.
*
* This source file is free software, available under the following license:
* MIT license - http://datatables.net/license/mit
*
* This source file is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the license files for details.
*
* For details please refer to: http://www.datatables.net
*/
(function( window, document, undefined ) {
var factory = function( $, DataTable ) {
"use strict";
/**
* AutoFill provides Excel like auto-fill features for a DataTable
*
* @class AutoFill
* @constructor
* @param {object} oTD DataTables settings object
* @param {object} oConfig Configuration object for AutoFill
*/
var AutoFill = function( oDT, oConfig )
{
/* Sanity check that we are a new instance */
if ( ! (this instanceof AutoFill) ) {
throw( "Warning: AutoFill must be initialised with the keyword 'new'" );
}
if ( ! $.fn.dataTableExt.fnVersionCheck('1.7.0') ) {
throw( "Warning: AutoFill requires DataTables 1.7 or greater");
}
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* Public class variables
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
this.c = {};
/**
* @namespace Settings object which contains customisable information for AutoFill instance
*/
this.s = {
/**
* @namespace Cached information about the little dragging icon (the filler)
*/
"filler": {
"height": 0,
"width": 0
},
/**
* @namespace Cached information about the border display
*/
"border": {
"width": 2
},
/**
* @namespace Store for live information for the current drag
*/
"drag": {
"startX": -1,
"startY": -1,
"startTd": null,
"endTd": null,
"dragging": false
},
/**
* @namespace Data cache for information that we need for scrolling the screen when we near
* the edges
*/
"screen": {
"interval": null,
"y": 0,
"height": 0,
"scrollTop": 0
},
/**
* @namespace Data cache for the position of the DataTables scrolling element (when scrolling
* is enabled)
*/
"scroller": {
"top": 0,
"bottom": 0
},
/**
* @namespace Information stored for each column. An array of objects
*/
"columns": []
};
/**
* @namespace Common and useful DOM elements for the class instance
*/
this.dom = {
"table": null,
"filler": null,
"borderTop": null,
"borderRight": null,
"borderBottom": null,
"borderLeft": null,
"currentTarget": null
};
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* Public class methods
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/**
* Retreieve the settings object from an instance
* @method fnSettings
* @returns {object} AutoFill settings object
*/
this.fnSettings = function () {
return this.s;
};
/* Constructor logic */
this._fnInit( oDT, oConfig );
return this;
};
AutoFill.prototype = {
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* Private methods (they are of course public in JS, but recommended as private)
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/**
* Initialisation
* @method _fnInit
* @param {object} dt DataTables settings object
* @param {object} config Configuration object for AutoFill
* @returns void
*/
"_fnInit": function ( dt, config )
{
var
that = this,
i, iLen;
// Use DataTables API to get the settings allowing selectors, instances
// etc to be used, or for backwards compatibility get from the old
// fnSettings method
this.s.dt = DataTable.Api ?
new DataTable.Api( dt ).settings()[0] :
dt.fnSettings();
this.s.init = config || {};
this.dom.table = this.s.dt.nTable;
$.extend( true, this.c, AutoFill.defaults, config );
/* Add and configure the columns */
this._initColumns();
/* Auto Fill click and drag icon */
var filler = $('<div/>', {
'class': 'AutoFill_filler'
} )
.appendTo( 'body' );
this.dom.filler = filler[0];
// Get the height / width of the click element
this.s.filler.height = filler.height();
this.s.filler.width = filler.width();
filler[0].style.display = "none";
/* Border display - one div for each side. We can't just use a single
* one with a border, as we want the events to effectively pass through
* the transparent bit of the box
*/
var border;
var appender = document.body;
if ( that.s.dt.oScroll.sY !== "" ) {
that.s.dt.nTable.parentNode.style.position = "relative";
appender = that.s.dt.nTable.parentNode;
}
border = $('<div/>', {
"class": "AutoFill_border"
} );
this.dom.borderTop = border.clone().appendTo( appender )[0];
this.dom.borderRight = border.clone().appendTo( appender )[0];
this.dom.borderBottom = border.clone().appendTo( appender )[0];
this.dom.borderLeft = border.clone().appendTo( appender )[0];
/* Events */
filler.on( 'mousedown.DTAF', function (e) {
this.onselectstart = function() { return false; };
that._fnFillerDragStart.call( that, e );
return false;
} );
$('tbody', this.dom.table).on(
'mouseover.DTAF mouseout.DTAF',
'>tr>td, >tr>th',
function (e) {
that._fnFillerDisplay.call( that, e );
}
);
$(this.dom.table).on( 'destroy.dt.DTAF', function () {
filler.off( 'mousedown.DTAF' ).remove();
$('tbody', this.dom.table).off( 'mouseover.DTAF mouseout.DTAF' );
} );
},
_initColumns: function ( )
{
var that = this;
var i, ien;
var dt = this.s.dt;
var config = this.s.init;
for ( i=0, ien=dt.aoColumns.length ; i<ien ; i++ ) {
this.s.columns[i] = $.extend( true, {}, AutoFill.defaults.column );
}
dt.oApi._fnApplyColumnDefs(
dt,
config.aoColumnDefs || config.columnDefs,
config.aoColumns || config.columns,
function (colIdx, def) {
that._fnColumnOptions( colIdx, def );
}
);
// For columns which don't have read, write, step functions defined,
// use the default ones
for ( i=0, ien=dt.aoColumns.length ; i<ien ; i++ ) {
var column = this.s.columns[i];
if ( ! column.read ) {
column.read = this._fnReadCell;
}
if ( ! column.write ) {
column.read = this._fnWriteCell;
}
if ( ! column.step ) {
column.read = this._fnStep;
}
}
},
"_fnColumnOptions": function ( i, opts )
{
var column = this.s.columns[ i ];
var set = function ( outProp, inProp ) {
if ( opts[ inProp[0] ] !== undefined ) {
column[ outProp ] = opts[ inProp[0] ];
}
if ( opts[ inProp[1] ] !== undefined ) {
column[ outProp ] = opts[ inProp[1] ];
}
};
// Compatibility with the old Hungarian style of notation
set( 'enable', ['bEnable', 'enable'] );
set( 'read', ['fnRead', 'read'] );
set( 'write', ['fnWrite', 'write'] );
set( 'step', ['fnStep', 'step'] );
set( 'increment', ['bIncrement', 'increment'] );
},
/**
* Find out the coordinates of a given TD cell in a table
* @method _fnTargetCoords
* @param {Node} nTd
* @returns {Object} x and y properties, for the position of the cell in the tables DOM
*/
"_fnTargetCoords": function ( nTd )
{
var nTr = $(nTd).parents('tr')[0];
var position = this.s.dt.oInstance.fnGetPosition( nTd );
return {
"x": $('td', nTr).index(nTd),
"y": $('tr', nTr.parentNode).index(nTr),
"row": position[0],
"column": position[2]
};
},
/**
* Display the border around one or more cells (from start to end)
* @method _fnUpdateBorder
* @param {Node} nStart Starting cell
* @param {Node} nEnd Ending cell
* @returns void
*/
"_fnUpdateBorder": function ( nStart, nEnd )
{
var
border = this.s.border.width,
offsetStart = $(nStart).offset(),
offsetEnd = $(nEnd).offset(),
x1 = offsetStart.left - border,
x2 = offsetEnd.left + $(nEnd).outerWidth(),
y1 = offsetStart.top - border,
y2 = offsetEnd.top + $(nEnd).outerHeight(),
width = offsetEnd.left + $(nEnd).outerWidth() - offsetStart.left + (2*border),
height = offsetEnd.top + $(nEnd).outerHeight() - offsetStart.top + (2*border),
oStyle;
// Recalculate start and end (when dragging "backwards")
if( offsetStart.left > offsetEnd.left) {
x1 = offsetEnd.left - border;
x2 = offsetStart.left + $(nStart).outerWidth();
width = offsetStart.left + $(nStart).outerWidth() - offsetEnd.left + (2*border);
}
if ( this.s.dt.oScroll.sY !== "" )
{
/* The border elements are inside the DT scroller - so position relative to that */
var
offsetScroll = $(this.s.dt.nTable.parentNode).offset(),
scrollTop = $(this.s.dt.nTable.parentNode).scrollTop(),
scrollLeft = $(this.s.dt.nTable.parentNode).scrollLeft();
x1 -= offsetScroll.left - scrollLeft;
x2 -= offsetScroll.left - scrollLeft;
y1 -= offsetScroll.top - scrollTop;
y2 -= offsetScroll.top - scrollTop;
}
/* Top */
oStyle = this.dom.borderTop.style;
oStyle.top = y1+"px";
oStyle.left = x1+"px";
oStyle.height = this.s.border.width+"px";
oStyle.width = width+"px";
/* Bottom */
oStyle = this.dom.borderBottom.style;
oStyle.top = y2+"px";
oStyle.left = x1+"px";
oStyle.height = this.s.border.width+"px";
oStyle.width = width+"px";
/* Left */
oStyle = this.dom.borderLeft.style;
oStyle.top = y1+"px";
oStyle.left = x1+"px";
oStyle.height = height+"px";
oStyle.width = this.s.border.width+"px";
/* Right */
oStyle = this.dom.borderRight.style;
oStyle.top = y1+"px";
oStyle.left = x2+"px";
oStyle.height = height+"px";
oStyle.width = this.s.border.width+"px";
},
/**
* Mouse down event handler for starting a drag
* @method _fnFillerDragStart
* @param {Object} e Event object
* @returns void
*/
"_fnFillerDragStart": function (e)
{
var that = this;
var startingTd = this.dom.currentTarget;
this.s.drag.dragging = true;
that.dom.borderTop.style.display = "block";
that.dom.borderRight.style.display = "block";
that.dom.borderBottom.style.display = "block";
that.dom.borderLeft.style.display = "block";
var coords = this._fnTargetCoords( startingTd );
this.s.drag.startX = coords.x;
this.s.drag.startY = coords.y;
this.s.drag.startTd = startingTd;
this.s.drag.endTd = startingTd;
this._fnUpdateBorder( startingTd, startingTd );
$(document).bind('mousemove.AutoFill', function (e) {
that._fnFillerDragMove.call( that, e );
} );
$(document).bind('mouseup.AutoFill', function (e) {
that._fnFillerFinish.call( that, e );
} );
/* Scrolling information cache */
this.s.screen.y = e.pageY;
this.s.screen.height = $(window).height();
this.s.screen.scrollTop = $(document).scrollTop();
if ( this.s.dt.oScroll.sY !== "" )
{
this.s.scroller.top = $(this.s.dt.nTable.parentNode).offset().top;
this.s.scroller.bottom = this.s.scroller.top + $(this.s.dt.nTable.parentNode).height();
}
/* Scrolling handler - we set an interval (which is cancelled on mouse up) which will fire
* regularly and see if we need to do any scrolling
*/
this.s.screen.interval = setInterval( function () {
var iScrollTop = $(document).scrollTop();
var iScrollDelta = iScrollTop - that.s.screen.scrollTop;
that.s.screen.y += iScrollDelta;
if ( that.s.screen.height - that.s.screen.y + iScrollTop < 50 )
{
$('html, body').animate( {
"scrollTop": iScrollTop + 50
}, 240, 'linear' );
}
else if ( that.s.screen.y - iScrollTop < 50 )
{
$('html, body').animate( {
"scrollTop": iScrollTop - 50
}, 240, 'linear' );
}
if ( that.s.dt.oScroll.sY !== "" )
{
if ( that.s.screen.y > that.s.scroller.bottom - 50 )
{
$(that.s.dt.nTable.parentNode).animate( {
"scrollTop": $(that.s.dt.nTable.parentNode).scrollTop() + 50
}, 240, 'linear' );
}
else if ( that.s.screen.y < that.s.scroller.top + 50 )
{
$(that.s.dt.nTable.parentNode).animate( {
"scrollTop": $(that.s.dt.nTable.parentNode).scrollTop() - 50
}, 240, 'linear' );
}
}
}, 250 );
},
/**
* Mouse move event handler for during a move. See if we want to update the display based on the
* new cursor position
* @method _fnFillerDragMove
* @param {Object} e Event object
* @returns void
*/
"_fnFillerDragMove": function (e)
{
if ( e.target && e.target.nodeName.toUpperCase() == "TD" &&
e.target != this.s.drag.endTd )
{
var coords = this._fnTargetCoords( e.target );
if ( this.c.mode == "y" && coords.x != this.s.drag.startX )
{
e.target = $('tbody>tr:eq('+coords.y+')>td:eq('+this.s.drag.startX+')', this.dom.table)[0];
}
if ( this.c.mode == "x" && coords.y != this.s.drag.startY )
{
e.target = $('tbody>tr:eq('+this.s.drag.startY+')>td:eq('+coords.x+')', this.dom.table)[0];
}
if ( this.c.mode == "either")
{
if(coords.x != this.s.drag.startX )
{
e.target = $('tbody>tr:eq('+this.s.drag.startY+')>td:eq('+coords.x+')', this.dom.table)[0];
}
else if ( coords.y != this.s.drag.startY ) {
e.target = $('tbody>tr:eq('+coords.y+')>td:eq('+this.s.drag.startX+')', this.dom.table)[0];
}
}
// update coords
if ( this.c.mode !== "both" ) {
coords = this._fnTargetCoords( e.target );
}
var drag = this.s.drag;
drag.endTd = e.target;
if ( coords.y >= this.s.drag.startY ) {
this._fnUpdateBorder( drag.startTd, drag.endTd );
}
else {
this._fnUpdateBorder( drag.endTd, drag.startTd );
}
this._fnFillerPosition( e.target );
}
/* Update the screen information so we can perform scrolling */
this.s.screen.y = e.pageY;
this.s.screen.scrollTop = $(document).scrollTop();
if ( this.s.dt.oScroll.sY !== "" )
{
this.s.scroller.scrollTop = $(this.s.dt.nTable.parentNode).scrollTop();
this.s.scroller.top = $(this.s.dt.nTable.parentNode).offset().top;
this.s.scroller.bottom = this.s.scroller.top + $(this.s.dt.nTable.parentNode).height();
}
},
/**
* Mouse release handler - end the drag and take action to update the cells with the needed values
* @method _fnFillerFinish
* @param {Object} e Event object
* @returns void
*/
"_fnFillerFinish": function (e)
{
var that = this, i, iLen, j;
$(document).unbind('mousemove.AutoFill mouseup.AutoFill');
this.dom.borderTop.style.display = "none";
this.dom.borderRight.style.display = "none";
this.dom.borderBottom.style.display = "none";
this.dom.borderLeft.style.display = "none";
this.s.drag.dragging = false;
clearInterval( this.s.screen.interval );
var cells = [];
var table = this.dom.table;
var coordsStart = this._fnTargetCoords( this.s.drag.startTd );
var coordsEnd = this._fnTargetCoords( this.s.drag.endTd );
var columnIndex = function ( visIdx ) {
return that.s.dt.oApi._fnVisibleToColumnIndex( that.s.dt, visIdx );
};
// xxx - urgh - there must be a way of reducing this...
if ( coordsStart.y <= coordsEnd.y ) {
for ( i=coordsStart.y ; i<=coordsEnd.y ; i++ ) {
if ( coordsStart.x <= coordsEnd.x ) {
for ( j=coordsStart.x ; j<=coordsEnd.x ; j++ ) {
cells.push( {
node: $('tbody>tr:eq('+i+')>td:eq('+j+')', table)[0],
x: j - coordsStart.x,
y: i - coordsStart.y,
colIdx: columnIndex( j )
} );
}
}
else {
for ( j=coordsStart.x ; j>=coordsEnd.x ; j-- ) {
cells.push( {
node: $('tbody>tr:eq('+i+')>td:eq('+j+')', table)[0],
x: j - coordsStart.x,
y: i - coordsStart.y,
colIdx: columnIndex( j )
} );
}
}
}
}
else {
for ( i=coordsStart.y ; i>=coordsEnd.y ; i-- ) {
if ( coordsStart.x <= coordsEnd.x ) {
for ( j=coordsStart.x ; j<=coordsEnd.x ; j++ ) {
cells.push( {
node: $('tbody>tr:eq('+i+')>td:eq('+j+')', table)[0],
x: j - coordsStart.x,
y: i - coordsStart.y,
colIdx: columnIndex( j )
} );
}
}
else {
for ( j=coordsStart.x ; j>=coordsEnd.x ; j-- ) {
cells.push( {
node: $('tbody>tr:eq('+i+')>td:eq('+j+')', table)[0],
x: coordsStart.x - j,
y: coordsStart.y - i,
colIdx: columnIndex( j )
} );
}
}
}
}
// An auto-fill requires 2 or more cells
if ( cells.length <= 1 ) {
return;
}
var edited = [];
var previous;
for ( i=0, iLen=cells.length ; i<iLen ; i++ ) {
var cell = cells[i];
var column = this.s.columns[ cell.colIdx ];
var read = column.read.call( column, cell.node );
var stepValue = column.step.call( column, cell.node, read, previous, i, cell.x, cell.y );
column.write.call( column, cell.node, stepValue );
previous = stepValue;
edited.push( {
cell: cell,
colIdx: cell.colIdx,
newValue: stepValue,
oldValue: read
} );
}
if ( this.c.complete !== null ) {
this.c.complete.call( this, edited );
}
// In 1.10 we can do a static draw
if ( DataTable.Api ) {
new DataTable.Api( this.s.dt ).draw( false );
}
else {
this.s.dt.oInstance.fnDraw();
}
},
/**
* Display the drag handle on mouse over cell
* @method _fnFillerDisplay
* @param {Object} e Event object
* @returns void
*/
"_fnFillerDisplay": function (e)
{
var filler = this.dom.filler;
/* Don't display automatically when dragging */
if ( this.s.drag.dragging)
{
return;
}
/* Check that we are allowed to AutoFill this column or not */
var nTd = (e.target.nodeName.toLowerCase() == 'td') ? e.target : $(e.target).parents('td')[0];
var iX = this._fnTargetCoords(nTd).column;
if ( !this.s.columns[iX].enable )
{
filler.style.display = "none";
return;
}
if (e.type == 'mouseover')
{
this.dom.currentTarget = nTd;
this._fnFillerPosition( nTd );
filler.style.display = "block";
}
else if ( !e.relatedTarget || !e.relatedTarget.className.match(/AutoFill/) )
{
filler.style.display = "none";
}
},
/**
* Position the filler icon over a cell
* @method _fnFillerPosition
* @param {Node} nTd Cell to position filler icon over
* @returns void
*/
"_fnFillerPosition": function ( nTd )
{
var offset = $(nTd).offset();
var filler = this.dom.filler;
filler.style.top = (offset.top - (this.s.filler.height / 2)-1 + $(nTd).outerHeight())+"px";
filler.style.left = (offset.left - (this.s.filler.width / 2)-1 + $(nTd).outerWidth())+"px";
}
};
// Alias for access
DataTable.AutoFill = AutoFill;
DataTable.AutoFill = AutoFill;
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* Constants
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/**
* AutoFill version
* @constant version
* @type String
* @default See code
*/
AutoFill.version = "1.2.1";
/**
* AutoFill defaults
* @namespace
*/
AutoFill.defaults = {
/**
* Mode for dragging (restrict to y-axis only, x-axis only, either one or none):
*
* * `y` - y-axis only (default)
* * `x` - x-axis only
* * `either` - either one, but not both axis at the same time
* * `both` - multiple cells allowed
*
* @type {string}
* @default `y`
*/
mode: 'y',
complete: null,
/**
* Column definition defaults
* @namespace
*/
column: {
/**
* If AutoFill should be enabled on this column
*
* @type {boolean}
* @default true
*/
enable: true,
/**
* Allow automatic increment / decrement on this column if a number
* is found.
*
* @type {boolean}
* @default true
*/
increment: true,
/**
* Cell read function
*
* Default function will simply read the value from the HTML of the
* cell.
*
* @type {function}
* @param {node} cell `th` / `td` element to read the value from
* @return {string} Data that has been read
*/
read: function ( cell ) {
return $(cell).html();
},
/**
* Cell write function
*
* Default function will simply write to the HTML and tell the DataTable
* to update.
*
* @type {function}
* @param {node} cell `th` / `td` element to write the value to
* @return {string} Data two write
*/
write: function ( cell, val ) {
var table = $(cell).parents('table');
if ( DataTable.Api ) {
// 1.10
table.DataTable().cell( cell ).data( val );
}
else {
// 1.9
var dt = table.dataTable();
var pos = dt.fnGetPosition( cell );
dt.fnUpdate( val, pos[0], pos[2], false );
}
},
/**
* Step function. This provides the ability to customise how the values
* are incremented.
*
* @param {node} cell `th` / `td` element that is being operated upon
* @param {string} read Cell value from `read` function
* @param {string} last Value of the previous cell
* @param {integer} i Loop counter
* @param {integer} x Cell x-position in the current auto-fill. The
* starting cell is coordinate 0 regardless of its physical position
* in the DataTable.
* @param {integer} y Cell y-position in the current auto-fill. The
* starting cell is coordinate 0 regardless of its physical position
* in the DataTable.
* @return {string} Value to write
*/
step: function ( cell, read, last, i, x, y ) {
// Increment a number if it is found
var re = /(\-?\d+)/;
var match = this.increment && last ? last.match(re) : null;
if ( match ) {
return last.replace( re, parseInt(match[1],10) + (x<0 || y<0 ? -1 : 1) );
}
return last === undefined ?
read :
last;
}
}
};
return AutoFill;
};
// Define as an AMD module if possible
if ( typeof define === 'function' && define.amd ) {
define( ['jquery', 'datatables'], factory );
}
else if ( typeof exports === 'object' ) {
// Node/CommonJS
factory( require('jquery'), require('datatables') );
}
else if ( jQuery && !jQuery.fn.dataTable.AutoFill ) {
// Otherwise simply initialise as normal, stopping multiple evaluation
factory( jQuery, jQuery.fn.dataTable );
}
}(window, document));

@ -0,0 +1,22 @@
/*!
AutoFill 1.2.1
©2008-2014 SpryMedia Ltd - datatables.net/license
*/
(function(o,j,m){var l=function(c,k){var h=function(d,b){if(!(this instanceof h))throw"Warning: AutoFill must be initialised with the keyword 'new'";if(!c.fn.dataTableExt.fnVersionCheck("1.7.0"))throw"Warning: AutoFill requires DataTables 1.7 or greater";this.c={};this.s={filler:{height:0,width:0},border:{width:2},drag:{startX:-1,startY:-1,startTd:null,endTd:null,dragging:!1},screen:{interval:null,y:0,height:0,scrollTop:0},scroller:{top:0,bottom:0},columns:[]};this.dom={table:null,filler:null,borderTop:null,
borderRight:null,borderBottom:null,borderLeft:null,currentTarget:null};this.fnSettings=function(){return this.s};this._fnInit(d,b);return this};h.prototype={_fnInit:function(d,b){var a=this;this.s.dt=k.Api?(new k.Api(d)).settings()[0]:d.fnSettings();this.s.init=b||{};this.dom.table=this.s.dt.nTable;c.extend(!0,this.c,h.defaults,b);this._initColumns();var e=c("<div/>",{"class":"AutoFill_filler"}).appendTo("body");this.dom.filler=e[0];this.s.filler.height=e.height();this.s.filler.width=e.width();e[0].style.display=
"none";var g,f=j.body;""!==a.s.dt.oScroll.sY&&(a.s.dt.nTable.parentNode.style.position="relative",f=a.s.dt.nTable.parentNode);g=c("<div/>",{"class":"AutoFill_border"});this.dom.borderTop=g.clone().appendTo(f)[0];this.dom.borderRight=g.clone().appendTo(f)[0];this.dom.borderBottom=g.clone().appendTo(f)[0];this.dom.borderLeft=g.clone().appendTo(f)[0];e.on("mousedown.DTAF",function(b){this.onselectstart=function(){return false};a._fnFillerDragStart.call(a,b);return false});c("tbody",this.dom.table).on("mouseover.DTAF mouseout.DTAF",
">tr>td, >tr>th",function(b){a._fnFillerDisplay.call(a,b)});c(this.dom.table).on("destroy.dt.DTAF",function(){e.off("mousedown.DTAF").remove();c("tbody",this.dom.table).off("mouseover.DTAF mouseout.DTAF")})},_initColumns:function(){var d=this,b,a,e=this.s.dt,g=this.s.init;b=0;for(a=e.aoColumns.length;b<a;b++)this.s.columns[b]=c.extend(!0,{},h.defaults.column);e.oApi._fnApplyColumnDefs(e,g.aoColumnDefs||g.columnDefs,g.aoColumns||g.columns,function(a,b){d._fnColumnOptions(a,b)});b=0;for(a=e.aoColumns.length;b<
a;b++)if(e=this.s.columns[b],e.read||(e.read=this._fnReadCell),e.write||(e.read=this._fnWriteCell),!e.step)e.read=this._fnStep},_fnColumnOptions:function(d,b){var a=this.s.columns[d],c=function(c,d){b[d[0]]!==m&&(a[c]=b[d[0]]);b[d[1]]!==m&&(a[c]=b[d[1]])};c("enable",["bEnable","enable"]);c("read",["fnRead","read"]);c("write",["fnWrite","write"]);c("step",["fnStep","step"]);c("increment",["bIncrement","increment"])},_fnTargetCoords:function(d){var b=c(d).parents("tr")[0],a=this.s.dt.oInstance.fnGetPosition(d);
return{x:c("td",b).index(d),y:c("tr",b.parentNode).index(b),row:a[0],column:a[2]}},_fnUpdateBorder:function(d,b){var a=this.s.border.width,e=c(d).offset(),g=c(b).offset(),f=e.left-a,i=g.left+c(b).outerWidth(),n=e.top-a,h=g.top+c(b).outerHeight(),j=g.left+c(b).outerWidth()-e.left+2*a,k=g.top+c(b).outerHeight()-e.top+2*a;e.left>g.left&&(f=g.left-a,i=e.left+c(d).outerWidth(),j=e.left+c(d).outerWidth()-g.left+2*a);""!==this.s.dt.oScroll.sY&&(a=c(this.s.dt.nTable.parentNode).offset(),e=c(this.s.dt.nTable.parentNode).scrollTop(),
g=c(this.s.dt.nTable.parentNode).scrollLeft(),f-=a.left-g,i-=a.left-g,n-=a.top-e,h-=a.top-e);a=this.dom.borderTop.style;a.top=n+"px";a.left=f+"px";a.height=this.s.border.width+"px";a.width=j+"px";a=this.dom.borderBottom.style;a.top=h+"px";a.left=f+"px";a.height=this.s.border.width+"px";a.width=j+"px";a=this.dom.borderLeft.style;a.top=n+"px";a.left=f+"px";a.height=k+"px";a.width=this.s.border.width+"px";a=this.dom.borderRight.style;a.top=n+"px";a.left=i+"px";a.height=k+"px";a.width=this.s.border.width+
"px"},_fnFillerDragStart:function(d){var b=this,a=this.dom.currentTarget;this.s.drag.dragging=!0;b.dom.borderTop.style.display="block";b.dom.borderRight.style.display="block";b.dom.borderBottom.style.display="block";b.dom.borderLeft.style.display="block";var e=this._fnTargetCoords(a);this.s.drag.startX=e.x;this.s.drag.startY=e.y;this.s.drag.startTd=a;this.s.drag.endTd=a;this._fnUpdateBorder(a,a);c(j).bind("mousemove.AutoFill",function(a){b._fnFillerDragMove.call(b,a)});c(j).bind("mouseup.AutoFill",
function(a){b._fnFillerFinish.call(b,a)});this.s.screen.y=d.pageY;this.s.screen.height=c(o).height();this.s.screen.scrollTop=c(j).scrollTop();""!==this.s.dt.oScroll.sY&&(this.s.scroller.top=c(this.s.dt.nTable.parentNode).offset().top,this.s.scroller.bottom=this.s.scroller.top+c(this.s.dt.nTable.parentNode).height());this.s.screen.interval=setInterval(function(){var a=c(j).scrollTop();b.s.screen.y=b.s.screen.y+(a-b.s.screen.scrollTop);b.s.screen.height-b.s.screen.y+a<50?c("html, body").animate({scrollTop:a+
50},240,"linear"):b.s.screen.y-a<50&&c("html, body").animate({scrollTop:a-50},240,"linear");b.s.dt.oScroll.sY!==""&&(b.s.screen.y>b.s.scroller.bottom-50?c(b.s.dt.nTable.parentNode).animate({scrollTop:c(b.s.dt.nTable.parentNode).scrollTop()+50},240,"linear"):b.s.screen.y<b.s.scroller.top+50&&c(b.s.dt.nTable.parentNode).animate({scrollTop:c(b.s.dt.nTable.parentNode).scrollTop()-50},240,"linear"))},250)},_fnFillerDragMove:function(d){if(d.target&&"TD"==d.target.nodeName.toUpperCase()&&d.target!=this.s.drag.endTd){var b=
this._fnTargetCoords(d.target);"y"==this.c.mode&&b.x!=this.s.drag.startX&&(d.target=c("tbody>tr:eq("+b.y+")>td:eq("+this.s.drag.startX+")",this.dom.table)[0]);"x"==this.c.mode&&b.y!=this.s.drag.startY&&(d.target=c("tbody>tr:eq("+this.s.drag.startY+")>td:eq("+b.x+")",this.dom.table)[0]);"either"==this.c.mode&&(b.x!=this.s.drag.startX?d.target=c("tbody>tr:eq("+this.s.drag.startY+")>td:eq("+b.x+")",this.dom.table)[0]:b.y!=this.s.drag.startY&&(d.target=c("tbody>tr:eq("+b.y+")>td:eq("+this.s.drag.startX+
")",this.dom.table)[0]));"both"!==this.c.mode&&(b=this._fnTargetCoords(d.target));var a=this.s.drag;a.endTd=d.target;b.y>=this.s.drag.startY?this._fnUpdateBorder(a.startTd,a.endTd):this._fnUpdateBorder(a.endTd,a.startTd);this._fnFillerPosition(d.target)}this.s.screen.y=d.pageY;this.s.screen.scrollTop=c(j).scrollTop();""!==this.s.dt.oScroll.sY&&(this.s.scroller.scrollTop=c(this.s.dt.nTable.parentNode).scrollTop(),this.s.scroller.top=c(this.s.dt.nTable.parentNode).offset().top,this.s.scroller.bottom=
this.s.scroller.top+c(this.s.dt.nTable.parentNode).height())},_fnFillerFinish:function(){var d=this,b,a;c(j).unbind("mousemove.AutoFill mouseup.AutoFill");this.dom.borderTop.style.display="none";this.dom.borderRight.style.display="none";this.dom.borderBottom.style.display="none";this.dom.borderLeft.style.display="none";this.s.drag.dragging=!1;clearInterval(this.s.screen.interval);var e=[],g=this.dom.table,f=this._fnTargetCoords(this.s.drag.startTd),i=this._fnTargetCoords(this.s.drag.endTd),h=function(a){return d.s.dt.oApi._fnVisibleToColumnIndex(d.s.dt,
a)};if(f.y<=i.y)for(b=f.y;b<=i.y;b++)if(f.x<=i.x)for(a=f.x;a<=i.x;a++)e.push({node:c("tbody>tr:eq("+b+")>td:eq("+a+")",g)[0],x:a-f.x,y:b-f.y,colIdx:h(a)});else for(a=f.x;a>=i.x;a--)e.push({node:c("tbody>tr:eq("+b+")>td:eq("+a+")",g)[0],x:a-f.x,y:b-f.y,colIdx:h(a)});else for(b=f.y;b>=i.y;b--)if(f.x<=i.x)for(a=f.x;a<=i.x;a++)e.push({node:c("tbody>tr:eq("+b+")>td:eq("+a+")",g)[0],x:a-f.x,y:b-f.y,colIdx:h(a)});else for(a=f.x;a>=i.x;a--)e.push({node:c("tbody>tr:eq("+b+")>td:eq("+a+")",g)[0],x:f.x-a,y:f.y-
b,colIdx:h(a)});if(!(1>=e.length)){var g=[],m;b=0;for(a=e.length;b<a;b++){var f=e[b],i=this.s.columns[f.colIdx],h=i.read.call(i,f.node),l=i.step.call(i,f.node,h,m,b,f.x,f.y);i.write.call(i,f.node,l);m=l;g.push({cell:f,colIdx:f.colIdx,newValue:l,oldValue:h})}null!==this.c.complete&&this.c.complete.call(this,g);k.Api?(new k.Api(this.s.dt)).draw(!1):this.s.dt.oInstance.fnDraw()}},_fnFillerDisplay:function(d){var b=this.dom.filler;if(!this.s.drag.dragging){var a="td"==d.target.nodeName.toLowerCase()?
d.target:c(d.target).parents("td")[0],e=this._fnTargetCoords(a).column;if(this.s.columns[e].enable)if("mouseover"==d.type)this.dom.currentTarget=a,this._fnFillerPosition(a),b.style.display="block";else{if(!d.relatedTarget||!d.relatedTarget.className.match(/AutoFill/))b.style.display="none"}else b.style.display="none"}},_fnFillerPosition:function(d){var b=c(d).offset(),a=this.dom.filler;a.style.top=b.top-this.s.filler.height/2-1+c(d).outerHeight()+"px";a.style.left=b.left-this.s.filler.width/2-1+c(d).outerWidth()+
"px"}};k.AutoFill=h;k.AutoFill=h;h.version="1.2.1";h.defaults={mode:"y",complete:null,column:{enable:!0,increment:!0,read:function(d){return c(d).html()},write:function(d,b){var a=c(d).parents("table");if(k.Api)a.DataTable().cell(d).data(b);else{var a=a.dataTable(),e=a.fnGetPosition(d);a.fnUpdate(b,e[0],e[2],!1)}},step:function(c,b,a,e,g,f){c=/(\-?\d+)/;return(e=this.increment&&a?a.match(c):null)?a.replace(c,parseInt(e[1],10)+(0>g||0>f?-1:1)):a===m?b:a}}};return h};"function"===typeof define&&define.amd?
define(["jquery","datatables"],l):"object"===typeof exports?l(require("jquery"),require("datatables")):jQuery&&!jQuery.fn.dataTable.AutoFill&&l(jQuery,jQuery.fn.dataTable)})(window,document);

Some files were not shown because too many files have changed in this diff Show More

Loading…
Cancel
Save