mirror of
https://github.com/abcv7/sfbx-cloud.git
synced 2026-08-16 19:49:49 +00:00
功能:在保险、规则、交易、积分和短信模块中实现初始功能和基础组件。
This commit is contained in:
@@ -0,0 +1,21 @@
|
||||
FROM openjdk:11-jdk
|
||||
LABEL maintainer="研究院研发组 <research@itcast.cn>"
|
||||
|
||||
# 时区修改为东八区
|
||||
ENV TZ=Asia/Shanghai
|
||||
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
|
||||
|
||||
WORKDIR /rule-web
|
||||
ARG JAR_FILE=target/*.jar
|
||||
ADD ${JAR_FILE} rule-web.jar
|
||||
|
||||
EXPOSE 8080
|
||||
|
||||
ENV JAVA_OPTS="\
|
||||
-server \
|
||||
-Xms256m \
|
||||
-Xmx1024m \
|
||||
-XX:MetaspaceSize=256m \
|
||||
-XX:MaxMetaspaceSize=512m\
|
||||
-Dspring.profiles.active=test"
|
||||
ENTRYPOINT ["sh","-c","java -Djava.security.egd=file:/dev/./urandom -jar $JAVA_OPTS rule-web.jar"]
|
||||
@@ -0,0 +1,123 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<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">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>com.itheima.sfbx</groupId>
|
||||
<artifactId>sfbx-rule</artifactId>
|
||||
<version>2.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
<artifactId>rule-web</artifactId>
|
||||
|
||||
<name>rule-web</name>
|
||||
<!-- FIXME change it to the project's website -->
|
||||
<url>http://www.example.com</url>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.itheima.sfbx</groupId>
|
||||
<artifactId>framework-rule-base</artifactId>
|
||||
<version>2.0-SNAPSHOT</version>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-jdk14</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<!--数据库驱动-->
|
||||
<dependency>
|
||||
<groupId>mysql</groupId>
|
||||
<artifactId>mysql-connector-java</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.jackrabbit</groupId>
|
||||
<artifactId>jackrabbit-core</artifactId>
|
||||
<version>2.13.3</version>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<artifactId>derby</artifactId>
|
||||
<groupId>org.apache.derby</groupId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>commons-dbcp</groupId>
|
||||
<artifactId>commons-dbcp</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>commons-pool</groupId>
|
||||
<artifactId>commons-pool</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>javax.jcr</groupId>
|
||||
<artifactId>jcr</artifactId>
|
||||
<version>2.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>commons-fileupload</groupId>
|
||||
<artifactId>commons-fileupload</artifactId>
|
||||
<version>1.3.2</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.velocity</groupId>
|
||||
<artifactId>velocity</artifactId>
|
||||
<version>1.7</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.poi</groupId>
|
||||
<artifactId>poi-ooxml</artifactId>
|
||||
<version>3.16</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-configuration-processor</artifactId>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-jdbc</artifactId>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-logging</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>com.zaxxer</groupId>
|
||||
<artifactId>HikariCP</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>druid-spring-boot-starter</artifactId>
|
||||
<version>1.1.9</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<finalName>rule-web</finalName>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
<goal>repackage</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
||||
@@ -0,0 +1,14 @@
|
||||
package com.itheima.sfbx.rule;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
/**
|
||||
* 本地规则引擎
|
||||
*/
|
||||
@SpringBootApplication
|
||||
public class RuleStart {
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(RuleStart.class, args);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
//package com.itheima.sfbx.rule.action;
|
||||
//
|
||||
//import cn.hutool.http.HttpRequest;
|
||||
//import cn.hutool.http.HttpUtil;
|
||||
//import com.itheima.sfbx.framework.rule.RuleException;
|
||||
//import com.itheima.sfbx.framework.rule.model.library.action.annotation.ActionBean;
|
||||
//import com.itheima.sfbx.framework.rule.model.library.action.annotation.ActionMethod;
|
||||
//import com.itheima.sfbx.framework.rule.model.library.action.annotation.ActionMethodParameter;
|
||||
//import org.apache.commons.lang.StringUtils;
|
||||
//import org.springframework.stereotype.Component;
|
||||
//
|
||||
//import java.text.ParseException;
|
||||
//import java.text.SimpleDateFormat;
|
||||
//import java.util.Date;
|
||||
//
|
||||
///**
|
||||
// * LogAction
|
||||
// *
|
||||
// * @author: wgl
|
||||
// * @describe: TODO
|
||||
// * @date: 2022/12/28 10:10
|
||||
// */
|
||||
//@ActionBean(name="日志")
|
||||
//@Component
|
||||
//public class LogAction {
|
||||
//
|
||||
// @ActionMethod(name="记录规则执行日志")
|
||||
// @ActionMethodParameter(names={"校验结果","校验描述"})
|
||||
// public void saveLog(Boolean checkResult, String des){
|
||||
// String url = "http://127.0.0.1:7065/log/"+checkResult+"/"+des;
|
||||
// HttpRequest get = HttpUtil.createGet(url);
|
||||
// // 如果有cookie 或者token进行鉴权,可以在此添加
|
||||
// String body = get.execute().body();
|
||||
// System.out.println(body);
|
||||
// }
|
||||
//}
|
||||
@@ -0,0 +1,18 @@
|
||||
package com.itheima.sfbx.rule.config;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.http.HttpServlet;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
public class IndexServlet extends HttpServlet {
|
||||
|
||||
private static final long serialVersionUID = 9155627652423910928L;
|
||||
|
||||
@Override
|
||||
protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
|
||||
resp.sendRedirect(req.getContextPath()+"/urule/frame");
|
||||
}
|
||||
}
|
||||
+43
@@ -0,0 +1,43 @@
|
||||
package com.itheima.sfbx.rule.config;
|
||||
|
||||
import org.springframework.beans.BeansException;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.ApplicationContextAware;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class SpringApplicationUtil implements ApplicationContextAware {
|
||||
|
||||
private static ApplicationContext applicationContext;
|
||||
|
||||
@Override
|
||||
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
|
||||
SpringApplicationUtil.applicationContext = applicationContext;
|
||||
}
|
||||
|
||||
public ApplicationContext getApplicationContext() {
|
||||
return applicationContext;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取服务Bean
|
||||
* @param name String 服务Bean名称
|
||||
* @return Object
|
||||
*/
|
||||
public static Object getBean(String name) {
|
||||
if (applicationContext == null)
|
||||
throw new RuntimeException("ApplicationContext为空");
|
||||
else
|
||||
return applicationContext.getBean(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取服务接口
|
||||
* @param impClz Class 实现类
|
||||
* @return bean
|
||||
*/
|
||||
public static <T> T getBean(Class<T> impClz){
|
||||
return applicationContext.getBean(impClz);
|
||||
}
|
||||
|
||||
}
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
package com.itheima.sfbx.rule.config;
|
||||
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.ImportResource;
|
||||
import org.springframework.context.annotation.PropertySource;
|
||||
import org.springframework.context.support.PropertySourcesPlaceholderConfigurer;
|
||||
|
||||
/**
|
||||
* URule配置
|
||||
* Created by zhaolong on 2018年4月1日.
|
||||
*/
|
||||
@Configuration
|
||||
@ImportResource({"classpath:urule-console-context.xml"})
|
||||
@PropertySource(value = {"classpath:urule-console-context.properties"})
|
||||
public class URuleConsoleConfiguration {
|
||||
@Bean
|
||||
public PropertySourcesPlaceholderConfigurer propertySourceLoader() {
|
||||
PropertySourcesPlaceholderConfigurer configurer = new PropertySourcesPlaceholderConfigurer();
|
||||
configurer.setIgnoreUnresolvablePlaceholders(true);
|
||||
configurer.setOrder(1);
|
||||
return configurer;
|
||||
}
|
||||
}
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
package com.itheima.sfbx.rule.config;
|
||||
|
||||
import org.springframework.boot.web.servlet.ServletRegistrationBean;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import com.itheima.sfbx.rule.console.servlet.URuleServlet;
|
||||
|
||||
@SuppressWarnings({ "rawtypes", "unchecked" })
|
||||
@Component
|
||||
public class URuleServletRegistration {
|
||||
|
||||
@Bean
|
||||
public ServletRegistrationBean registerURuleServlet(){
|
||||
return new ServletRegistrationBean(new URuleServlet(),"/urule/*");
|
||||
}
|
||||
|
||||
@Bean
|
||||
public ServletRegistrationBean registerIndexServlet(){
|
||||
return new ServletRegistrationBean(new IndexServlet(),"/");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE Repository PUBLIC "-//The Apache Software Foundation//DTD Jackrabbit 1.5//EN" "http://jackrabbit.apache.org/dtd/repository-1.5.dtd">
|
||||
<Repository>
|
||||
<FileSystem class="com.itheima.sfbx.rule.console.repository.database.system.MysqlFileSystem">
|
||||
<param name="schemaObjectPrefix" value="repo_"/>
|
||||
</FileSystem>
|
||||
<Security appName="Jackrabbit">
|
||||
<AccessManager class="org.apache.jackrabbit.core.security.simple.SimpleAccessManager"></AccessManager>
|
||||
<LoginModule class="org.apache.jackrabbit.core.security.simple.SimpleLoginModule">
|
||||
<param name="anonymousId" value="anonymous" />
|
||||
<param name="adminId" value="admin" />
|
||||
</LoginModule>
|
||||
</Security>
|
||||
<DataStore class="com.itheima.sfbx.rule.console.repository.database.DatabaseDataStore">
|
||||
<param name="schemaObjectPrefix" value="repo_ds_"/>
|
||||
</DataStore>
|
||||
<Workspaces rootPath="${rep.home}/workspaces" defaultWorkspace="default" />
|
||||
<Workspace name="default">
|
||||
<FileSystem class="com.itheima.sfbx.rule.console.repository.database.system.MysqlFileSystem">
|
||||
<param name="schemaObjectPrefix" value="repo_${wsp.name}_"/>
|
||||
</FileSystem>
|
||||
<PersistenceManager class="com.itheima.sfbx.rule.console.repository.database.manager.MySqlPersistenceManager">
|
||||
<param name="schemaObjectPrefix" value="repo_pm_${wsp.name}_"/>
|
||||
</PersistenceManager>
|
||||
</Workspace>
|
||||
<Versioning rootPath="${rep.home}/version">
|
||||
<FileSystem class="com.itheima.sfbx.rule.console.repository.database.system.MysqlFileSystem">
|
||||
<param name="schemaObjectPrefix" value="repo_fsver_"/>
|
||||
</FileSystem>
|
||||
<PersistenceManager class="com.itheima.sfbx.rule.console.repository.database.manager.MySqlPersistenceManager">
|
||||
<param name="schemaObjectPrefix" value="repo_ver_"/>
|
||||
</PersistenceManager>
|
||||
</Versioning>
|
||||
|
||||
<Cluster syncDelay="5000">
|
||||
<Journal class="com.itheima.sfbx.rule.console.repository.database.journal.DatabaseJournal">
|
||||
<param name="schemaObjectPrefix" value="journal_"/>
|
||||
</Journal>
|
||||
</Cluster>
|
||||
</Repository>
|
||||
+55
@@ -0,0 +1,55 @@
|
||||
/*******************************************************************************
|
||||
* Copyright 2017 Bstek
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
||||
* use this file except in compliance with the License. You may obtain a copy
|
||||
* of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations under
|
||||
* the License.
|
||||
******************************************************************************/
|
||||
package com.itheima.sfbx.rule.console;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import com.itheima.sfbx.rule.console.servlet.RequestContext;
|
||||
|
||||
/**
|
||||
* @author Jacky.gao
|
||||
* @since 2016年5月25日
|
||||
*/
|
||||
public class DefaultEnvironmentProvider implements EnvironmentProvider {
|
||||
|
||||
@Override
|
||||
public User getLoginUser(RequestContext context) {
|
||||
DefaultUser user=new DefaultUser();
|
||||
user.setCompanyId("bstek");
|
||||
user.setUsername("admin");
|
||||
user.setAdmin(true);
|
||||
return user;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<User> getUsers() {
|
||||
DefaultUser user1=new DefaultUser();
|
||||
user1.setCompanyId("bstek");
|
||||
user1.setUsername("user1");
|
||||
DefaultUser user2=new DefaultUser();
|
||||
user2.setCompanyId("bstek");
|
||||
user2.setUsername("user2");
|
||||
DefaultUser user3=new DefaultUser();
|
||||
user3.setCompanyId("bstek");
|
||||
user3.setUsername("user3");
|
||||
List<User> users=new ArrayList<User>();
|
||||
users.add(user1);
|
||||
users.add(user2);
|
||||
users.add(user3);
|
||||
return users;
|
||||
}
|
||||
}
|
||||
+77
@@ -0,0 +1,77 @@
|
||||
/*******************************************************************************
|
||||
* Copyright 2017 Bstek
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
||||
* use this file except in compliance with the License. You may obtain a copy
|
||||
* of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations under
|
||||
* the License.
|
||||
******************************************************************************/
|
||||
package com.itheima.sfbx.rule.console;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
import com.itheima.sfbx.framework.rule.RuleException;
|
||||
import com.itheima.sfbx.framework.rule.builder.KnowledgeBase;
|
||||
import com.itheima.sfbx.framework.rule.builder.KnowledgeBuilder;
|
||||
import com.itheima.sfbx.framework.rule.builder.ResourceBase;
|
||||
import com.itheima.sfbx.rule.console.repository.RepositoryService;
|
||||
import com.itheima.sfbx.rule.console.repository.model.ResourceItem;
|
||||
import com.itheima.sfbx.rule.console.repository.model.ResourcePackage;
|
||||
import com.itheima.sfbx.framework.rule.runtime.KnowledgePackage;
|
||||
import com.itheima.sfbx.framework.rule.runtime.service.KnowledgePackageService;
|
||||
|
||||
/**
|
||||
* @author Jacky.gao
|
||||
* @since 2016年6月22日
|
||||
*/
|
||||
public class DefaultKnowledgePackageService implements KnowledgePackageService{
|
||||
private KnowledgeBuilder knowledgeBuilder;
|
||||
private RepositoryService repositoryService;
|
||||
|
||||
@Override
|
||||
public KnowledgePackage buildKnowledgePackage(String packageInfo) throws IOException{
|
||||
try{
|
||||
String[] info=packageInfo.split("/");
|
||||
if(info.length!=2){
|
||||
throw new RuleException("PackageInfo ["+packageInfo+"] is invalid. Correct such as \"projectName/packageId\".");
|
||||
}
|
||||
String project=info[0];
|
||||
String packageId=info[1];
|
||||
List<ResourcePackage> packages=repositoryService.loadProjectResourcePackages(project);
|
||||
List<ResourceItem> list=null;
|
||||
for(ResourcePackage p:packages){
|
||||
if(p.getId().equals(packageId)){
|
||||
list=p.getResourceItems();
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(list==null){
|
||||
throw new RuleException("PackageId ["+packageId+"] was not found in project ["+project+"].");
|
||||
}
|
||||
ResourceBase resourceBase=knowledgeBuilder.newResourceBase();
|
||||
for(ResourceItem item:list){
|
||||
resourceBase.addResource(item.getPath(),item.getVersion());
|
||||
}
|
||||
KnowledgeBase knowledgeBase=knowledgeBuilder.buildKnowledgeBase(resourceBase);
|
||||
KnowledgePackage knowledgePackage=knowledgeBase.getKnowledgePackage();
|
||||
return knowledgePackage;
|
||||
}catch(Exception ex){
|
||||
throw new RuleException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
public void setKnowledgeBuilder(KnowledgeBuilder knowledgeBuilder) {
|
||||
this.knowledgeBuilder = knowledgeBuilder;
|
||||
}
|
||||
public void setRepositoryService(RepositoryService repositoryService) {
|
||||
this.repositoryService = repositoryService;
|
||||
}
|
||||
}
|
||||
+65
@@ -0,0 +1,65 @@
|
||||
/*******************************************************************************
|
||||
* Copyright 2017 Bstek
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
||||
* use this file except in compliance with the License. You may obtain a copy
|
||||
* of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations under
|
||||
* the License.
|
||||
******************************************************************************/
|
||||
package com.itheima.sfbx.rule.console;
|
||||
|
||||
|
||||
/**
|
||||
* @author Jacky.gao
|
||||
* @since 2016年8月30日
|
||||
*/
|
||||
public class DefaultRepositoryInteceptor implements RepositoryInteceptor {
|
||||
|
||||
@Override
|
||||
public void readFile(String file) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void saveFile(String file, String content) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void createFile(String file,String content) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteFile(String file) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void renameFile(String oldFileName, String newFileName) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void createDir(String dir) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void createProject(String project) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
/*******************************************************************************
|
||||
* Copyright 2017 Bstek
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
||||
* use this file except in compliance with the License. You may obtain a copy
|
||||
* of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations under
|
||||
* the License.
|
||||
******************************************************************************/
|
||||
package com.itheima.sfbx.rule.console;
|
||||
/**
|
||||
* @author Jacky.gao
|
||||
* @since 2016年5月25日
|
||||
*/
|
||||
public class DefaultUser implements User{
|
||||
private String username;
|
||||
private String companyId;
|
||||
private boolean isAdmin;
|
||||
public String getUsername() {
|
||||
return username;
|
||||
}
|
||||
public void setUsername(String username) {
|
||||
this.username = username;
|
||||
}
|
||||
public String getCompanyId() {
|
||||
return companyId;
|
||||
}
|
||||
public void setCompanyId(String companyId) {
|
||||
this.companyId = companyId;
|
||||
}
|
||||
public boolean isAdmin() {
|
||||
return isAdmin;
|
||||
}
|
||||
public void setAdmin(boolean isAdmin) {
|
||||
this.isAdmin = isAdmin;
|
||||
}
|
||||
}
|
||||
+37
@@ -0,0 +1,37 @@
|
||||
/*******************************************************************************
|
||||
* Copyright 2017 Bstek
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
||||
* use this file except in compliance with the License. You may obtain a copy
|
||||
* of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations under
|
||||
* the License.
|
||||
******************************************************************************/
|
||||
package com.itheima.sfbx.rule.console;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.itheima.sfbx.rule.console.servlet.RequestContext;
|
||||
|
||||
/**
|
||||
* @author Jacky.gao
|
||||
* @since 2015年3月27日
|
||||
*/
|
||||
public interface EnvironmentProvider {
|
||||
/**
|
||||
* @param context 请求上下文对象
|
||||
* @return 返回当前登录用户
|
||||
*/
|
||||
User getLoginUser(RequestContext context);
|
||||
|
||||
/**
|
||||
* @return 返回当前系统当中用户集合 ,供配置资源库权限使用
|
||||
*/
|
||||
List<User> getUsers();
|
||||
}
|
||||
+53
@@ -0,0 +1,53 @@
|
||||
/*******************************************************************************
|
||||
* Copyright 2017 Bstek
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
||||
* use this file except in compliance with the License. You may obtain a copy
|
||||
* of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations under
|
||||
* the License.
|
||||
******************************************************************************/
|
||||
package com.itheima.sfbx.rule.console;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import org.springframework.context.ApplicationContext;
|
||||
|
||||
import com.itheima.sfbx.framework.rule.Utils;
|
||||
import com.itheima.sfbx.rule.console.servlet.RequestContext;
|
||||
|
||||
|
||||
/**
|
||||
* @author Jacky.gao
|
||||
* @since 2015年1月6日
|
||||
*/
|
||||
public class EnvironmentUtils{
|
||||
private static EnvironmentProvider environmentProvider;
|
||||
public static User getLoginUser(RequestContext context){
|
||||
if(environmentProvider==null){
|
||||
initEnvironmentProvider();
|
||||
}
|
||||
return environmentProvider.getLoginUser(context);
|
||||
}
|
||||
public static void initEnvironmentProvider(){
|
||||
ApplicationContext context=Utils.getApplicationContext();
|
||||
Collection<EnvironmentProvider> providers=context.getBeansOfType(EnvironmentProvider.class).values();
|
||||
if(providers.size()==0){
|
||||
environmentProvider=new DefaultEnvironmentProvider();
|
||||
}else{
|
||||
environmentProvider = providers.iterator().next();
|
||||
}
|
||||
}
|
||||
public static EnvironmentProvider getEnvironmentProvider(){
|
||||
if(environmentProvider==null){
|
||||
initEnvironmentProvider();
|
||||
}
|
||||
return environmentProvider;
|
||||
}
|
||||
}
|
||||
+31
@@ -0,0 +1,31 @@
|
||||
/*******************************************************************************
|
||||
* Copyright 2017 Bstek
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
||||
* use this file except in compliance with the License. You may obtain a copy
|
||||
* of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations under
|
||||
* the License.
|
||||
******************************************************************************/
|
||||
package com.itheima.sfbx.rule.console;
|
||||
|
||||
|
||||
/**
|
||||
* @author Jacky.gao
|
||||
* @since 2016年8月30日
|
||||
*/
|
||||
public interface RepositoryInteceptor {
|
||||
void readFile(String file);
|
||||
void saveFile(String file, String content);
|
||||
void createFile(String file, String content);
|
||||
void deleteFile(String file);
|
||||
void renameFile(String oldFileName, String newFileName);
|
||||
void createDir(String dir);
|
||||
void createProject(String project);
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
/*******************************************************************************
|
||||
* Copyright 2017 Bstek
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
||||
* use this file except in compliance with the License. You may obtain a copy
|
||||
* of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations under
|
||||
* the License.
|
||||
******************************************************************************/
|
||||
package com.itheima.sfbx.rule.console;
|
||||
/**
|
||||
* @author Jacky.gao
|
||||
* @since 2015年5月7日
|
||||
*/
|
||||
public interface User {
|
||||
/**
|
||||
* @return 用户名
|
||||
*/
|
||||
String getUsername();
|
||||
/**
|
||||
* @return 所在公司ID
|
||||
*/
|
||||
String getCompanyId();
|
||||
/**
|
||||
* @return 是否为管理员
|
||||
*/
|
||||
boolean isAdmin();
|
||||
}
|
||||
+27
@@ -0,0 +1,27 @@
|
||||
/*******************************************************************************
|
||||
* Copyright 2017 Bstek
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
||||
* use this file except in compliance with the License. You may obtain a copy
|
||||
* of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations under
|
||||
* the License.
|
||||
******************************************************************************/
|
||||
package com.itheima.sfbx.rule.console.exception;
|
||||
|
||||
/**
|
||||
* @author Jacky.gao
|
||||
* @since 2016年9月1日
|
||||
*/
|
||||
public class NoPermissionException extends RuntimeException {
|
||||
private static final long serialVersionUID = 441877650698078466L;
|
||||
public NoPermissionException() {
|
||||
super("Permission denied!");
|
||||
}
|
||||
}
|
||||
+265
@@ -0,0 +1,265 @@
|
||||
/*******************************************************************************
|
||||
* Copyright 2017 Bstek
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
||||
* use this file except in compliance with the License. You may obtain a copy
|
||||
* of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations under
|
||||
* the License.
|
||||
******************************************************************************/
|
||||
package com.itheima.sfbx.rule.console.repository;
|
||||
|
||||
import com.itheima.sfbx.framework.rule.RuleException;
|
||||
import com.itheima.sfbx.framework.rule.Utils;
|
||||
import com.itheima.sfbx.rule.console.DefaultRepositoryInteceptor;
|
||||
import com.itheima.sfbx.rule.console.RepositoryInteceptor;
|
||||
import com.itheima.sfbx.rule.console.repository.model.*;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.apache.jackrabbit.core.RepositoryImpl;
|
||||
import org.dom4j.Document;
|
||||
import org.dom4j.DocumentHelper;
|
||||
import org.dom4j.Element;
|
||||
import org.springframework.beans.BeansException;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.ApplicationContextAware;
|
||||
|
||||
import javax.jcr.*;
|
||||
import javax.jcr.lock.LockManager;
|
||||
import javax.jcr.version.Version;
|
||||
import javax.jcr.version.VersionHistory;
|
||||
import javax.jcr.version.VersionIterator;
|
||||
import javax.jcr.version.VersionManager;
|
||||
import java.io.InputStream;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Jacky.gao
|
||||
* @since 2017年12月15日
|
||||
*/
|
||||
public abstract class BaseRepositoryService implements RepositoryReader,ApplicationContextAware {
|
||||
public static final String RES_PACKGE_FILE="___res__package__file__";
|
||||
public static final String CLIENT_CONFIG_FILE="___client_config__file__";
|
||||
public static final String RESOURCE_SECURITY_CONFIG_FILE="___resource_security_config__file__";
|
||||
protected final String DATA = "_data";
|
||||
protected final String DIR_TAG = "_dir";
|
||||
protected final String FILE = "_file";
|
||||
protected final String CRATE_USER = "_create_user";
|
||||
protected final String CRATE_DATE = "_create_date";
|
||||
protected final String VERSION_COMMENT="_version_comment";
|
||||
protected final String COMPANY_ID="_company_id";
|
||||
|
||||
protected RepositoryBuilder repositoryBuilder;
|
||||
protected RepositoryImpl repository;
|
||||
protected Session session;
|
||||
protected VersionManager versionManager;
|
||||
protected LockManager lockManager;
|
||||
|
||||
protected RepositoryInteceptor repositoryInteceptor;
|
||||
|
||||
@Override
|
||||
public List<RepositoryFile> loadProjects(String companyId) throws Exception{
|
||||
List<RepositoryFile> projects=new ArrayList<RepositoryFile>();
|
||||
Node rootNode=getRootNode();
|
||||
NodeIterator nodeIterator = rootNode.getNodes();
|
||||
while (nodeIterator.hasNext()) {
|
||||
Node projectNode = nodeIterator.nextNode();
|
||||
if (!projectNode.hasProperty(FILE)) {
|
||||
continue;
|
||||
}
|
||||
if(StringUtils.isNotEmpty(companyId)){
|
||||
if(projectNode.hasProperty(COMPANY_ID)){
|
||||
String id=projectNode.getProperty(COMPANY_ID).getString();
|
||||
if(!companyId.equals(id)){
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
if(projectNode.getName().indexOf(RESOURCE_SECURITY_CONFIG_FILE)>-1){
|
||||
continue;
|
||||
}
|
||||
RepositoryFile projectFile = new RepositoryFile();
|
||||
projectFile.setType(Type.project);
|
||||
projectFile.setName(projectNode.getName());
|
||||
projectFile.setFullPath("/" + projectNode.getName());
|
||||
projects.add(projectFile);
|
||||
}
|
||||
return projects;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<VersionFile> getVersionFiles(String path) throws Exception{
|
||||
path = processPath(path);
|
||||
Node rootNode=getRootNode();
|
||||
if (!rootNode.hasNode(path)) {
|
||||
throw new RuleException("File [" + path + "] not exist.");
|
||||
}
|
||||
List<VersionFile> files = new ArrayList<VersionFile>();
|
||||
Node fileNode = rootNode.getNode(path);
|
||||
VersionHistory versionHistory = versionManager.getVersionHistory(fileNode.getPath());
|
||||
VersionIterator iterator = versionHistory.getAllVersions();
|
||||
while (iterator.hasNext()) {
|
||||
Version version = iterator.nextVersion();
|
||||
String versionName = version.getName();
|
||||
if (versionName.startsWith("jcr:")) {
|
||||
continue; // skip root version
|
||||
}
|
||||
Node fnode = version.getFrozenNode();
|
||||
VersionFile file = new VersionFile();
|
||||
file.setName(version.getName());
|
||||
file.setPath(fileNode.getPath());
|
||||
Property prop = fnode.getProperty(CRATE_USER);
|
||||
file.setCreateUser(prop.getString());
|
||||
prop = fnode.getProperty(CRATE_DATE);
|
||||
file.setCreateDate(prop.getDate().getTime());
|
||||
if(fnode.hasProperty(VERSION_COMMENT)){
|
||||
prop=fnode.getProperty(VERSION_COMMENT);
|
||||
file.setComment(prop.getString());
|
||||
}
|
||||
files.add(file);
|
||||
}
|
||||
return files;
|
||||
}
|
||||
|
||||
@Override
|
||||
public InputStream readFile(String path) throws Exception{
|
||||
return readFile(path, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public InputStream readFile(String path,String version) throws Exception{
|
||||
if(StringUtils.isNotBlank(version)){
|
||||
repositoryInteceptor.readFile(path+":"+version);
|
||||
return readVersionFile(path, version);
|
||||
}
|
||||
repositoryInteceptor.readFile(path);
|
||||
Node rootNode=getRootNode();
|
||||
int colonPos = path.lastIndexOf(":");
|
||||
if (colonPos > -1) {
|
||||
version = path.substring(colonPos + 1, path.length());
|
||||
path = path.substring(0, colonPos);
|
||||
return readFile(path, version);
|
||||
}
|
||||
path = processPath(path);
|
||||
if (!rootNode.hasNode(path)) {
|
||||
throw new RuleException("File [" + path + "] not exist.");
|
||||
}
|
||||
Node fileNode = rootNode.getNode(path);
|
||||
Property property = fileNode.getProperty(DATA);
|
||||
Binary fileBinary = property.getBinary();
|
||||
return fileBinary.getStream();
|
||||
}
|
||||
|
||||
|
||||
private InputStream readVersionFile(String path, String version) throws Exception{
|
||||
path = processPath(path);
|
||||
Node rootNode=getRootNode();
|
||||
if (!rootNode.hasNode(path)) {
|
||||
throw new RuleException("File [" + path + "] not exist.");
|
||||
}
|
||||
Node fileNode = rootNode.getNode(path);
|
||||
VersionHistory versionHistory = versionManager.getVersionHistory(fileNode.getPath());
|
||||
Version v = versionHistory.getVersion(version);
|
||||
Node fnode = v.getFrozenNode();
|
||||
Property property = fnode.getProperty(DATA);
|
||||
Binary fileBinary = property.getBinary();
|
||||
return fileBinary.getStream();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ResourcePackage> loadProjectResourcePackages(String project) throws Exception {
|
||||
Node rootNode=getRootNode();
|
||||
String filePath = processPath(project) + "/" + RES_PACKGE_FILE;
|
||||
SimpleDateFormat sd = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
Node fileNode = rootNode.getNode(filePath);
|
||||
Property property = fileNode.getProperty(DATA);
|
||||
Binary fileBinary = property.getBinary();
|
||||
InputStream inputStream = fileBinary.getStream();
|
||||
String content = IOUtils.toString(inputStream, "utf-8");
|
||||
content = Utils.decodeURL(content);
|
||||
inputStream.close();
|
||||
Document document = DocumentHelper.parseText(content);
|
||||
Element rootElement = document.getRootElement();
|
||||
List<ResourcePackage> packages = new ArrayList<ResourcePackage>();
|
||||
for (Object obj : rootElement.elements()) {
|
||||
if (!(obj instanceof Element)) {
|
||||
continue;
|
||||
}
|
||||
Element element = (Element) obj;
|
||||
if (!element.getName().equals("res-package")) {
|
||||
continue;
|
||||
}
|
||||
ResourcePackage p = new ResourcePackage();
|
||||
String dateStr = element.attributeValue("create_date");
|
||||
if (dateStr != null) {
|
||||
p.setCreateDate(sd.parse(dateStr));
|
||||
}
|
||||
p.setId(element.attributeValue("id"));
|
||||
p.setName(element.attributeValue("name"));
|
||||
p.setProject(project);
|
||||
List<ResourceItem> items = new ArrayList<ResourceItem>();
|
||||
for (Object o : element.elements()) {
|
||||
if (!(o instanceof Element)) {
|
||||
continue;
|
||||
}
|
||||
Element ele = (Element) o;
|
||||
if (!ele.getName().equals("res-package-item")) {
|
||||
continue;
|
||||
}
|
||||
ResourceItem item = new ResourceItem();
|
||||
item.setName(ele.attributeValue("name"));
|
||||
item.setPackageId(p.getId());
|
||||
item.setPath(ele.attributeValue("path"));
|
||||
item.setVersion(ele.attributeValue("version"));
|
||||
items.add(item);
|
||||
}
|
||||
p.setResourceItems(items);
|
||||
packages.add(p);
|
||||
}
|
||||
return packages;
|
||||
}
|
||||
|
||||
protected String processPath(String path) {
|
||||
if (path.startsWith("/")) {
|
||||
return path.substring(1, path.length());
|
||||
}
|
||||
return path;
|
||||
}
|
||||
|
||||
protected Node getRootNode() throws Exception{
|
||||
return session.getRootNode();
|
||||
}
|
||||
|
||||
public void setRepositoryBuilder(RepositoryBuilder repositoryBuilder) {
|
||||
this.repositoryBuilder = repositoryBuilder;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
|
||||
try {
|
||||
repository = repositoryBuilder.getRepository();
|
||||
SimpleCredentials cred = new SimpleCredentials("admin", "admin".toCharArray());
|
||||
cred.setAttribute("AutoRefresh", true);
|
||||
session = repository.login(cred, null);
|
||||
versionManager = session.getWorkspace().getVersionManager();
|
||||
lockManager=session.getWorkspace().getLockManager();
|
||||
Collection<RepositoryInteceptor> repositoryInteceptors=applicationContext.getBeansOfType(RepositoryInteceptor.class).values();
|
||||
if(repositoryInteceptors.size()==0){
|
||||
repositoryInteceptor=new DefaultRepositoryInteceptor();
|
||||
}else{
|
||||
repositoryInteceptor=repositoryInteceptors.iterator().next();
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
throw new RuleException(ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
+43
@@ -0,0 +1,43 @@
|
||||
/*******************************************************************************
|
||||
* Copyright 2017 Bstek
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
||||
* use this file except in compliance with the License. You may obtain a copy
|
||||
* of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations under
|
||||
* the License.
|
||||
******************************************************************************/
|
||||
package com.itheima.sfbx.rule.console.repository;
|
||||
/**
|
||||
* @author Jacky.gao
|
||||
* @since 2016年8月11日
|
||||
*/
|
||||
public class ClientConfig {
|
||||
private String name;
|
||||
private String client;
|
||||
private String project;
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
public String getClient() {
|
||||
return client;
|
||||
}
|
||||
public void setClient(String client) {
|
||||
this.client = client;
|
||||
}
|
||||
public String getProject() {
|
||||
return project;
|
||||
}
|
||||
public void setProject(String project) {
|
||||
this.project = project;
|
||||
}
|
||||
}
|
||||
+29
@@ -0,0 +1,29 @@
|
||||
/*******************************************************************************
|
||||
* Copyright 2017 Bstek
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
||||
* use this file except in compliance with the License. You may obtain a copy
|
||||
* of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations under
|
||||
* the License.
|
||||
******************************************************************************/
|
||||
package com.itheima.sfbx.rule.console.repository;
|
||||
|
||||
import com.itheima.sfbx.framework.rule.RuleException;
|
||||
|
||||
/**
|
||||
* @author Jacky.gao
|
||||
* @since 2017年11月22日
|
||||
*/
|
||||
public class NodeLockException extends RuleException {
|
||||
private static final long serialVersionUID = 5117384355737392800L;
|
||||
public NodeLockException(String msg) {
|
||||
super(msg);
|
||||
}
|
||||
}
|
||||
+37
@@ -0,0 +1,37 @@
|
||||
/*******************************************************************************
|
||||
* Copyright 2017 Bstek
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
||||
* use this file except in compliance with the License. You may obtain a copy
|
||||
* of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations under
|
||||
* the License.
|
||||
******************************************************************************/
|
||||
package com.itheima.sfbx.rule.console.repository;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.itheima.sfbx.rule.console.repository.model.RepositoryFile;
|
||||
|
||||
public class Repository {
|
||||
private RepositoryFile rootFile;
|
||||
private List<String> projectNames;
|
||||
public RepositoryFile getRootFile() {
|
||||
return rootFile;
|
||||
}
|
||||
public void setRootFile(RepositoryFile rootFile) {
|
||||
this.rootFile = rootFile;
|
||||
}
|
||||
public List<String> getProjectNames() {
|
||||
return projectNames;
|
||||
}
|
||||
public void setProjectNames(List<String> projectNames) {
|
||||
this.projectNames = projectNames;
|
||||
}
|
||||
}
|
||||
+327
@@ -0,0 +1,327 @@
|
||||
/*******************************************************************************
|
||||
* Copyright 2017 Bstek
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
||||
* use this file except in compliance with the License. You may obtain a copy
|
||||
* of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations under
|
||||
* the License.
|
||||
******************************************************************************/
|
||||
package com.itheima.sfbx.rule.console.repository;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.InputStream;
|
||||
import java.util.Properties;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import javax.jcr.RepositoryException;
|
||||
import javax.servlet.ServletContext;
|
||||
import javax.sql.DataSource;
|
||||
import javax.xml.parsers.DocumentBuilder;
|
||||
import javax.xml.parsers.DocumentBuilderFactory;
|
||||
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.apache.jackrabbit.core.RepositoryImpl;
|
||||
import org.apache.jackrabbit.core.config.AccessManagerConfig;
|
||||
import org.apache.jackrabbit.core.config.BeanConfig;
|
||||
import org.apache.jackrabbit.core.config.ClusterConfig;
|
||||
import org.apache.jackrabbit.core.config.DataSourceConfig;
|
||||
import org.apache.jackrabbit.core.config.LoginModuleConfig;
|
||||
import org.apache.jackrabbit.core.config.PersistenceManagerConfig;
|
||||
import org.apache.jackrabbit.core.config.RepositoryConfig;
|
||||
import org.apache.jackrabbit.core.config.RepositoryConfigurationParser;
|
||||
import org.apache.jackrabbit.core.config.SecurityConfig;
|
||||
import org.apache.jackrabbit.core.config.SecurityManagerConfig;
|
||||
import org.apache.jackrabbit.core.config.VersioningConfig;
|
||||
import org.apache.jackrabbit.core.data.DataStore;
|
||||
import org.apache.jackrabbit.core.data.DataStoreFactory;
|
||||
import org.apache.jackrabbit.core.data.FileDataStore;
|
||||
import org.apache.jackrabbit.core.fs.FileSystem;
|
||||
import org.apache.jackrabbit.core.fs.FileSystemException;
|
||||
import org.apache.jackrabbit.core.fs.FileSystemFactory;
|
||||
import org.apache.jackrabbit.core.fs.local.LocalFileSystem;
|
||||
import org.apache.jackrabbit.core.query.QueryHandlerFactory;
|
||||
import org.apache.jackrabbit.core.state.DefaultISMLocking;
|
||||
import org.apache.jackrabbit.core.state.ISMLocking;
|
||||
import org.apache.jackrabbit.core.state.ISMLockingFactory;
|
||||
import org.apache.jackrabbit.core.util.CooperativeFileLock;
|
||||
import org.apache.jackrabbit.core.util.RepositoryLockMechanism;
|
||||
import org.apache.jackrabbit.core.util.RepositoryLockMechanismFactory;
|
||||
import org.apache.jackrabbit.core.util.db.ConnectionFactory;
|
||||
import org.springframework.beans.BeansException;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.ApplicationContextAware;
|
||||
import org.springframework.web.context.WebApplicationContext;
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.Element;
|
||||
|
||||
import com.itheima.sfbx.framework.rule.RuleException;
|
||||
|
||||
/**
|
||||
* @author Jacky.gao
|
||||
* @since 2016年5月24日
|
||||
*/
|
||||
public class RepositoryBuilder implements InitializingBean,ApplicationContextAware{
|
||||
private String repoHomeDir;
|
||||
private Element workspaceTemplate;
|
||||
private RepositoryImpl repository;
|
||||
private String repositoryXml;
|
||||
private ApplicationContext applicationContext;
|
||||
private String repositoryDatasourceName;
|
||||
public static String databaseType;
|
||||
public static DataSource datasource;
|
||||
private Logger log=Logger.getLogger(RepositoryBuilder.class.getName());
|
||||
public RepositoryImpl getRepository() {
|
||||
return repository;
|
||||
}
|
||||
|
||||
private SecurityConfig buildSecurityConfig(){
|
||||
SecurityConfig securityConfig=new SecurityConfig("uruleRepoSecurity",buildSecurityManagerConfig(),buildAccessManagerConfig(),buildLoginModuleConfig());
|
||||
return securityConfig;
|
||||
}
|
||||
|
||||
private RepositoryLockMechanismFactory buildRepositoryLockMechanismFactory(){
|
||||
return new RepositoryLockMechanismFactory(){
|
||||
public RepositoryLockMechanism getRepositoryLockMechanism() throws RepositoryException {
|
||||
return new CooperativeFileLock();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private FileSystemFactory buildFileSystemFactory(final String dirName){
|
||||
return new FileSystemFactory() {
|
||||
public FileSystem getFileSystem() throws RepositoryException {
|
||||
try {
|
||||
LocalFileSystem fs = new LocalFileSystem();
|
||||
fs.setPath(""+repoHomeDir+"/"+dirName);
|
||||
fs.init();
|
||||
return fs;
|
||||
} catch (FileSystemException e) {
|
||||
throw new RepositoryException("File system initialization failure.", e);
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private DataStoreFactory buildDataStoreFactory(){
|
||||
return new DataStoreFactory(){
|
||||
public DataStore getDataStore() throws RepositoryException {
|
||||
FileDataStore datastore=new FileDataStore();
|
||||
datastore.setPath(""+repoHomeDir+"/repository/datastore");
|
||||
datastore.setMinRecordLength(100);
|
||||
return null;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private VersioningConfig buildVersioningConfig(){
|
||||
String homeDir=""+repoHomeDir+"/version";
|
||||
FileSystemFactory fileSystemFactory=buildFileSystemFactory("version");
|
||||
PersistenceManagerConfig persistenceManagerConfig=buildPersistenceManagerConfig();
|
||||
ISMLockingFactory ismLockingFactory=buildISMLockingFactory();
|
||||
VersioningConfig versioningConfig=new VersioningConfig(homeDir,fileSystemFactory,persistenceManagerConfig,ismLockingFactory);
|
||||
return versioningConfig;
|
||||
}
|
||||
|
||||
private ISMLockingFactory buildISMLockingFactory(){
|
||||
return new ISMLockingFactory(){
|
||||
public ISMLocking getISMLocking() throws RepositoryException {
|
||||
return new DefaultISMLocking();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private PersistenceManagerConfig buildPersistenceManagerConfig(){
|
||||
Properties prop=new Properties();
|
||||
BeanConfig beanConfig=new BeanConfig("org.apache.jackrabbit.core.persistence.bundle.BundleFsPersistenceManager",prop);
|
||||
PersistenceManagerConfig persistenceManagerConfig=new PersistenceManagerConfig(beanConfig);
|
||||
return persistenceManagerConfig;
|
||||
}
|
||||
|
||||
private SecurityManagerConfig buildSecurityManagerConfig(){
|
||||
Properties prop=new Properties();
|
||||
BeanConfig beanConfig=new BeanConfig("org.apache.jackrabbit.core.security.simple.SimpleSecurityManager",prop);
|
||||
SecurityManagerConfig securityManagerConfig=new SecurityManagerConfig(beanConfig,"default",null);
|
||||
return securityManagerConfig;
|
||||
}
|
||||
|
||||
private AccessManagerConfig buildAccessManagerConfig(){
|
||||
Properties prop=new Properties();
|
||||
BeanConfig beanConfig=new BeanConfig("org.apache.jackrabbit.core.security.simple.SimpleAccessManager",prop);
|
||||
AccessManagerConfig accessManagerConfig=new AccessManagerConfig(beanConfig);
|
||||
return accessManagerConfig;
|
||||
}
|
||||
|
||||
private LoginModuleConfig buildLoginModuleConfig(){
|
||||
Properties prop=new Properties();
|
||||
prop.put("anonymousId", "anonymous");
|
||||
prop.put("adminId", "admin");
|
||||
BeanConfig beanConfig=new BeanConfig("org.apache.jackrabbit.core.security.simple.SimpleLoginModule",prop);
|
||||
LoginModuleConfig loginModuleConfig=new LoginModuleConfig(beanConfig);
|
||||
return loginModuleConfig;
|
||||
}
|
||||
|
||||
private void initRepositoryByXml(String xml)throws Exception {
|
||||
log.info("Build repository from user custom xml file...");
|
||||
InputStream inputStream=null;
|
||||
try{
|
||||
inputStream=this.applicationContext.getResource(xml).getInputStream();
|
||||
String tempRepoHomeDir=System.getProperty("java.io.tmpdir");
|
||||
// String tempRepoHomeDir = "D:/repo2/";
|
||||
if(StringUtils.isNotBlank(tempRepoHomeDir) && tempRepoHomeDir.length()>1){
|
||||
if(tempRepoHomeDir.endsWith("/") || tempRepoHomeDir.endsWith("\\")){
|
||||
tempRepoHomeDir+="urule-temp-repo-home/";
|
||||
}else{
|
||||
tempRepoHomeDir+="/urule-temp-repo-home/";
|
||||
}
|
||||
File tempDir=new File(tempRepoHomeDir);
|
||||
clearTempDir(tempDir);
|
||||
}else{
|
||||
tempRepoHomeDir="";
|
||||
}
|
||||
RepositoryConfig repositoryConfig = RepositoryConfig.create(inputStream,tempRepoHomeDir);
|
||||
repository=RepositoryImpl.create(repositoryConfig);
|
||||
}finally{
|
||||
if(inputStream!=null){
|
||||
inputStream.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void clearTempDir(File file){
|
||||
if(file.isDirectory()){
|
||||
for(File childFile:file.listFiles()){
|
||||
clearTempDir(childFile);
|
||||
}
|
||||
}
|
||||
file.delete();
|
||||
}
|
||||
|
||||
private void initDefaultRepository()throws Exception {
|
||||
SecurityConfig securityConfig=buildSecurityConfig();
|
||||
FileSystemFactory fileSystemFactory=buildFileSystemFactory("repository");
|
||||
String workspaceDirectory=""+repoHomeDir+"/workspaces";
|
||||
String workspaceConfigDirectory=null;
|
||||
String defaultWorkspace="default";
|
||||
int workspaceMaxIdleTime=0;
|
||||
VersioningConfig versioningConfig=buildVersioningConfig();
|
||||
QueryHandlerFactory queryHandlerFactory=null;
|
||||
ClusterConfig clusterConfig=null;
|
||||
DataStoreFactory dataStoreFactory=buildDataStoreFactory();
|
||||
RepositoryLockMechanismFactory repositoryLockMechanismFactory=buildRepositoryLockMechanismFactory();
|
||||
DataSourceConfig dataSourceConfig=new DataSourceConfig();
|
||||
ConnectionFactory connectionFactory=new ConnectionFactory();
|
||||
RepositoryConfigurationParser repositoryConfigurationParser=new RepositoryConfigurationParser(new Properties());
|
||||
initWorkspaceTemplate();
|
||||
RepositoryConfig repositoryConfig = new RepositoryConfig(repoHomeDir, securityConfig,
|
||||
fileSystemFactory, workspaceDirectory,
|
||||
workspaceConfigDirectory, defaultWorkspace,
|
||||
workspaceMaxIdleTime, workspaceTemplate, versioningConfig,
|
||||
queryHandlerFactory, clusterConfig, dataStoreFactory,
|
||||
repositoryLockMechanismFactory, dataSourceConfig,
|
||||
connectionFactory, repositoryConfigurationParser);
|
||||
repositoryConfig.init();
|
||||
repository=RepositoryImpl.create(repositoryConfig);
|
||||
}
|
||||
|
||||
private void initWorkspaceTemplate(){
|
||||
InputStream inputStream=null;
|
||||
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
|
||||
try {
|
||||
DocumentBuilder builder = factory.newDocumentBuilder();
|
||||
inputStream=applicationContext.getResource("classpath:workspace_template.xml").getInputStream();
|
||||
// inputStream=applicationContext.getResource("classpath:com/itheima/sfbx/framework/rule/console/repository/workspace_template.xml").getInputStream();
|
||||
// inputStream=applicationContext.getResource("classpath:com/itheima/sfbx/rule/config/workspace_template.xml").getInputStream();
|
||||
Document doc = builder.parse(inputStream);
|
||||
workspaceTemplate=doc.getDocumentElement();
|
||||
} catch (Exception e) {
|
||||
throw new RuleException(e);
|
||||
} finally {
|
||||
IOUtils.closeQuietly(inputStream);
|
||||
}
|
||||
}
|
||||
|
||||
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
|
||||
this.applicationContext=applicationContext;
|
||||
}
|
||||
|
||||
private void initRepositoryDir(ApplicationContext applicationContext){
|
||||
if(applicationContext instanceof WebApplicationContext){
|
||||
WebApplicationContext context=(WebApplicationContext)applicationContext;
|
||||
ServletContext servletContext=context.getServletContext();
|
||||
File file=new File(repoHomeDir);
|
||||
if(!file.exists()){
|
||||
repoHomeDir=servletContext.getRealPath(repoHomeDir);
|
||||
}
|
||||
file=new File(repoHomeDir);
|
||||
if(!file.exists()){
|
||||
throw new RuleException("Repository root dir "+repoHomeDir+" is not exist.");
|
||||
}
|
||||
}else{
|
||||
log.info("Current is not a standard web container,so can't resolve real path for repo home dir.");
|
||||
}
|
||||
log.info("Use \""+repoHomeDir+"\" as urule repository home directory.");
|
||||
}
|
||||
public void afterPropertiesSet() throws Exception {
|
||||
if(StringUtils.isNotBlank(repositoryDatasourceName)){
|
||||
RepositoryBuilder.datasource=(DataSource)this.applicationContext.getBean(repositoryDatasourceName);
|
||||
}
|
||||
if(repository!=null){
|
||||
repository.shutdown();
|
||||
}
|
||||
if(StringUtils.isNotBlank(repoHomeDir) && !repoHomeDir.equals("${urule.repository.dir}")){
|
||||
initRepositoryDir(applicationContext);
|
||||
}
|
||||
if(StringUtils.isNotBlank(repositoryXml)){
|
||||
initRepositoryByXml(repositoryXml);
|
||||
}else if(RepositoryBuilder.datasource!=null){
|
||||
if(RepositoryBuilder.databaseType==null){
|
||||
throw new RuleException("You need config \"urule.repository.databasetype\" property when use spring datasource!");
|
||||
}
|
||||
initRepositoryFromSpringDatasource();
|
||||
}else{
|
||||
if(StringUtils.isBlank(repoHomeDir)){
|
||||
throw new RuleException("You need config \"urule.repository.dir\" property for set repository home dir.");
|
||||
}
|
||||
initDefaultRepository();
|
||||
}
|
||||
}
|
||||
|
||||
private void initRepositoryFromSpringDatasource() throws Exception{
|
||||
System.out.println("Init repository from spring datasource ["+repositoryDatasourceName+"] with database type ["+RepositoryBuilder.databaseType+"]...");
|
||||
String xml="classpath:"+RepositoryBuilder.databaseType+".xml";
|
||||
// String xml="classpath:com/itheima/sfbx/rule/console/repository/database/configs/"+RepositoryBuilder.databaseType+".xml";
|
||||
// String xml="classpath:com/itheima/sfbx/rule/config/"+RepositoryBuilder.databaseType+".xml";
|
||||
initRepositoryByXml(xml);
|
||||
}
|
||||
|
||||
public void setRepoHomeDir(String repoHomeDir) {
|
||||
this.repoHomeDir = repoHomeDir;
|
||||
}
|
||||
|
||||
|
||||
public void setRepositoryXml(String repositoryXml) {
|
||||
this.repositoryXml = repositoryXml;
|
||||
}
|
||||
|
||||
public void setDatabaseType(String databaseType) {
|
||||
RepositoryBuilder.databaseType = databaseType;
|
||||
}
|
||||
public void setRepositoryDatasourceName(String repositoryDatasourceName) {
|
||||
this.repositoryDatasourceName = repositoryDatasourceName;
|
||||
}
|
||||
|
||||
public void destroy(){
|
||||
System.out.println("Shutdown repository...");
|
||||
repository.shutdown();
|
||||
System.out.println("Shutdown repository completed...");
|
||||
}
|
||||
}
|
||||
+68
@@ -0,0 +1,68 @@
|
||||
/*******************************************************************************
|
||||
* Copyright 2017 Bstek
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
||||
* use this file except in compliance with the License. You may obtain a copy
|
||||
* of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations under
|
||||
* the License.
|
||||
******************************************************************************/
|
||||
package com.itheima.sfbx.rule.console.repository;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.util.List;
|
||||
|
||||
import com.itheima.sfbx.rule.console.repository.model.RepositoryFile;
|
||||
import com.itheima.sfbx.rule.console.repository.model.ResourcePackage;
|
||||
import com.itheima.sfbx.rule.console.repository.model.VersionFile;
|
||||
|
||||
/**
|
||||
* @author Jacky.gao
|
||||
* @since 2017年12月15日
|
||||
*/
|
||||
public interface RepositoryReader {
|
||||
public static final String BEAN_ID=RepositoryService.BEAN_ID;
|
||||
/**
|
||||
* 加载指定的companyId下创建的所有的项目信息
|
||||
* @param companyId 指定的公司ID
|
||||
* @return 返回所有的项目信息
|
||||
* @throws Exception 抛出异常
|
||||
*/
|
||||
List<RepositoryFile> loadProjects(String companyId) throws Exception;
|
||||
/**
|
||||
* 读取指定的最新版本的文件
|
||||
* @param path 文件考路径
|
||||
* @return 返回文件内容
|
||||
* @throws Exception 抛出异常
|
||||
*/
|
||||
InputStream readFile(String path) throws Exception;
|
||||
/**
|
||||
* 加载指定项目下的知识包信息
|
||||
* @param project 项目名称
|
||||
* @return 返回已定义的知识包信息
|
||||
* @throws Exception 抛出异常
|
||||
*/
|
||||
List<ResourcePackage> loadProjectResourcePackages(String project) throws Exception;
|
||||
/**
|
||||
* 获取指定路径文件的所有版本信息
|
||||
* @param path 文件路径
|
||||
* @return 返回版本信息列表
|
||||
* @throws Exception
|
||||
*/
|
||||
List<VersionFile> getVersionFiles(String path) throws Exception;
|
||||
|
||||
/**
|
||||
* 读取指定版本文件
|
||||
* @param path 文件路径
|
||||
* @param version 文件版本号
|
||||
* @return 返回文件内容
|
||||
* @throws Exception 抛出异常
|
||||
*/
|
||||
InputStream readFile(String path, String version) throws Exception;
|
||||
}
|
||||
+102
@@ -0,0 +1,102 @@
|
||||
/*******************************************************************************
|
||||
* Copyright 2017 Bstek
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
||||
* use this file except in compliance with the License. You may obtain a copy
|
||||
* of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations under
|
||||
* the License.
|
||||
******************************************************************************/
|
||||
package com.itheima.sfbx.rule.console.repository;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import javax.jcr.Node;
|
||||
import javax.jcr.NodeIterator;
|
||||
import javax.jcr.RepositoryException;
|
||||
|
||||
import org.apache.tika.io.IOUtils;
|
||||
|
||||
import com.itheima.sfbx.framework.rule.RuleException;
|
||||
import com.itheima.sfbx.rule.console.repository.model.FileType;
|
||||
|
||||
/**
|
||||
* @author Jacky.gao
|
||||
* @since 2016年5月25日
|
||||
*/
|
||||
public class RepositoryRefactor {
|
||||
private RepositoryService repositoryService;
|
||||
public RepositoryRefactor(RepositoryService repositoryService) {
|
||||
this.repositoryService=repositoryService;
|
||||
}
|
||||
|
||||
public List<String> getReferenceFiles(Node rootNode,String path,String searchText) throws Exception{
|
||||
List<String> referenceFiles=new ArrayList<String>();
|
||||
List<String> files=getFiles(rootNode, path);
|
||||
for(String nodePath:files){
|
||||
InputStream inputStream=repositoryService.readFile(nodePath,null);
|
||||
try {
|
||||
String content = IOUtils.toString(inputStream);
|
||||
inputStream.close();
|
||||
boolean containPath=content.contains(path);
|
||||
boolean containText=content.contains(searchText);
|
||||
if(containPath && containText){
|
||||
referenceFiles.add(nodePath);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new RuleException(e);
|
||||
}
|
||||
}
|
||||
return referenceFiles;
|
||||
}
|
||||
|
||||
public List<String> getFiles(Node rootNode,String path){
|
||||
String project=getProject(path);
|
||||
try{
|
||||
List<String> list=new ArrayList<String>();
|
||||
Node projectNode=rootNode.getNode(project);
|
||||
buildPath(list, projectNode);
|
||||
return list;
|
||||
}catch(Exception ex){
|
||||
throw new RuleException(ex);
|
||||
}
|
||||
}
|
||||
private void buildPath(List<String> list, Node parentNode) throws RepositoryException {
|
||||
NodeIterator nodeIterator=parentNode.getNodes();
|
||||
while(nodeIterator.hasNext()){
|
||||
Node node=nodeIterator.nextNode();
|
||||
String nodePath=node.getPath();
|
||||
if(nodePath.endsWith(FileType.Ruleset.toString())){
|
||||
list.add(nodePath);
|
||||
}else if(nodePath.endsWith(FileType.UL.toString())){
|
||||
list.add(nodePath);
|
||||
}else if(nodePath.endsWith(FileType.DecisionTable.toString())){
|
||||
list.add(nodePath);
|
||||
}else if(nodePath.endsWith(FileType.ScriptDecisionTable.toString())){
|
||||
list.add(nodePath);
|
||||
}else if(nodePath.endsWith(FileType.DecisionTree.toString())){
|
||||
list.add(nodePath);
|
||||
}else if(nodePath.endsWith(FileType.RuleFlow.toString())){
|
||||
list.add(nodePath);
|
||||
}
|
||||
buildPath(list,node);
|
||||
}
|
||||
}
|
||||
|
||||
private String getProject(String path){
|
||||
if(path.startsWith("/")){
|
||||
path=path.substring(1);
|
||||
}
|
||||
int pos=path.indexOf("/");
|
||||
return path.substring(0,pos);
|
||||
}
|
||||
}
|
||||
+59
@@ -0,0 +1,59 @@
|
||||
/*******************************************************************************
|
||||
* Copyright 2017 Bstek
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
||||
* use this file except in compliance with the License. You may obtain a copy
|
||||
* of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations under
|
||||
* the License.
|
||||
******************************************************************************/
|
||||
package com.itheima.sfbx.rule.console.repository;
|
||||
|
||||
import java.io.InputStream;
|
||||
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
|
||||
import com.itheima.sfbx.framework.rule.RuleException;
|
||||
import com.itheima.sfbx.framework.rule.builder.resource.Resource;
|
||||
import com.itheima.sfbx.framework.rule.builder.resource.ResourceProvider;
|
||||
|
||||
/**
|
||||
* @author Jacky.gao
|
||||
* @since 2015年3月25日
|
||||
*/
|
||||
public class RepositoryResourceProvider implements ResourceProvider {
|
||||
public static final String JCR="jcr:";
|
||||
private RepositoryService repositoryService;
|
||||
|
||||
@Override
|
||||
public Resource provide(String path,String version) {
|
||||
String newpath=path.substring(4,path.length());
|
||||
InputStream inputStream=null;
|
||||
try {
|
||||
if(StringUtils.isEmpty(version) || version.equals("LATEST")){
|
||||
inputStream=repositoryService.readFile(newpath,null);
|
||||
}else{
|
||||
inputStream=repositoryService.readFile(newpath,version);
|
||||
}
|
||||
String content=IOUtils.toString(inputStream,"utf-8");
|
||||
IOUtils.closeQuietly(inputStream);
|
||||
return new Resource(content,path);
|
||||
} catch (Exception e) {
|
||||
throw new RuleException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean support(String path) {
|
||||
return path.startsWith(JCR);
|
||||
}
|
||||
public void setRepositoryService(RepositoryService repositoryService) {
|
||||
this.repositoryService = repositoryService;
|
||||
}
|
||||
}
|
||||
+52
@@ -0,0 +1,52 @@
|
||||
/*******************************************************************************
|
||||
* Copyright 2017 Bstek
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
||||
* use this file except in compliance with the License. You may obtain a copy
|
||||
* of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations under
|
||||
* the License.
|
||||
******************************************************************************/
|
||||
package com.itheima.sfbx.rule.console.repository;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.util.List;
|
||||
|
||||
import com.itheima.sfbx.rule.console.User;
|
||||
import com.itheima.sfbx.rule.console.repository.model.FileType;
|
||||
import com.itheima.sfbx.rule.console.repository.model.RepositoryFile;
|
||||
import com.itheima.sfbx.rule.console.repository.model.VersionFile;
|
||||
import com.itheima.sfbx.rule.console.servlet.permission.UserPermission;
|
||||
|
||||
/**
|
||||
* @author Jacky.gao
|
||||
* @since 2015年3月24日
|
||||
*/
|
||||
public interface RepositoryService extends RepositoryReader{
|
||||
public static final String BEAN_ID="urule.repositoryService";
|
||||
boolean fileExistCheck(String filePath) throws Exception;
|
||||
RepositoryFile createProject(String projectName, User user, boolean classify) throws Exception;
|
||||
void createDir(String path, User user) throws Exception;
|
||||
void createFile(String path, String content, User user) throws Exception;
|
||||
void saveFile(String path, String content, boolean newVersion, String versionComment, User user) throws Exception;
|
||||
void deleteFile(String path, User user)throws Exception;
|
||||
void lockPath(String path, User user) throws Exception;
|
||||
void unlockPath(String path, User user) throws Exception;
|
||||
Repository loadRepository(String project, User user, boolean classify, FileType[] types, String searchFileName) throws Exception;
|
||||
void fileRename(String path, String newPath) throws Exception;
|
||||
List<String> getReferenceFiles(String path, String searchText) throws Exception;
|
||||
InputStream readFile(String path, String version) throws Exception;
|
||||
List<VersionFile> getVersionFiles(String path) throws Exception;
|
||||
void exportXml(String projectPath, OutputStream outputStream)throws Exception;
|
||||
void importXml(InputStream inputStream, boolean overwrite)throws Exception;
|
||||
List<RepositoryFile> getDirectories(String project) throws Exception;
|
||||
List<ClientConfig> loadClientConfigs(String project)throws Exception;
|
||||
List<UserPermission> loadResourceSecurityConfigs(String companyId) throws Exception;
|
||||
}
|
||||
+936
@@ -0,0 +1,936 @@
|
||||
/*******************************************************************************
|
||||
* Copyright 2017 Bstek
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
||||
* use this file except in compliance with the License. You may obtain a copy
|
||||
* of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations under
|
||||
* the License.
|
||||
******************************************************************************/
|
||||
package com.itheima.sfbx.rule.console.repository;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import javax.jcr.Binary;
|
||||
import javax.jcr.ImportUUIDBehavior;
|
||||
import javax.jcr.Node;
|
||||
import javax.jcr.NodeIterator;
|
||||
import javax.jcr.Property;
|
||||
import javax.jcr.RepositoryException;
|
||||
import javax.jcr.lock.Lock;
|
||||
import javax.jcr.nodetype.NodeType;
|
||||
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.apache.jackrabbit.value.BinaryImpl;
|
||||
import org.apache.jackrabbit.value.DateValue;
|
||||
import org.dom4j.Document;
|
||||
import org.dom4j.DocumentHelper;
|
||||
import org.dom4j.Element;
|
||||
import org.springframework.context.ApplicationContextAware;
|
||||
|
||||
import com.itheima.sfbx.framework.rule.RuleException;
|
||||
import com.itheima.sfbx.framework.rule.Utils;
|
||||
import com.itheima.sfbx.rule.console.User;
|
||||
import com.itheima.sfbx.rule.console.exception.NoPermissionException;
|
||||
import com.itheima.sfbx.rule.console.repository.model.FileType;
|
||||
import com.itheima.sfbx.rule.console.repository.model.LibType;
|
||||
import com.itheima.sfbx.rule.console.repository.model.RepositoryFile;
|
||||
import com.itheima.sfbx.rule.console.repository.model.Type;
|
||||
import com.itheima.sfbx.rule.console.repository.permission.PermissionService;
|
||||
import com.itheima.sfbx.rule.console.servlet.permission.ProjectConfig;
|
||||
import com.itheima.sfbx.rule.console.servlet.permission.UserPermission;
|
||||
|
||||
/**
|
||||
* @author Jacky.gao
|
||||
* @since 2016年5月24日
|
||||
*/
|
||||
public class RepositoryServiceImpl extends BaseRepositoryService implements RepositoryService, ApplicationContextAware {
|
||||
private PermissionService permissionService;
|
||||
|
||||
@Override
|
||||
public List<UserPermission> loadResourceSecurityConfigs(String companyId) throws Exception{
|
||||
List<UserPermission> configs=new ArrayList<UserPermission>();
|
||||
String filePath=RESOURCE_SECURITY_CONFIG_FILE+(companyId == null ? "" : companyId);
|
||||
Node rootNode=getRootNode();
|
||||
Node fileNode = rootNode.getNode(filePath);
|
||||
Property property = fileNode.getProperty(DATA);
|
||||
Binary fileBinary = property.getBinary();
|
||||
InputStream inputStream = fileBinary.getStream();
|
||||
String content = IOUtils.toString(inputStream, "utf-8");
|
||||
inputStream.close();
|
||||
Document document = DocumentHelper.parseText(content);
|
||||
Element rootElement = document.getRootElement();
|
||||
for (Object obj : rootElement.elements()) {
|
||||
if (!(obj instanceof Element)) {
|
||||
continue;
|
||||
}
|
||||
Element element = (Element) obj;
|
||||
if (!element.getName().equals("user-permission")) {
|
||||
continue;
|
||||
}
|
||||
UserPermission userResource=new UserPermission();
|
||||
userResource.setUsername(element.attributeValue("username"));
|
||||
userResource.setProjectConfigs(parseProjectConfigs(element));
|
||||
configs.add(userResource);
|
||||
}
|
||||
return configs;
|
||||
}
|
||||
|
||||
private List<ProjectConfig> parseProjectConfigs(Element element){
|
||||
List<ProjectConfig> list=new ArrayList<ProjectConfig>();
|
||||
for (Object obj : element.elements()) {
|
||||
if (!(obj instanceof Element)) {
|
||||
continue;
|
||||
}
|
||||
Element ele = (Element) obj;
|
||||
if (!ele.getName().equals("project-config")) {
|
||||
continue;
|
||||
}
|
||||
ProjectConfig config=new ProjectConfig();
|
||||
config.setProject(ele.attributeValue("project"));
|
||||
config.setReadProject(parseBooleanValue(ele, "read-project"));
|
||||
|
||||
config.setReadPackage(parseBooleanValue(ele, "read-package"));
|
||||
config.setWritePackage(parseBooleanValue(ele, "write-package"));
|
||||
|
||||
config.setReadVariableFile(parseBooleanValue(ele, "read-variable-file"));
|
||||
config.setWriteVariableFile(parseBooleanValue(ele, "write-variable-file"));
|
||||
|
||||
config.setReadParameterFile(parseBooleanValue(ele, "read-parameter-file"));
|
||||
config.setWriteParameterFile(parseBooleanValue(ele, "write-parameter-file"));
|
||||
|
||||
config.setReadConstantFile(parseBooleanValue(ele, "read-constant-file"));
|
||||
config.setWriteConstantFile(parseBooleanValue(ele, "write-constant-file"));
|
||||
|
||||
config.setReadActionFile(parseBooleanValue(ele, "read-action-file"));
|
||||
config.setWriteActionFile(parseBooleanValue(ele, "write-action-file"));
|
||||
|
||||
config.setReadRuleFile(parseBooleanValue(ele, "read-rule-file"));
|
||||
config.setWriteRuleFile(parseBooleanValue(ele, "write-rule-file"));
|
||||
|
||||
config.setReadScorecardFile(parseBooleanValue(ele, "read-scorecard-file"));
|
||||
config.setWriteScorecardFile(parseBooleanValue(ele, "write-scorecard-file"));
|
||||
|
||||
config.setReadDecisionTableFile(parseBooleanValue(ele, "read-decision-table-file"));
|
||||
config.setWriteDecisionTableFile(parseBooleanValue(ele, "write-decision-table-file"));
|
||||
|
||||
config.setReadDecisionTreeFile(parseBooleanValue(ele, "read-decision-tree-file"));
|
||||
config.setWriteDecisionTreeFile(parseBooleanValue(ele, "write-decision-tree-file"));
|
||||
|
||||
config.setReadFlowFile(parseBooleanValue(ele, "read-flow-file"));
|
||||
config.setWriteFlowFile(parseBooleanValue(ele, "write-flow-file"));
|
||||
list.add(config);
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
private boolean parseBooleanValue(Element element,String attributeName){
|
||||
if(element.attributeValue(attributeName)!=null){
|
||||
return Boolean.valueOf(element.attributeValue(attributeName));
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ClientConfig> loadClientConfigs(String project) throws Exception{
|
||||
if(!permissionService.isAdmin()){
|
||||
throw new NoPermissionException();
|
||||
}
|
||||
List<ClientConfig> clients=new ArrayList<ClientConfig>();
|
||||
Node rootNode=getRootNode();
|
||||
String filePath = processPath(project) + "/" + CLIENT_CONFIG_FILE;
|
||||
Node fileNode = rootNode.getNode(filePath);
|
||||
Property property = fileNode.getProperty(DATA);
|
||||
Binary fileBinary = property.getBinary();
|
||||
InputStream inputStream = fileBinary.getStream();
|
||||
String content = IOUtils.toString(inputStream, "utf-8");
|
||||
inputStream.close();
|
||||
Document document = DocumentHelper.parseText(content);
|
||||
Element rootElement = document.getRootElement();
|
||||
for (Object obj : rootElement.elements()) {
|
||||
if (!(obj instanceof Element)) {
|
||||
continue;
|
||||
}
|
||||
Element element = (Element) obj;
|
||||
if (!element.getName().equals("item")) {
|
||||
continue;
|
||||
}
|
||||
ClientConfig client = new ClientConfig();
|
||||
client.setName(element.attributeValue("name"));
|
||||
client.setClient(element.attributeValue("client"));
|
||||
client.setProject(project);
|
||||
clients.add(client);
|
||||
}
|
||||
return clients;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<RepositoryFile> getDirectories(String project) throws Exception {
|
||||
Node rootNode=getRootNode();
|
||||
NodeIterator nodeIterator = rootNode.getNodes();
|
||||
Node targetProjectNode = null;
|
||||
while (nodeIterator.hasNext()) {
|
||||
Node projectNode = nodeIterator.nextNode();
|
||||
if (!projectNode.hasProperty(FILE)) {
|
||||
continue;
|
||||
}
|
||||
String projectName = projectNode.getName();
|
||||
if (project != null && !project.equals(projectName)) {
|
||||
continue;
|
||||
}
|
||||
targetProjectNode = projectNode;
|
||||
break;
|
||||
}
|
||||
if (targetProjectNode == null) {
|
||||
throw new RuleException("Project [" + project + "] not exist.");
|
||||
}
|
||||
List<RepositoryFile> fileList = new ArrayList<RepositoryFile>();
|
||||
RepositoryFile root = new RepositoryFile();
|
||||
root.setName("根目录");
|
||||
String projectPath = targetProjectNode.getPath();
|
||||
root.setFullPath(projectPath);
|
||||
fileList.add(root);
|
||||
NodeIterator projectNodeIterator = targetProjectNode.getNodes();
|
||||
while (projectNodeIterator.hasNext()) {
|
||||
Node dirNode = projectNodeIterator.nextNode();
|
||||
if (!dirNode.hasProperty(DIR_TAG)) {
|
||||
continue;
|
||||
}
|
||||
RepositoryFile file = new RepositoryFile();
|
||||
file.setName(dirNode.getPath().substring(projectPath.length()));
|
||||
file.setFullPath(dirNode.getPath());
|
||||
fileList.add(file);
|
||||
buildDirectories(dirNode, fileList, projectPath);
|
||||
}
|
||||
return fileList;
|
||||
}
|
||||
|
||||
private void buildDirectories(Node node, List<RepositoryFile> fileList, String projectPath) throws Exception {
|
||||
NodeIterator nodeIterator = node.getNodes();
|
||||
while (nodeIterator.hasNext()) {
|
||||
Node dirNode = nodeIterator.nextNode();
|
||||
if (!dirNode.hasProperty(FILE)) {
|
||||
continue;
|
||||
}
|
||||
if (!dirNode.hasProperty(DIR_TAG)) {
|
||||
continue;
|
||||
}
|
||||
RepositoryFile file = new RepositoryFile();
|
||||
file.setName(dirNode.getPath().substring(projectPath.length()));
|
||||
file.setFullPath(dirNode.getPath());
|
||||
buildDirectories(dirNode, fileList, projectPath);
|
||||
fileList.add(file);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Repository loadRepository(String project,User user,boolean classify,FileType[] types,String searchFileName) throws Exception{
|
||||
String companyId=user.getCompanyId();
|
||||
createSecurityConfigFile(user);
|
||||
if(project!=null && project.startsWith("/")){
|
||||
project=project.substring(1,project.length());
|
||||
}
|
||||
Repository repo=new Repository();
|
||||
List<String> projectNames=new ArrayList<String>();
|
||||
repo.setProjectNames(projectNames);
|
||||
RepositoryFile rootFile = new RepositoryFile();
|
||||
rootFile.setFullPath("/");
|
||||
rootFile.setName("项目列表");
|
||||
rootFile.setType(Type.root);
|
||||
Node rootNode=getRootNode();
|
||||
NodeIterator nodeIterator = rootNode.getNodes();
|
||||
while (nodeIterator.hasNext()) {
|
||||
Node projectNode = nodeIterator.nextNode();
|
||||
if (!projectNode.hasProperty(FILE)) {
|
||||
continue;
|
||||
}
|
||||
if(StringUtils.isNotEmpty(companyId)){
|
||||
if(projectNode.hasProperty(COMPANY_ID)){
|
||||
String id=projectNode.getProperty(COMPANY_ID).getString();
|
||||
if(!companyId.equals(id)){
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
String projectName = projectNode.getName();
|
||||
if(projectName.indexOf(RESOURCE_SECURITY_CONFIG_FILE)>-1){
|
||||
continue;
|
||||
}
|
||||
if (StringUtils.isNotBlank(project) && !project.equals(projectName)) {
|
||||
continue;
|
||||
}
|
||||
if(!permissionService.projectHasPermission(projectNode.getPath())){
|
||||
continue;
|
||||
}
|
||||
if(StringUtils.isBlank(project)){
|
||||
projectNames.add(projectName);
|
||||
}
|
||||
RepositoryFile projectFile=buildProjectFile(projectNode,types,classify,searchFileName);
|
||||
rootFile.addChild(projectFile, false);
|
||||
}
|
||||
repo.setRootFile(rootFile);
|
||||
return repo;
|
||||
}
|
||||
|
||||
private RepositoryFile buildProjectFile(Node projectNode,FileType[] types,boolean classify,String searchFileName) throws Exception{
|
||||
RepositoryFile projectFile = new RepositoryFile();
|
||||
projectFile.setType(Type.project);
|
||||
projectFile.setName(projectNode.getName());
|
||||
projectFile.setFullPath("/" + projectNode.getName());
|
||||
RepositoryFile resDir = new RepositoryFile();
|
||||
resDir.setFullPath(projectFile.getFullPath());
|
||||
resDir.setName("资源");
|
||||
if((types==null || types.length==0) && permissionService.projectPackageHasReadPermission(projectNode.getPath())){
|
||||
RepositoryFile packageFile = new RepositoryFile();
|
||||
packageFile.setName("知识包");
|
||||
packageFile.setType(Type.resourcePackage);
|
||||
packageFile.setFullPath(projectFile.getFullPath());
|
||||
projectFile.addChild(packageFile, false);
|
||||
}
|
||||
if(classify){
|
||||
resDir.setType(Type.resource);
|
||||
createResourceCategory(projectNode, resDir,types,searchFileName);
|
||||
}else{
|
||||
resDir.setType(Type.all);
|
||||
buildResources(projectNode, resDir, types,searchFileName);
|
||||
}
|
||||
projectFile.addChild(resDir, false);
|
||||
return projectFile;
|
||||
}
|
||||
|
||||
private void buildResources(Node projectNode, RepositoryFile libDir,FileType[] types,String searchFileName) throws Exception{
|
||||
FileType[] fileTypes=types;
|
||||
if(types==null || types.length==0){
|
||||
fileTypes = new FileType[] { FileType.VariableLibrary,
|
||||
FileType.ParameterLibrary, FileType.ConstantLibrary,
|
||||
FileType.ActionLibrary, FileType.Ruleset,
|
||||
FileType.RuleFlow, FileType.DecisionTable,
|
||||
FileType.DecisionTree, FileType.ScriptDecisionTable,
|
||||
FileType.UL,FileType.Scorecard };
|
||||
}
|
||||
libDir.setLibType(LibType.all);
|
||||
buildNodes(projectNode.getNodes(), libDir, fileTypes,Type.all,searchFileName);
|
||||
}
|
||||
|
||||
private void createResourceCategory(Node projectNode, RepositoryFile libDir,FileType[] types,String searchFileName) throws Exception{
|
||||
RepositoryFile subLib = buildLibFile(libDir,"库",LibType.res);
|
||||
subLib.setType(Type.lib);
|
||||
libDir.addChild(subLib, false);
|
||||
FileType[] librarySubTypes = types;
|
||||
if(types==null || types.length==0){
|
||||
librarySubTypes=new FileType[] { FileType.VariableLibrary, FileType.ParameterLibrary,FileType.ConstantLibrary, FileType.ActionLibrary };
|
||||
}
|
||||
buildNodes(projectNode.getNodes(), subLib, librarySubTypes,Type.lib,searchFileName);
|
||||
|
||||
RepositoryFile rulesLib = buildLibFile(libDir,"决策集",LibType.ruleset);
|
||||
rulesLib.setFullPath(libDir.getFullPath());
|
||||
rulesLib.setType(Type.ruleLib);
|
||||
|
||||
RepositoryFile decisionTableLib = buildLibFile(libDir,"决策表",LibType.decisiontable);
|
||||
decisionTableLib.setFullPath(libDir.getFullPath());
|
||||
decisionTableLib.setType(Type.decisionTableLib);
|
||||
|
||||
RepositoryFile decisionTreeLib = buildLibFile(libDir,"决策树",LibType.decisiontree);
|
||||
decisionTreeLib.setFullPath(libDir.getFullPath());
|
||||
decisionTreeLib.setType(Type.decisionTreeLib);
|
||||
|
||||
RepositoryFile scorecardLib = buildLibFile(libDir,"评分卡",LibType.scorecard);
|
||||
scorecardLib.setFullPath(libDir.getFullPath());
|
||||
scorecardLib.setType(Type.scorecardLib);
|
||||
|
||||
RepositoryFile flowLib = buildLibFile(libDir,"决策流",LibType.ruleflow);
|
||||
flowLib.setFullPath(libDir.getFullPath());
|
||||
flowLib.setType(Type.flowLib);
|
||||
|
||||
libDir.addChild(rulesLib, false);
|
||||
libDir.addChild(decisionTableLib, false);
|
||||
libDir.addChild(decisionTreeLib, false);
|
||||
libDir.addChild(scorecardLib, false);
|
||||
libDir.addChild(flowLib, false);
|
||||
|
||||
FileType[] libraryRuleTypes = types;
|
||||
if(types==null || types.length==0){
|
||||
libraryRuleTypes=new FileType[] { FileType.Ruleset, FileType.UL };
|
||||
}
|
||||
|
||||
FileType[] libraryDecisionTypes = types;
|
||||
if(types==null || types.length==0){
|
||||
libraryDecisionTypes = new FileType[] { FileType.DecisionTable, FileType.ScriptDecisionTable };
|
||||
}
|
||||
FileType[] libraryDecisionTreeTypes = types;
|
||||
if(types==null || types.length==0){
|
||||
libraryDecisionTreeTypes = new FileType[] { FileType.DecisionTree };
|
||||
}
|
||||
|
||||
FileType[] libraryFlowTypes = types;
|
||||
if(types==null || types.length==0){
|
||||
libraryFlowTypes = new FileType[] { FileType.RuleFlow };
|
||||
}
|
||||
|
||||
FileType[] libraryScorecardTypes = types;
|
||||
if(types==null || types.length==0){
|
||||
libraryScorecardTypes = new FileType[] { FileType.Scorecard };
|
||||
}
|
||||
|
||||
buildNodes(projectNode.getNodes(), rulesLib, libraryRuleTypes,Type.ruleLib,searchFileName);
|
||||
buildNodes(projectNode.getNodes(), decisionTableLib, libraryDecisionTypes,Type.decisionTableLib,searchFileName);
|
||||
buildNodes(projectNode.getNodes(), decisionTreeLib, libraryDecisionTreeTypes,Type.decisionTreeLib,searchFileName);
|
||||
buildNodes(projectNode.getNodes(), scorecardLib, libraryScorecardTypes,Type.scorecardLib,searchFileName);
|
||||
buildNodes(projectNode.getNodes(), flowLib, libraryFlowTypes,Type.flowLib,searchFileName);
|
||||
}
|
||||
|
||||
private RepositoryFile buildLibFile(RepositoryFile libraryDir,String name,LibType libType) {
|
||||
RepositoryFile subLib = new RepositoryFile();
|
||||
subLib.setFullPath(libraryDir.getFullPath());
|
||||
subLib.setName(name);
|
||||
subLib.setLibType(libType);
|
||||
return subLib;
|
||||
}
|
||||
|
||||
private void buildNodes(NodeIterator nodeIterator, RepositoryFile parent, FileType[] types,Type folderType,String searchFileName) throws Exception{
|
||||
LibType libType=parent.getLibType();
|
||||
while (nodeIterator.hasNext()) {
|
||||
Node fileNode = nodeIterator.nextNode();
|
||||
if (!fileNode.hasProperty(FILE)) {
|
||||
continue;
|
||||
}
|
||||
RepositoryFile file = new RepositoryFile();
|
||||
file.setLibType(libType);
|
||||
String name = fileNode.getName();
|
||||
if (name.toLowerCase().indexOf(RES_PACKGE_FILE) > -1 || name.toLowerCase().indexOf(CLIENT_CONFIG_FILE) > -1 || name.toLowerCase().indexOf(RESOURCE_SECURITY_CONFIG_FILE) > -1) {
|
||||
continue;
|
||||
}
|
||||
if (!fileNode.hasProperty(DIR_TAG)) {
|
||||
if(!permissionService.fileHasReadPermission(fileNode.getPath())){
|
||||
continue;
|
||||
}
|
||||
FileType fileType=null;
|
||||
boolean add = false;
|
||||
for (FileType type : types) {
|
||||
if (name.toLowerCase().endsWith(type.toString())) {
|
||||
fileType=type;
|
||||
add = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!add) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if(libType.equals(LibType.res)){
|
||||
if(!fileType.equals(FileType.ActionLibrary) && !fileType.equals(FileType.ParameterLibrary) && !fileType.equals(FileType.ConstantLibrary) && !fileType.equals(FileType.VariableLibrary)) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if(libType.equals(LibType.decisiontable)){
|
||||
if(!fileType.equals(FileType.ScriptDecisionTable) && !fileType.equals(FileType.DecisionTable)) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if(libType.equals(LibType.decisiontree)){
|
||||
if(!fileType.equals(FileType.DecisionTree)) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if(libType.equals(LibType.ruleflow)){
|
||||
if(!fileType.equals(FileType.RuleFlow)) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if(libType.equals(LibType.scorecard)){
|
||||
if(!fileType.equals(FileType.Scorecard)) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if(libType.equals(LibType.ruleset)){
|
||||
if(!fileType.equals(FileType.Ruleset) && !fileType.equals(FileType.UL)) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
if(StringUtils.isNotBlank(searchFileName)){
|
||||
if(name.toLowerCase().indexOf(searchFileName.toLowerCase())==-1){
|
||||
continue;
|
||||
}
|
||||
}
|
||||
if (name.toLowerCase().endsWith(FileType.ActionLibrary.toString())) {
|
||||
file.setType(Type.action);
|
||||
} else if (name.toLowerCase().endsWith(FileType.VariableLibrary.toString())) {
|
||||
file.setType(Type.variable);
|
||||
} else if (name.toLowerCase().endsWith(FileType.ConstantLibrary.toString())) {
|
||||
file.setType(Type.constant);
|
||||
} else if (name.toLowerCase().endsWith(FileType.Ruleset.toString())) {
|
||||
file.setType(Type.rule);
|
||||
} else if (name.toLowerCase().endsWith(FileType.DecisionTable.toString())) {
|
||||
file.setType(Type.decisionTable);
|
||||
} else if (name.toLowerCase().endsWith(FileType.UL.toString())) {
|
||||
file.setType(Type.ul);
|
||||
} else if (name.toLowerCase().endsWith(FileType.ParameterLibrary.toString())) {
|
||||
file.setType(Type.parameter);
|
||||
} else if (name.toLowerCase().endsWith(FileType.RuleFlow.toString())) {
|
||||
file.setType(Type.flow);
|
||||
} else if (name.toLowerCase().endsWith(FileType.ScriptDecisionTable.toString())) {
|
||||
file.setType(Type.scriptDecisionTable);
|
||||
} else if (name.toLowerCase().endsWith(FileType.DecisionTree.toString())) {
|
||||
file.setType(Type.decisionTree);
|
||||
} else if (name.toLowerCase().endsWith(FileType.Scorecard.toString())) {
|
||||
file.setType(Type.scorecard);
|
||||
}
|
||||
file.setFullPath(fileNode.getPath());
|
||||
file.setName(name);
|
||||
buildNodeLockInfo(fileNode,file);
|
||||
parent.addChild(file, false);
|
||||
buildNodes(fileNode.getNodes(), file, types,folderType,searchFileName);
|
||||
}else{
|
||||
file.setFullPath(fileNode.getPath());
|
||||
file.setName(name);
|
||||
file.setType(Type.folder);
|
||||
buildNodeLockInfo(fileNode,file);
|
||||
file.setFolderType(folderType);
|
||||
parent.addChild(file, true);
|
||||
buildNodes(fileNode.getNodes(), file, types,folderType,searchFileName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void buildNodeLockInfo(Node node,RepositoryFile file) throws Exception{
|
||||
String absPath=node.getPath();
|
||||
if(!lockManager.isLocked(absPath)){
|
||||
return;
|
||||
}
|
||||
String owner=lockManager.getLock(absPath).getLockOwner();
|
||||
file.setLock(true);
|
||||
file.setLockInfo("被"+owner+"锁定");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void lockPath(String path,User user) throws Exception{
|
||||
path = processPath(path);
|
||||
int pos=path.indexOf(":");
|
||||
if(pos!=-1){
|
||||
path=path.substring(0,pos);
|
||||
}
|
||||
Node rootNode=getRootNode();
|
||||
if (!rootNode.hasNode(path)) {
|
||||
throw new RuleException("File [" + path + "] not exist.");
|
||||
}
|
||||
Node fileNode = rootNode.getNode(path);
|
||||
String topAbsPath=fileNode.getPath();
|
||||
if(lockManager.isLocked(topAbsPath)){
|
||||
String owner=lockManager.getLock(topAbsPath).getLockOwner();
|
||||
throw new NodeLockException("【"+path+"】已被"+owner+"锁定,您不能进行再次锁定!");
|
||||
}
|
||||
List<Node> nodeList=new ArrayList<Node>();
|
||||
unlockAllChildNodes(fileNode, user, nodeList, path);
|
||||
for(Node node:nodeList){
|
||||
if(!lockManager.isLocked(node.getPath())){
|
||||
continue;
|
||||
}
|
||||
Lock lock=lockManager.getLock(node.getPath());
|
||||
lockManager.unlock(lock.getNode().getPath());
|
||||
}
|
||||
if(!fileNode.isNodeType(NodeType.MIX_LOCKABLE)){
|
||||
if (!fileNode.isCheckedOut()) {
|
||||
versionManager.checkout(fileNode.getPath());
|
||||
}
|
||||
fileNode.addMixin("mix:lockable");
|
||||
session.save();
|
||||
}
|
||||
lockManager.lock(topAbsPath, true, true, Long.MAX_VALUE, user.getUsername());
|
||||
}
|
||||
|
||||
private void unlockAllChildNodes(Node node,User user,List<Node> nodeList,String rootPath) throws Exception{
|
||||
NodeIterator iter=node.getNodes();
|
||||
while(iter.hasNext()){
|
||||
Node nextNode=iter.nextNode();
|
||||
String absPath=nextNode.getPath();
|
||||
if(!lockManager.isLocked(absPath)){
|
||||
continue;
|
||||
}
|
||||
Lock lock=lockManager.getLock(absPath);
|
||||
String owner=lock.getLockOwner();
|
||||
if(!user.getUsername().equals(owner)){
|
||||
throw new NodeLockException("当前目录下有子目录被其它人锁定,您不能执行锁定"+rootPath+"目录");
|
||||
}
|
||||
nodeList.add(nextNode);
|
||||
unlockAllChildNodes(nextNode, user, nodeList, rootPath);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unlockPath(String path,User user) throws Exception{
|
||||
path = processPath(path);
|
||||
int pos=path.indexOf(":");
|
||||
if(pos!=-1){
|
||||
path=path.substring(0,pos);
|
||||
}
|
||||
Node rootNode=getRootNode();
|
||||
if (!rootNode.hasNode(path)) {
|
||||
throw new RuleException("File [" + path + "] not exist.");
|
||||
}
|
||||
Node fileNode = rootNode.getNode(path);
|
||||
String absPath=fileNode.getPath();
|
||||
if(!lockManager.isLocked(absPath)){
|
||||
throw new NodeLockException("当前文件未锁定,不需要解锁!");
|
||||
}
|
||||
Lock lock=lockManager.getLock(absPath);
|
||||
String owner=lock.getLockOwner();
|
||||
if(!owner.equals(user.getUsername())){
|
||||
throw new NodeLockException("当前文件由【"+owner+"】锁定,您无权解锁!");
|
||||
}
|
||||
lockManager.unlock(lock.getNode().getPath());
|
||||
}
|
||||
|
||||
public void deleteFile(String path,User user) throws Exception{
|
||||
if(!permissionService.fileHasWritePermission(path)){
|
||||
throw new NoPermissionException();
|
||||
}
|
||||
repositoryInteceptor.deleteFile(path);
|
||||
path = processPath(path);
|
||||
Node rootNode=getRootNode();
|
||||
if (!rootNode.hasNode(path)) {
|
||||
throw new RuleException("File [" + path + "] not exist.");
|
||||
}
|
||||
String[] subpaths = path.split("/");
|
||||
Node fileNode = rootNode;
|
||||
for (String subpath : subpaths) {
|
||||
if (StringUtils.isEmpty(subpath)) {
|
||||
continue;
|
||||
}
|
||||
String subDirs[] = subpath.split("\\.");
|
||||
for (String dir : subDirs) {
|
||||
if (StringUtils.isEmpty(dir)) {
|
||||
continue;
|
||||
}
|
||||
if (!fileNode.hasNode(dir)) {
|
||||
continue;
|
||||
}
|
||||
fileNode = fileNode.getNode(dir);
|
||||
lockCheck(fileNode,user);
|
||||
if (!fileNode.isCheckedOut()) {
|
||||
versionManager.checkout(fileNode.getPath());
|
||||
}
|
||||
}
|
||||
}
|
||||
fileNode = rootNode.getNode(path);
|
||||
lockCheck(fileNode,user);
|
||||
if (!fileNode.isCheckedOut()) {
|
||||
versionManager.checkout(fileNode.getPath());
|
||||
}
|
||||
fileNode.remove();
|
||||
session.save();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void saveFile(String path, String content,boolean newVersion,String versionComment,User user) throws Exception{
|
||||
path=Utils.decodeURL(path);
|
||||
if(path.indexOf(RES_PACKGE_FILE)>-1){
|
||||
if(!permissionService.projectPackageHasWritePermission(path)){
|
||||
throw new NoPermissionException();
|
||||
}
|
||||
}
|
||||
if(!permissionService.fileHasWritePermission(path)){
|
||||
throw new NoPermissionException();
|
||||
}
|
||||
|
||||
repositoryInteceptor.saveFile(path, content);
|
||||
path = processPath(path);
|
||||
int pos=path.indexOf(":");
|
||||
if(pos!=-1){
|
||||
path=path.substring(0,pos);
|
||||
}
|
||||
Node rootNode=getRootNode();
|
||||
if (!rootNode.hasNode(path)) {
|
||||
throw new RuleException("File [" + path + "] not exist.");
|
||||
}
|
||||
Node fileNode = rootNode.getNode(path);
|
||||
lockCheck(fileNode,user);
|
||||
versionManager.checkout(fileNode.getPath());
|
||||
Binary fileBinary = new BinaryImpl(content.getBytes("utf-8"));
|
||||
fileNode.setProperty(DATA, fileBinary);
|
||||
fileNode.setProperty(FILE, true);
|
||||
fileNode.setProperty(CRATE_USER, user.getUsername());
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
calendar.setTime(new Date());
|
||||
DateValue dateValue = new DateValue(calendar);
|
||||
fileNode.setProperty(CRATE_DATE, dateValue);
|
||||
if (newVersion && StringUtils.isNotBlank(versionComment)) {
|
||||
fileNode.setProperty(VERSION_COMMENT, versionComment);
|
||||
}
|
||||
session.save();
|
||||
if (newVersion) {
|
||||
versionManager.checkin(fileNode.getPath());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getReferenceFiles(String path,String searchText) throws Exception{
|
||||
Node rootNode=getRootNode();
|
||||
List<String> referenceFiles=new ArrayList<String>();
|
||||
List<String> files=getFiles(rootNode, path);
|
||||
for(String nodePath:files){
|
||||
InputStream inputStream=readFile(nodePath,null);
|
||||
try {
|
||||
String content = IOUtils.toString(inputStream);
|
||||
inputStream.close();
|
||||
boolean containPath=content.contains(path);
|
||||
boolean containText=content.contains(searchText);
|
||||
if(containPath && containText){
|
||||
referenceFiles.add(nodePath);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new RuleException(e);
|
||||
}
|
||||
}
|
||||
return referenceFiles;
|
||||
}
|
||||
|
||||
private List<String> getFiles(Node rootNode,String path) throws Exception{
|
||||
String project=getProject(path);
|
||||
List<String> list=new ArrayList<String>();
|
||||
Node projectNode=rootNode.getNode(project);
|
||||
buildPath(list, projectNode);
|
||||
return list;
|
||||
}
|
||||
|
||||
private void buildPath(List<String> list, Node parentNode) throws RepositoryException {
|
||||
NodeIterator nodeIterator=parentNode.getNodes();
|
||||
while(nodeIterator.hasNext()){
|
||||
Node node=nodeIterator.nextNode();
|
||||
String nodePath=node.getPath();
|
||||
if(nodePath.endsWith(FileType.Ruleset.toString())){
|
||||
list.add(nodePath);
|
||||
}else if(nodePath.endsWith(FileType.UL.toString())){
|
||||
list.add(nodePath);
|
||||
}else if(nodePath.endsWith(FileType.DecisionTable.toString())){
|
||||
list.add(nodePath);
|
||||
}else if(nodePath.endsWith(FileType.ScriptDecisionTable.toString())){
|
||||
list.add(nodePath);
|
||||
}else if(nodePath.endsWith(FileType.DecisionTree.toString())){
|
||||
list.add(nodePath);
|
||||
}else if(nodePath.endsWith(FileType.RuleFlow.toString())){
|
||||
list.add(nodePath);
|
||||
}
|
||||
buildPath(list,node);
|
||||
}
|
||||
}
|
||||
|
||||
private String getProject(String path){
|
||||
if(path.startsWith("/")){
|
||||
path=path.substring(1);
|
||||
}
|
||||
int pos=path.indexOf("/");
|
||||
return path.substring(0,pos);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean fileExistCheck(String filePath) throws Exception{
|
||||
Node rootNode=getRootNode();
|
||||
filePath=processPath(filePath);
|
||||
if(filePath.contains(" ") || filePath.equals("")){
|
||||
return true;
|
||||
}
|
||||
if(rootNode.hasNode(filePath)){
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public RepositoryFile createProject(String projectName, User user,boolean classify) throws Exception{
|
||||
if(!permissionService.isAdmin()){
|
||||
throw new NoPermissionException();
|
||||
}
|
||||
repositoryInteceptor.createProject(projectName);
|
||||
Node rootNode=getRootNode();
|
||||
if(rootNode.hasNode(projectName)){
|
||||
throw new RuleException("Project ["+projectName+"] already exist.");
|
||||
}
|
||||
Node projectNode=rootNode.addNode(projectName);
|
||||
projectNode.addMixin("mix:versionable");
|
||||
projectNode.setProperty(FILE, true);
|
||||
projectNode.setProperty(CRATE_USER,user.getUsername());
|
||||
projectNode.setProperty(COMPANY_ID, user.getCompanyId());
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
calendar.setTime(new Date());
|
||||
DateValue dateValue = new DateValue(calendar);
|
||||
projectNode.setProperty(CRATE_DATE, dateValue);
|
||||
session.save();
|
||||
createResourcePackageFile(projectName,user);
|
||||
createClientConfigFile(projectName, user);
|
||||
RepositoryFile projectFileInfo=buildProjectFile(projectNode, null ,classify,null);
|
||||
return projectFileInfo;
|
||||
}
|
||||
|
||||
public void createDir(String path,User user) throws Exception{
|
||||
if(!permissionService.isAdmin()){
|
||||
throw new NoPermissionException();
|
||||
}
|
||||
repositoryInteceptor.createDir(path);
|
||||
Node rootNode=getRootNode();
|
||||
path = processPath(path);
|
||||
if (rootNode.hasNode(path)) {
|
||||
throw new RuleException("Dir [" + path + "] already exist.");
|
||||
}
|
||||
boolean add = false;
|
||||
String[] subpaths = path.split("/");
|
||||
Node parentNode = rootNode;
|
||||
for (String subpath : subpaths) {
|
||||
if (StringUtils.isEmpty(subpath)) {
|
||||
continue;
|
||||
}
|
||||
String subDirs[] = subpath.split("\\.");
|
||||
for (String dir : subDirs) {
|
||||
if (StringUtils.isEmpty(dir)) {
|
||||
continue;
|
||||
}
|
||||
if (parentNode.hasNode(dir)) {
|
||||
parentNode = parentNode.getNode(dir);
|
||||
} else {
|
||||
parentNode = parentNode.addNode(dir);
|
||||
parentNode.addMixin("mix:versionable");
|
||||
parentNode.addMixin("mix:lockable");
|
||||
parentNode.setProperty(DIR_TAG, true);
|
||||
parentNode.setProperty(FILE, true);
|
||||
parentNode.setProperty(CRATE_USER,user.getUsername());
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
calendar.setTime(new Date());
|
||||
DateValue dateValue = new DateValue(calendar);
|
||||
parentNode.setProperty(CRATE_DATE, dateValue);
|
||||
add = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (add) {
|
||||
session.save();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void createFile(String path, String content,User user) throws Exception{
|
||||
if(!permissionService.isAdmin()){
|
||||
throw new NoPermissionException();
|
||||
}
|
||||
createFileNode(path, content, user, true);
|
||||
}
|
||||
|
||||
public void fileRename(String path, String newPath) throws Exception{
|
||||
if(!permissionService.isAdmin()){
|
||||
throw new NoPermissionException();
|
||||
}
|
||||
|
||||
repositoryInteceptor.renameFile(path, newPath);
|
||||
path = processPath(path);
|
||||
newPath = processPath(newPath);
|
||||
Node rootNode=getRootNode();
|
||||
if (!rootNode.hasNode(path)) {
|
||||
throw new RuleException("File [" + path + "] not exist.");
|
||||
}
|
||||
session.getWorkspace().move("/" + path, "/" + newPath);
|
||||
session.save();
|
||||
}
|
||||
|
||||
public void exportXml(String projectPath, OutputStream outputStream) throws Exception{
|
||||
if(!permissionService.isAdmin()){
|
||||
throw new NoPermissionException();
|
||||
}
|
||||
session.exportSystemView(projectPath, outputStream, false, false);
|
||||
}
|
||||
|
||||
public void importXml(InputStream inputStream,boolean overwrite) throws Exception{
|
||||
if(!permissionService.isAdmin()){
|
||||
throw new NoPermissionException();
|
||||
}
|
||||
String rootNodePath=getRootNode().getPath();
|
||||
if(overwrite){
|
||||
session.importXML(rootNodePath, inputStream,ImportUUIDBehavior.IMPORT_UUID_COLLISION_REPLACE_EXISTING);
|
||||
}else{
|
||||
session.importXML(rootNodePath, inputStream,ImportUUIDBehavior.IMPORT_UUID_CREATE_NEW);
|
||||
}
|
||||
session.save();
|
||||
}
|
||||
|
||||
private void createResourcePackageFile(String project,User user) throws Exception{
|
||||
String filePath = processPath(project) + "/" + RES_PACKGE_FILE;
|
||||
Node rootNode=getRootNode();
|
||||
if (!rootNode.hasNode(filePath)) {
|
||||
createFile(filePath, "<?xml version=\"1.0\" encoding=\"utf-8\"?><res-packages></res-packages>",user);
|
||||
}
|
||||
}
|
||||
|
||||
private void createClientConfigFile(String project,User user) throws Exception{
|
||||
Node rootNode=getRootNode();
|
||||
String filePath = processPath(project) + "/" + CLIENT_CONFIG_FILE;
|
||||
if (!rootNode.hasNode(filePath)) {
|
||||
createFile(filePath, "<?xml version=\"1.0\" encoding=\"utf-8\"?><client-config></client-config>",user);
|
||||
}
|
||||
}
|
||||
|
||||
private void createSecurityConfigFile(User user) throws Exception{
|
||||
String companyId=user.getCompanyId();
|
||||
String filePath=RESOURCE_SECURITY_CONFIG_FILE+(companyId == null ? "" : companyId);
|
||||
Node rootNode=getRootNode();
|
||||
if (!rootNode.hasNode(filePath)) {
|
||||
createFileNode(filePath, "<?xml version=\"1.0\" encoding=\"utf-8\"?><user-permission></user-permission>",user,false);
|
||||
}
|
||||
}
|
||||
|
||||
private void createFileNode(String path, String content,User user,boolean isFile) throws Exception{
|
||||
String createUser=user.getUsername();
|
||||
repositoryInteceptor.createFile(path,content);
|
||||
Node rootNode=getRootNode();
|
||||
path = processPath(path);
|
||||
try {
|
||||
if (rootNode.hasNode(path)) {
|
||||
throw new RuleException("File [" + path + "] already exist.");
|
||||
}
|
||||
Node fileNode = rootNode.addNode(path);
|
||||
fileNode.addMixin("mix:versionable");
|
||||
fileNode.addMixin("mix:lockable");
|
||||
Binary fileBinary = new BinaryImpl(content.getBytes());
|
||||
fileNode.setProperty(DATA, fileBinary);
|
||||
if(isFile){
|
||||
fileNode.setProperty(FILE, true);
|
||||
}
|
||||
fileNode.setProperty(CRATE_USER, createUser);
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
calendar.setTime(new Date());
|
||||
DateValue dateValue = new DateValue(calendar);
|
||||
fileNode.setProperty(CRATE_DATE, dateValue);
|
||||
session.save();
|
||||
} catch (Exception ex) {
|
||||
throw new RuleException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
private void lockCheck(Node node,User user) throws Exception{
|
||||
if(lockManager.isLocked(node.getPath())){
|
||||
String lockOwner=lockManager.getLock(node.getPath()).getLockOwner();
|
||||
if(lockOwner.equals(user.getUsername())){
|
||||
return;
|
||||
}
|
||||
throw new NodeLockException("【"+node.getName()+"】已被"+lockOwner+"锁定!");
|
||||
}
|
||||
}
|
||||
|
||||
public void setPermissionService(PermissionService permissionService) {
|
||||
this.permissionService = permissionService;
|
||||
}
|
||||
}
|
||||
+58
@@ -0,0 +1,58 @@
|
||||
/*******************************************************************************
|
||||
* Copyright 2017 Bstek
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
||||
* use this file except in compliance with the License. You may obtain a copy
|
||||
* of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations under
|
||||
* the License.
|
||||
******************************************************************************/
|
||||
package com.itheima.sfbx.rule.console.repository.database;
|
||||
|
||||
import org.apache.jackrabbit.core.fs.FileSystemException;
|
||||
import org.apache.jackrabbit.core.fs.db.DbFileSystem;
|
||||
|
||||
import com.itheima.sfbx.rule.console.repository.RepositoryBuilder;
|
||||
|
||||
/**
|
||||
* @author Jacky.gao
|
||||
* @since 2017年12月6日
|
||||
*/
|
||||
public abstract class BaseDbFileSystem extends DbFileSystem {
|
||||
@Override
|
||||
public void init() throws FileSystemException {
|
||||
if (initialized) {
|
||||
throw new IllegalStateException("already initialized");
|
||||
}
|
||||
try {
|
||||
setSchema(databaseType());
|
||||
conHelper = createConnectionHelper(RepositoryBuilder.datasource);
|
||||
|
||||
// make sure schemaObjectPrefix consists of legal name characters only
|
||||
schemaObjectPrefix = conHelper.prepareDbIdentifier(schemaObjectPrefix);
|
||||
|
||||
// check if schema objects exist and create them if necessary
|
||||
if (isSchemaCheckEnabled()) {
|
||||
createCheckSchemaOperation().run();
|
||||
}
|
||||
|
||||
// build sql statements
|
||||
buildSQLStatements();
|
||||
|
||||
// finally verify that there's a file system root entry
|
||||
verifyRootExists();
|
||||
|
||||
initialized = true;
|
||||
} catch (Exception e) {
|
||||
String msg = "failed to initialize file system";
|
||||
throw new FileSystemException(msg, e);
|
||||
}
|
||||
}
|
||||
public abstract String databaseType();
|
||||
}
|
||||
+93
@@ -0,0 +1,93 @@
|
||||
/*******************************************************************************
|
||||
* Copyright 2017 Bstek
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
||||
* use this file except in compliance with the License. You may obtain a copy
|
||||
* of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations under
|
||||
* the License.
|
||||
******************************************************************************/
|
||||
package com.itheima.sfbx.rule.console.repository.database;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.Properties;
|
||||
|
||||
import org.apache.jackrabbit.core.data.DataStoreException;
|
||||
import org.apache.jackrabbit.core.data.db.DbDataStore;
|
||||
|
||||
import com.itheima.sfbx.rule.console.repository.RepositoryBuilder;
|
||||
|
||||
/**
|
||||
* @author Jacky.gao
|
||||
* @since 2017年12月7日
|
||||
*/
|
||||
public class DatabaseDataStore extends DbDataStore {
|
||||
@Override
|
||||
public synchronized void init(String homeDir) throws DataStoreException {
|
||||
try {
|
||||
initDatabaseType();
|
||||
conHelper = createConnectionHelper(RepositoryBuilder.datasource);
|
||||
if (isSchemaCheckEnabled()) {
|
||||
createCheckSchemaOperation().run();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
throw convert("Can not init data store, driver=" + driver + " url=" + url + " user=" + user +
|
||||
" schemaObjectPrefix=" + schemaObjectPrefix + " tableSQL=" + tableSQL + " createTableSQL=" + createTableSQL, e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void initDatabaseType() throws DataStoreException {
|
||||
databaseType=RepositoryBuilder.databaseType;
|
||||
InputStream in =
|
||||
DbDataStore.class.getResourceAsStream(databaseType + ".properties");
|
||||
if (in == null) {
|
||||
String msg =
|
||||
"Configuration error: The resource '" + databaseType
|
||||
+ ".properties' could not be found;"
|
||||
+ " Please verify the databaseType property";
|
||||
throw new DataStoreException(msg);
|
||||
}
|
||||
Properties prop = new Properties();
|
||||
try {
|
||||
try {
|
||||
prop.load(in);
|
||||
} finally {
|
||||
in.close();
|
||||
}
|
||||
} catch (IOException e) {
|
||||
String msg = "Configuration error: Could not read properties '" + databaseType + ".properties'";
|
||||
throw new DataStoreException(msg, e);
|
||||
}
|
||||
if (driver == null) {
|
||||
driver = getProperty(prop, "driver", driver);
|
||||
}
|
||||
tableSQL = getProperty(prop, "table", tableSQL);
|
||||
createTableSQL = getProperty(prop, "createTable", createTableSQL);
|
||||
insertTempSQL = getProperty(prop, "insertTemp", insertTempSQL);
|
||||
updateDataSQL = getProperty(prop, "updateData", updateDataSQL);
|
||||
updateLastModifiedSQL = getProperty(prop, "updateLastModified", updateLastModifiedSQL);
|
||||
updateSQL = getProperty(prop, "update", updateSQL);
|
||||
deleteSQL = getProperty(prop, "delete", deleteSQL);
|
||||
deleteOlderSQL = getProperty(prop, "deleteOlder", deleteOlderSQL);
|
||||
selectMetaSQL = getProperty(prop, "selectMeta", selectMetaSQL);
|
||||
selectAllSQL = getProperty(prop, "selectAll", selectAllSQL);
|
||||
selectDataSQL = getProperty(prop, "selectData", selectDataSQL);
|
||||
storeStream = getProperty(prop, "storeStream", storeStream);
|
||||
if (!STORE_SIZE_MINUS_ONE.equals(storeStream)
|
||||
&& !STORE_TEMP_FILE.equals(storeStream)
|
||||
&& !STORE_SIZE_MAX.equals(storeStream)) {
|
||||
String msg = "Unsupported Stream store mechanism: " + storeStream
|
||||
+ " supported are: " + STORE_SIZE_MINUS_ONE + ", "
|
||||
+ STORE_TEMP_FILE + ", " + STORE_SIZE_MAX;
|
||||
throw new DataStoreException(msg);
|
||||
}
|
||||
}
|
||||
}
|
||||
+1277
File diff suppressed because it is too large
Load Diff
+40
@@ -0,0 +1,40 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE Repository PUBLIC "-//The Apache Software Foundation//DTD Jackrabbit 1.5//EN" "http://jackrabbit.apache.org/dtd/repository-1.5.dtd">
|
||||
<Repository>
|
||||
<FileSystem class="com.itheima.sfbx.rule.console.repository.database.system.DB2FileSystem">
|
||||
<param name="schemaObjectPrefix" value="repo_"/>
|
||||
</FileSystem>
|
||||
<Security appName="Jackrabbit">
|
||||
<AccessManager class="org.apache.jackrabbit.core.security.simple.SimpleAccessManager"></AccessManager>
|
||||
<LoginModule class="org.apache.jackrabbit.core.security.simple.SimpleLoginModule">
|
||||
<param name="anonymousId" value="anonymous" />
|
||||
<param name="adminId" value="admin" />
|
||||
</LoginModule>
|
||||
</Security>
|
||||
<DataStore class="com.itheima.sfbx.rule.console.repository.database.DatabaseDataStore">
|
||||
<param name="schemaObjectPrefix" value="repo_ds_"/>
|
||||
</DataStore>
|
||||
<Workspaces rootPath="${rep.home}/workspaces" defaultWorkspace="default" />
|
||||
<Workspace name="default">
|
||||
<FileSystem class="com.itheima.sfbx.rule.console.repository.database.system.DB2FileSystem">
|
||||
<param name="schemaObjectPrefix" value="repo_${wsp.name}_"/>
|
||||
</FileSystem>
|
||||
<PersistenceManager class="com.itheima.sfbx.rule.console.repository.database.DbPersistenceManager">
|
||||
<param name="schemaObjectPrefix" value="repo_pm_${wsp.name}_"/>
|
||||
</PersistenceManager>
|
||||
</Workspace>
|
||||
<Versioning rootPath="${rep.home}/version">
|
||||
<FileSystem class="com.itheima.sfbx.rule.console.repository.database.system.DB2FileSystem">
|
||||
<param name="schemaObjectPrefix" value="repo_fsver_"/>
|
||||
</FileSystem>
|
||||
<PersistenceManager class="com.itheima.sfbx.rule.console.repository.database.DbPersistenceManager">
|
||||
<param name="schemaObjectPrefix" value="repo_ver_"/>
|
||||
</PersistenceManager>
|
||||
</Versioning>
|
||||
|
||||
<Cluster syncDelay="5000">
|
||||
<Journal class="com.itheima.sfbx.rule.console.repository.database.journal.DatabaseJournal">
|
||||
<param name="schemaObjectPrefix" value="journal_"/>
|
||||
</Journal>
|
||||
</Cluster>
|
||||
</Repository>
|
||||
+40
@@ -0,0 +1,40 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE Repository PUBLIC "-//The Apache Software Foundation//DTD Jackrabbit 1.5//EN" "http://jackrabbit.apache.org/dtd/repository-1.5.dtd">
|
||||
<Repository>
|
||||
<FileSystem class="com.itheima.sfbx.rule.console.repository.database.system.DerbyFileSystem">
|
||||
<param name="schemaObjectPrefix" value="repo_"/>
|
||||
</FileSystem>
|
||||
<Security appName="Jackrabbit">
|
||||
<AccessManager class="org.apache.jackrabbit.core.security.simple.SimpleAccessManager"></AccessManager>
|
||||
<LoginModule class="org.apache.jackrabbit.core.security.simple.SimpleLoginModule">
|
||||
<param name="anonymousId" value="anonymous" />
|
||||
<param name="adminId" value="admin" />
|
||||
</LoginModule>
|
||||
</Security>
|
||||
<DataStore class="com.itheima.sfbx.rule.console.repository.database.store.DerbyDataStore">
|
||||
<param name="schemaObjectPrefix" value="repo_ds_"/>
|
||||
</DataStore>
|
||||
<Workspaces rootPath="${rep.home}/workspaces" defaultWorkspace="default" />
|
||||
<Workspace name="default">
|
||||
<FileSystem class="com.itheima.sfbx.rule.console.repository.database.system.DerbyFileSystem">
|
||||
<param name="schemaObjectPrefix" value="repo_${wsp.name}_"/>
|
||||
</FileSystem>
|
||||
<PersistenceManager class="com.itheima.sfbx.rule.console.repository.database.manager.DerbyPersistenceManager">
|
||||
<param name="schemaObjectPrefix" value="repo_pm_${wsp.name}_"/>
|
||||
</PersistenceManager>
|
||||
</Workspace>
|
||||
<Versioning rootPath="${rep.home}/version">
|
||||
<FileSystem class="com.itheima.sfbx.rule.console.repository.database.system.DerbyFileSystem">
|
||||
<param name="schemaObjectPrefix" value="repo_fsver_"/>
|
||||
</FileSystem>
|
||||
<PersistenceManager class="com.itheima.sfbx.rule.console.repository.database.manager.DerbyPersistenceManager">
|
||||
<param name="schemaObjectPrefix" value="repo_ver_"/>
|
||||
</PersistenceManager>
|
||||
</Versioning>
|
||||
|
||||
<Cluster syncDelay="5000">
|
||||
<Journal class="com.itheima.sfbx.rule.console.repository.database.journal.DatabaseJournal">
|
||||
<param name="schemaObjectPrefix" value="journal_"/>
|
||||
</Journal>
|
||||
</Cluster>
|
||||
</Repository>
|
||||
+40
@@ -0,0 +1,40 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE Repository PUBLIC "-//The Apache Software Foundation//DTD Jackrabbit 1.5//EN" "http://jackrabbit.apache.org/dtd/repository-1.5.dtd">
|
||||
<Repository>
|
||||
<FileSystem class="com.itheima.sfbx.rule.console.repository.database.system.MSSqlFileSystem">
|
||||
<param name="schemaObjectPrefix" value="repo_"/>
|
||||
</FileSystem>
|
||||
<Security appName="Jackrabbit">
|
||||
<AccessManager class="org.apache.jackrabbit.core.security.simple.SimpleAccessManager"></AccessManager>
|
||||
<LoginModule class="org.apache.jackrabbit.core.security.simple.SimpleLoginModule">
|
||||
<param name="anonymousId" value="anonymous" />
|
||||
<param name="adminId" value="admin" />
|
||||
</LoginModule>
|
||||
</Security>
|
||||
<DataStore class="com.itheima.sfbx.rule.console.repository.database.DatabaseDataStore">
|
||||
<param name="schemaObjectPrefix" value="repo_ds_"/>
|
||||
</DataStore>
|
||||
<Workspaces rootPath="${rep.home}/workspaces" defaultWorkspace="default" />
|
||||
<Workspace name="default">
|
||||
<FileSystem class="com.itheima.sfbx.rule.console.repository.database.system.MSSqlFileSystem">
|
||||
<param name="schemaObjectPrefix" value="repo_${wsp.name}_"/>
|
||||
</FileSystem>
|
||||
<PersistenceManager class="com.itheima.sfbx.rule.console.repository.database.manager.MSSqlPersistenceManager">
|
||||
<param name="schemaObjectPrefix" value="repo_pm_${wsp.name}_"/>
|
||||
</PersistenceManager>
|
||||
</Workspace>
|
||||
<Versioning rootPath="${rep.home}/version">
|
||||
<FileSystem class="com.itheima.sfbx.rule.console.repository.database.system.MSSqlFileSystem">
|
||||
<param name="schemaObjectPrefix" value="repo_fsver_"/>
|
||||
</FileSystem>
|
||||
<PersistenceManager class="com.itheima.sfbx.rule.console.repository.database.manager.MSSqlPersistenceManager">
|
||||
<param name="schemaObjectPrefix" value="repo_ver_"/>
|
||||
</PersistenceManager>
|
||||
</Versioning>
|
||||
|
||||
<Cluster syncDelay="5000">
|
||||
<Journal class="com.itheima.sfbx.rule.console.repository.database.journal.MSSqlDatabaseJournal">
|
||||
<param name="schemaObjectPrefix" value="journal_"/>
|
||||
</Journal>
|
||||
</Cluster>
|
||||
</Repository>
|
||||
+40
@@ -0,0 +1,40 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE Repository PUBLIC "-//The Apache Software Foundation//DTD Jackrabbit 1.5//EN" "http://jackrabbit.apache.org/dtd/repository-1.5.dtd">
|
||||
<Repository>
|
||||
<FileSystem class="com.itheima.sfbx.rule.console.repository.database.system.MysqlFileSystem">
|
||||
<param name="schemaObjectPrefix" value="repo_"/>
|
||||
</FileSystem>
|
||||
<Security appName="Jackrabbit">
|
||||
<AccessManager class="org.apache.jackrabbit.core.security.simple.SimpleAccessManager"></AccessManager>
|
||||
<LoginModule class="org.apache.jackrabbit.core.security.simple.SimpleLoginModule">
|
||||
<param name="anonymousId" value="anonymous" />
|
||||
<param name="adminId" value="admin" />
|
||||
</LoginModule>
|
||||
</Security>
|
||||
<DataStore class="com.itheima.sfbx.rule.console.repository.database.DatabaseDataStore">
|
||||
<param name="schemaObjectPrefix" value="repo_ds_"/>
|
||||
</DataStore>
|
||||
<Workspaces rootPath="${rep.home}/workspaces" defaultWorkspace="default" />
|
||||
<Workspace name="default">
|
||||
<FileSystem class="com.itheima.sfbx.rule.console.repository.database.system.MysqlFileSystem">
|
||||
<param name="schemaObjectPrefix" value="repo_${wsp.name}_"/>
|
||||
</FileSystem>
|
||||
<PersistenceManager class="com.itheima.sfbx.rule.console.repository.database.manager.MySqlPersistenceManager">
|
||||
<param name="schemaObjectPrefix" value="repo_pm_${wsp.name}_"/>
|
||||
</PersistenceManager>
|
||||
</Workspace>
|
||||
<Versioning rootPath="${rep.home}/version">
|
||||
<FileSystem class="com.itheima.sfbx.rule.console.repository.database.system.MysqlFileSystem">
|
||||
<param name="schemaObjectPrefix" value="repo_fsver_"/>
|
||||
</FileSystem>
|
||||
<PersistenceManager class="com.itheima.sfbx.rule.console.repository.database.manager.MySqlPersistenceManager">
|
||||
<param name="schemaObjectPrefix" value="repo_ver_"/>
|
||||
</PersistenceManager>
|
||||
</Versioning>
|
||||
|
||||
<Cluster syncDelay="5000">
|
||||
<Journal class="com.itheima.sfbx.rule.console.repository.database.journal.DatabaseJournal">
|
||||
<param name="schemaObjectPrefix" value="journal_"/>
|
||||
</Journal>
|
||||
</Cluster>
|
||||
</Repository>
|
||||
+40
@@ -0,0 +1,40 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE Repository PUBLIC "-//The Apache Software Foundation//DTD Jackrabbit 1.5//EN" "http://jackrabbit.apache.org/dtd/repository-1.5.dtd">
|
||||
<Repository>
|
||||
<FileSystem class="com.itheima.sfbx.rule.console.repository.database.system.OracleFileSystem">
|
||||
<param name="schemaObjectPrefix" value="repo_"/>
|
||||
</FileSystem>
|
||||
<Security appName="Jackrabbit">
|
||||
<AccessManager class="org.apache.jackrabbit.core.security.simple.SimpleAccessManager"></AccessManager>
|
||||
<LoginModule class="org.apache.jackrabbit.core.security.simple.SimpleLoginModule">
|
||||
<param name="anonymousId" value="anonymous" />
|
||||
<param name="adminId" value="admin" />
|
||||
</LoginModule>
|
||||
</Security>
|
||||
<DataStore class="com.itheima.sfbx.rule.console.repository.database.DatabaseDataStore">
|
||||
<param name="schemaObjectPrefix" value="repo_ds_"/>
|
||||
</DataStore>
|
||||
<Workspaces rootPath="${rep.home}/workspaces" defaultWorkspace="default" />
|
||||
<Workspace name="default">
|
||||
<FileSystem class="com.itheima.sfbx.rule.console.repository.database.system.OracleFileSystem">
|
||||
<param name="schemaObjectPrefix" value="repo_${wsp.name}_"/>
|
||||
</FileSystem>
|
||||
<PersistenceManager class="com.itheima.sfbx.rule.console.repository.database.manager.OraclePersistenceManager">
|
||||
<param name="schemaObjectPrefix" value="repo_pm_${wsp.name}_"/>
|
||||
</PersistenceManager>
|
||||
</Workspace>
|
||||
<Versioning rootPath="${rep.home}/version">
|
||||
<FileSystem class="com.itheima.sfbx.rule.console.repository.database.system.OracleFileSystem">
|
||||
<param name="schemaObjectPrefix" value="repo_fsver_"/>
|
||||
</FileSystem>
|
||||
<PersistenceManager class="com.itheima.sfbx.rule.console.repository.database.manager.OraclePersistenceManager">
|
||||
<param name="schemaObjectPrefix" value="repo_ver_"/>
|
||||
</PersistenceManager>
|
||||
</Versioning>
|
||||
|
||||
<Cluster syncDelay="5000">
|
||||
<Journal class="com.itheima.sfbx.rule.console.repository.database.journal.OracleDatabaseJournal">
|
||||
<param name="schemaObjectPrefix" value="journal_"/>
|
||||
</Journal>
|
||||
</Cluster>
|
||||
</Repository>
|
||||
+40
@@ -0,0 +1,40 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE Repository PUBLIC "-//The Apache Software Foundation//DTD Jackrabbit 1.5//EN" "http://jackrabbit.apache.org/dtd/repository-1.5.dtd">
|
||||
<Repository>
|
||||
<FileSystem class="com.itheima.sfbx.rule.console.repository.database.system.PostgreSQLFileSystem">
|
||||
<param name="schemaObjectPrefix" value="repo_"/>
|
||||
</FileSystem>
|
||||
<Security appName="Jackrabbit">
|
||||
<AccessManager class="org.apache.jackrabbit.core.security.simple.SimpleAccessManager"></AccessManager>
|
||||
<LoginModule class="org.apache.jackrabbit.core.security.simple.SimpleLoginModule">
|
||||
<param name="anonymousId" value="anonymous" />
|
||||
<param name="adminId" value="admin" />
|
||||
</LoginModule>
|
||||
</Security>
|
||||
<DataStore class="com.itheima.sfbx.rule.console.repository.database.DatabaseDataStore">
|
||||
<param name="schemaObjectPrefix" value="repo_ds_"/>
|
||||
</DataStore>
|
||||
<Workspaces rootPath="${rep.home}/workspaces" defaultWorkspace="default" />
|
||||
<Workspace name="default">
|
||||
<FileSystem class="com.itheima.sfbx.rule.console.repository.database.system.PostgreSQLFileSystem">
|
||||
<param name="schemaObjectPrefix" value="repo_${wsp.name}_"/>
|
||||
</FileSystem>
|
||||
<PersistenceManager class="com.itheima.sfbx.rule.console.repository.database.manager.PostgreSQLPersistenceManager">
|
||||
<param name="schemaObjectPrefix" value="repo_pm_${wsp.name}_"/>
|
||||
</PersistenceManager>
|
||||
</Workspace>
|
||||
<Versioning rootPath="${rep.home}/version">
|
||||
<FileSystem class="com.itheima.sfbx.rule.console.repository.database.system.PostgreSQLFileSystem">
|
||||
<param name="schemaObjectPrefix" value="repo_fsver_"/>
|
||||
</FileSystem>
|
||||
<PersistenceManager class="com.itheima.sfbx.rule.console.repository.database.manager.PostgreSQLPersistenceManager">
|
||||
<param name="schemaObjectPrefix" value="repo_ver_"/>
|
||||
</PersistenceManager>
|
||||
</Versioning>
|
||||
|
||||
<Cluster syncDelay="5000">
|
||||
<Journal class="com.itheima.sfbx.rule.console.repository.database.journal.DatabaseJournal">
|
||||
<param name="schemaObjectPrefix" value="journal_"/>
|
||||
</Journal>
|
||||
</Cluster>
|
||||
</Repository>
|
||||
+808
@@ -0,0 +1,808 @@
|
||||
/*******************************************************************************
|
||||
* Copyright 2017 Bstek
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
||||
* use this file except in compliance with the License. You may obtain a copy
|
||||
* of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations under
|
||||
* the License.
|
||||
******************************************************************************/
|
||||
package com.itheima.sfbx.rule.console.repository.database.journal;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.File;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.Calendar;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.apache.jackrabbit.core.journal.AbstractJournal;
|
||||
import org.apache.jackrabbit.core.journal.AppendRecord;
|
||||
import org.apache.jackrabbit.core.journal.FileRevision;
|
||||
import org.apache.jackrabbit.core.journal.InstanceRevision;
|
||||
import org.apache.jackrabbit.core.journal.JournalException;
|
||||
import org.apache.jackrabbit.core.journal.RecordIterator;
|
||||
import org.apache.jackrabbit.core.util.db.CheckSchemaOperation;
|
||||
import org.apache.jackrabbit.core.util.db.ConnectionFactory;
|
||||
import org.apache.jackrabbit.core.util.db.ConnectionHelper;
|
||||
import org.apache.jackrabbit.core.util.db.DatabaseAware;
|
||||
import org.apache.jackrabbit.core.util.db.DbUtility;
|
||||
import org.apache.jackrabbit.core.util.db.StreamWrapper;
|
||||
import org.apache.jackrabbit.spi.commons.namespace.NamespaceResolver;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.itheima.sfbx.rule.console.repository.RepositoryBuilder;
|
||||
|
||||
/**
|
||||
* @author Jacky.gao
|
||||
* @since 2017年12月7日
|
||||
*/
|
||||
public class DatabaseJournal extends AbstractJournal implements DatabaseAware{
|
||||
|
||||
/**
|
||||
* Default journal table name, used to check schema completeness.
|
||||
*/
|
||||
private static final String DEFAULT_JOURNAL_TABLE = "JOURNAL";
|
||||
|
||||
/**
|
||||
* Local revisions table name, used to check schema completeness.
|
||||
*/
|
||||
private static final String LOCAL_REVISIONS_TABLE = "LOCAL_REVISIONS";
|
||||
|
||||
/**
|
||||
* Logger.
|
||||
*/
|
||||
static Logger log = LoggerFactory.getLogger(DatabaseJournal.class);
|
||||
|
||||
/**
|
||||
* Driver name, bean property.
|
||||
*/
|
||||
private String driver;
|
||||
|
||||
/**
|
||||
* Connection URL, bean property.
|
||||
*/
|
||||
private String url;
|
||||
|
||||
/**
|
||||
* Database type, bean property.
|
||||
*/
|
||||
private String databaseType;
|
||||
|
||||
/**
|
||||
* User name, bean property.
|
||||
*/
|
||||
private String user;
|
||||
|
||||
/**
|
||||
* Password, bean property.
|
||||
*/
|
||||
private String password;
|
||||
|
||||
/**
|
||||
* DataSource logical name, bean property.
|
||||
*/
|
||||
private String dataSourceName;
|
||||
|
||||
/**
|
||||
* The connection helper
|
||||
*/
|
||||
ConnectionHelper conHelper;
|
||||
|
||||
/**
|
||||
* Auto commit level.
|
||||
*/
|
||||
private int lockLevel;
|
||||
|
||||
/**
|
||||
* Locked revision.
|
||||
*/
|
||||
private long lockedRevision;
|
||||
|
||||
/**
|
||||
* Whether the revision table janitor thread is enabled.
|
||||
*/
|
||||
private boolean janitorEnabled = false;
|
||||
|
||||
/**
|
||||
* The sleep time of the revision table janitor in seconds, 1 day default.
|
||||
*/
|
||||
int janitorSleep = 60 * 60 * 24;
|
||||
|
||||
/**
|
||||
* Indicates when the next run of the janitor is scheduled.
|
||||
* The first run is scheduled by default at 03:00 hours.
|
||||
*/
|
||||
Calendar janitorNextRun = Calendar.getInstance();
|
||||
|
||||
{
|
||||
if (janitorNextRun.get(Calendar.HOUR_OF_DAY) >= 3) {
|
||||
janitorNextRun.add(Calendar.DAY_OF_MONTH, 1);
|
||||
}
|
||||
janitorNextRun.set(Calendar.HOUR_OF_DAY, 3);
|
||||
janitorNextRun.set(Calendar.MINUTE, 0);
|
||||
janitorNextRun.set(Calendar.SECOND, 0);
|
||||
janitorNextRun.set(Calendar.MILLISECOND, 0);
|
||||
}
|
||||
|
||||
private Thread janitorThread;
|
||||
|
||||
/**
|
||||
* Whether the schema check must be done during initialization.
|
||||
*/
|
||||
private boolean schemaCheckEnabled = true;
|
||||
|
||||
/**
|
||||
* The instance that manages the local revision.
|
||||
*/
|
||||
private DatabaseRevision databaseRevision;
|
||||
|
||||
/**
|
||||
* SQL statement returning all revisions within a range.
|
||||
*/
|
||||
protected String selectRevisionsStmtSQL;
|
||||
|
||||
/**
|
||||
* SQL statement updating the global revision.
|
||||
*/
|
||||
protected String updateGlobalStmtSQL;
|
||||
|
||||
/**
|
||||
* SQL statement returning the global revision.
|
||||
*/
|
||||
protected String selectGlobalStmtSQL;
|
||||
|
||||
/**
|
||||
* SQL statement appending a new record.
|
||||
*/
|
||||
protected String insertRevisionStmtSQL;
|
||||
|
||||
/**
|
||||
* SQL statement returning the minimum of the local revisions.
|
||||
*/
|
||||
protected String selectMinLocalRevisionStmtSQL;
|
||||
|
||||
/**
|
||||
* SQL statement removing a set of revisions with from the journal table.
|
||||
*/
|
||||
protected String cleanRevisionStmtSQL;
|
||||
|
||||
/**
|
||||
* SQL statement returning the local revision of this cluster node.
|
||||
*/
|
||||
protected String getLocalRevisionStmtSQL;
|
||||
|
||||
/**
|
||||
* SQL statement for inserting the local revision of this cluster node.
|
||||
*/
|
||||
protected String insertLocalRevisionStmtSQL;
|
||||
|
||||
/**
|
||||
* SQL statement for updating the local revision of this cluster node.
|
||||
*/
|
||||
protected String updateLocalRevisionStmtSQL;
|
||||
|
||||
/**
|
||||
* Schema object prefix, bean property.
|
||||
*/
|
||||
protected String schemaObjectPrefix;
|
||||
/*
|
||||
*//**
|
||||
* The repositories {@link ConnectionFactory}.
|
||||
*//*
|
||||
private ConnectionFactory connectionFactory;*/
|
||||
|
||||
public DatabaseJournal() {
|
||||
databaseType = "default";
|
||||
schemaObjectPrefix = "";
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public void setConnectionFactory(ConnectionFactory connnectionFactory) {
|
||||
//this.connectionFactory = connnectionFactory;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public void init(String id, NamespaceResolver resolver)
|
||||
throws JournalException {
|
||||
|
||||
super.init(id, resolver);
|
||||
|
||||
init();
|
||||
|
||||
try {
|
||||
conHelper = createConnectionHelper(getDataSource());
|
||||
|
||||
// make sure schemaObjectPrefix consists of legal name characters only
|
||||
schemaObjectPrefix = conHelper.prepareDbIdentifier(schemaObjectPrefix);
|
||||
|
||||
// check if schema objects exist and create them if necessary
|
||||
if (isSchemaCheckEnabled()) {
|
||||
createCheckSchemaOperation().run();
|
||||
}
|
||||
|
||||
// Make sure that the LOCAL_REVISIONS table exists (see JCR-1087)
|
||||
if (isSchemaCheckEnabled()) {
|
||||
checkLocalRevisionSchema();
|
||||
}
|
||||
|
||||
buildSQLStatements();
|
||||
initInstanceRevisionAndJanitor();
|
||||
} catch (Exception e) {
|
||||
String msg = "Unable to create connection.";
|
||||
throw new JournalException(msg, e);
|
||||
}
|
||||
log.info("DatabaseJournal initialized.");
|
||||
}
|
||||
|
||||
private DataSource getDataSource() throws Exception {
|
||||
/*if (getDataSourceName() == null || "".equals(getDataSourceName())) {
|
||||
return connectionFactory.getDataSource(getDriver(), getUrl(), getUser(), getPassword());
|
||||
} else {
|
||||
return connectionFactory.getDataSource(dataSourceName);
|
||||
}*/
|
||||
return RepositoryBuilder.datasource;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is called from the {@link #init(String, NamespaceResolver)} method of this class and
|
||||
* returns a {@link ConnectionHelper} instance which is assigned to the {@code conHelper} field.
|
||||
* Subclasses may override it to return a specialized connection helper.
|
||||
*
|
||||
* @param dataSrc the {@link DataSource} of this persistence manager
|
||||
* @return a {@link ConnectionHelper}
|
||||
* @throws Exception on error
|
||||
*/
|
||||
protected ConnectionHelper createConnectionHelper(DataSource dataSrc) throws Exception {
|
||||
return new ConnectionHelper(dataSrc, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is called from {@link #init(String, NamespaceResolver)} after the
|
||||
* {@link #createConnectionHelper(DataSource)} method, and returns a default {@link CheckSchemaOperation}.
|
||||
* Subclasses can overrride this implementation to get a customized implementation.
|
||||
*
|
||||
* @return a new {@link CheckSchemaOperation} instance
|
||||
*/
|
||||
protected CheckSchemaOperation createCheckSchemaOperation() {
|
||||
InputStream in = org.apache.jackrabbit.core.journal.DatabaseJournal.class.getResourceAsStream(databaseType + ".ddl");
|
||||
return new CheckSchemaOperation(conHelper, in, schemaObjectPrefix + DEFAULT_JOURNAL_TABLE).addVariableReplacement(
|
||||
CheckSchemaOperation.SCHEMA_OBJECT_PREFIX_VARIABLE, schemaObjectPrefix);
|
||||
}
|
||||
|
||||
/**
|
||||
* Completes initialization of this database journal. Base implementation
|
||||
* checks whether the required bean properties <code>driver</code> and
|
||||
* <code>url</code> have been specified and optionally deduces a valid
|
||||
* database type. Should be overridden by subclasses that use a different way to
|
||||
* create a connection and therefore require other arguments.
|
||||
* @throws JournalException if initialization fails
|
||||
*/
|
||||
protected void init() throws JournalException {
|
||||
databaseType=RepositoryBuilder.databaseType;
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize the instance revision manager and the janitor thread.
|
||||
*
|
||||
* @throws JournalException on error
|
||||
*/
|
||||
protected void initInstanceRevisionAndJanitor() throws Exception {
|
||||
databaseRevision = new DatabaseRevision();
|
||||
|
||||
// Get the local file revision from disk (upgrade; see JCR-1087)
|
||||
long localFileRevision = 0L;
|
||||
if (getRevision() != null) {
|
||||
InstanceRevision currentFileRevision = new FileRevision(new File(getRevision()), true);
|
||||
localFileRevision = currentFileRevision.get();
|
||||
currentFileRevision.close();
|
||||
}
|
||||
|
||||
// Now write the localFileRevision (or 0 if it does not exist) to the LOCAL_REVISIONS
|
||||
// table, but only if the LOCAL_REVISIONS table has no entry yet for this cluster node
|
||||
long localRevision = databaseRevision.init(localFileRevision);
|
||||
log.info("Initialized local revision to " + localRevision);
|
||||
|
||||
// Start the clean-up thread if necessary.
|
||||
if (janitorEnabled) {
|
||||
janitorThread = new Thread(new RevisionTableJanitor(), "Jackrabbit-ClusterRevisionJanitor");
|
||||
janitorThread.setDaemon(true);
|
||||
janitorThread.start();
|
||||
log.info("Cluster revision janitor thread started; first run scheduled at " + janitorNextRun.getTime());
|
||||
} else {
|
||||
log.info("Cluster revision janitor thread not started");
|
||||
}
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.apache.jackrabbit.core.journal.Journal#getInstanceRevision()
|
||||
*/
|
||||
public InstanceRevision getInstanceRevision() throws JournalException {
|
||||
return databaseRevision;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public RecordIterator getRecords(long startRevision) throws JournalException {
|
||||
try {
|
||||
return new DatabaseRecordIterator(conHelper.exec(selectRevisionsStmtSQL, new Object[]{new Long(
|
||||
startRevision)}, false, 0), getResolver(), getNamePathResolver());
|
||||
} catch (SQLException e) {
|
||||
throw new JournalException("Unable to return record iterator.", e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public RecordIterator getRecords() throws JournalException {
|
||||
try {
|
||||
return new DatabaseRecordIterator(conHelper.exec(selectRevisionsStmtSQL, new Object[]{new Long(
|
||||
Long.MIN_VALUE)}, false, 0), getResolver(), getNamePathResolver());
|
||||
} catch (SQLException e) {
|
||||
throw new JournalException("Unable to return record iterator.", e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Synchronize contents from journal. May be overridden by subclasses.
|
||||
* Do the initial sync in batchMode, since some databases (PSQL) when
|
||||
* not in transactional mode, load all results in memory which causes
|
||||
* out of memory. See JCR-2832
|
||||
*
|
||||
* @param startRevision start point (exclusive)
|
||||
* @param startup indicates if the cluster node is syncing on startup
|
||||
* or does a normal sync.
|
||||
* @throws JournalException if an error occurs
|
||||
*/
|
||||
@Override
|
||||
protected void doSync(long startRevision, boolean startup) throws JournalException {
|
||||
if (!startup) {
|
||||
// if the cluster node is not starting do a normal sync
|
||||
doSync(startRevision);
|
||||
} else {
|
||||
try {
|
||||
startBatch();
|
||||
try {
|
||||
doSync(startRevision);
|
||||
} finally {
|
||||
endBatch(true);
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
throw new JournalException("Couldn't sync the cluster node", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* This journal is locked by incrementing the current value in the table
|
||||
* named <code>GLOBAL_REVISION</code>, which effectively write-locks this
|
||||
* table. The updated value is then saved away and remembered in the
|
||||
* appended record, because a save may entail multiple appends (JCR-884).
|
||||
*/
|
||||
protected void doLock() throws JournalException {
|
||||
ResultSet rs = null;
|
||||
boolean succeeded = false;
|
||||
|
||||
try {
|
||||
startBatch();
|
||||
} catch (SQLException e) {
|
||||
throw new JournalException("Unable to set autocommit to false.", e);
|
||||
}
|
||||
|
||||
try {
|
||||
conHelper.exec(updateGlobalStmtSQL);
|
||||
rs = conHelper.exec(selectGlobalStmtSQL, null, false, 0);
|
||||
if (!rs.next()) {
|
||||
throw new JournalException("No revision available.");
|
||||
}
|
||||
lockedRevision = rs.getLong(1);
|
||||
succeeded = true;
|
||||
} catch (SQLException e) {
|
||||
throw new JournalException("Unable to lock global revision table.", e);
|
||||
} finally {
|
||||
DbUtility.close(rs);
|
||||
if (!succeeded) {
|
||||
doUnlock(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
protected void doUnlock(boolean successful) {
|
||||
endBatch(successful);
|
||||
}
|
||||
|
||||
private void startBatch() throws SQLException {
|
||||
if (lockLevel++ == 0) {
|
||||
conHelper.startBatch();
|
||||
}
|
||||
}
|
||||
|
||||
private void endBatch(boolean successful) {
|
||||
if (--lockLevel == 0) {
|
||||
try {
|
||||
conHelper.endBatch(successful);;
|
||||
} catch (SQLException e) {
|
||||
log.error("failed to end batch", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Save away the locked revision inside the newly appended record.
|
||||
*/
|
||||
protected void appending(AppendRecord record) {
|
||||
record.setRevision(lockedRevision);
|
||||
}
|
||||
|
||||
/**
|
||||
* We have already saved away the revision for this record.
|
||||
*/
|
||||
protected void append(AppendRecord record, InputStream in, int length)
|
||||
throws JournalException {
|
||||
|
||||
try {
|
||||
conHelper.exec(insertRevisionStmtSQL, record.getRevision(), getId(), record.getProducerId(),
|
||||
new StreamWrapper(in, length));
|
||||
|
||||
} catch (SQLException e) {
|
||||
String msg = "Unable to append revision " + lockedRevision + ".";
|
||||
throw new JournalException(msg, e);
|
||||
}
|
||||
}
|
||||
|
||||
public void close() {
|
||||
if (janitorThread != null) {
|
||||
janitorThread.interrupt();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the local revision schema objects exist and creates them if they
|
||||
* don't exist yet.
|
||||
*
|
||||
* @throws Exception if an error occurs
|
||||
*/
|
||||
private void checkLocalRevisionSchema() throws Exception {
|
||||
InputStream localRevisionDDLStream = null;
|
||||
InputStream in = org.apache.jackrabbit.core.journal.DatabaseJournal.class.getResourceAsStream(databaseType + ".ddl");
|
||||
try {
|
||||
BufferedReader reader = new BufferedReader(new InputStreamReader(in));
|
||||
String sql = reader.readLine();
|
||||
while (sql != null) {
|
||||
// Skip comments and empty lines, and select only the statement to create the LOCAL_REVISIONS
|
||||
// table.
|
||||
if (!sql.startsWith("#") && sql.length() > 0 && sql.indexOf(LOCAL_REVISIONS_TABLE) != -1) {
|
||||
localRevisionDDLStream = new ByteArrayInputStream(sql.getBytes());
|
||||
break;
|
||||
}
|
||||
// read next sql stmt
|
||||
sql = reader.readLine();
|
||||
}
|
||||
} finally {
|
||||
IOUtils.closeQuietly(in);
|
||||
}
|
||||
// Run the schema check for the single table
|
||||
new CheckSchemaOperation(conHelper, localRevisionDDLStream, schemaObjectPrefix
|
||||
+ LOCAL_REVISIONS_TABLE).addVariableReplacement(
|
||||
CheckSchemaOperation.SCHEMA_OBJECT_PREFIX_VARIABLE, schemaObjectPrefix).run();
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds the SQL statements. May be overridden by subclasses to allow
|
||||
* different table and/or column names.
|
||||
*/
|
||||
protected void buildSQLStatements() {
|
||||
selectRevisionsStmtSQL =
|
||||
"select REVISION_ID, JOURNAL_ID, PRODUCER_ID, REVISION_DATA from "
|
||||
+ schemaObjectPrefix + "JOURNAL where REVISION_ID > ? order by REVISION_ID";
|
||||
updateGlobalStmtSQL =
|
||||
"update " + schemaObjectPrefix + "GLOBAL_REVISION"
|
||||
+ " set REVISION_ID = REVISION_ID + 1";
|
||||
selectGlobalStmtSQL =
|
||||
"select REVISION_ID from "
|
||||
+ schemaObjectPrefix + "GLOBAL_REVISION";
|
||||
insertRevisionStmtSQL =
|
||||
"insert into " + schemaObjectPrefix + "JOURNAL"
|
||||
+ " (REVISION_ID, JOURNAL_ID, PRODUCER_ID, REVISION_DATA) "
|
||||
+ "values (?,?,?,?)";
|
||||
selectMinLocalRevisionStmtSQL =
|
||||
"select MIN(REVISION_ID) from " + schemaObjectPrefix + "LOCAL_REVISIONS";
|
||||
cleanRevisionStmtSQL =
|
||||
"delete from " + schemaObjectPrefix + "JOURNAL " + "where REVISION_ID < ?";
|
||||
getLocalRevisionStmtSQL =
|
||||
"select REVISION_ID from " + schemaObjectPrefix + "LOCAL_REVISIONS "
|
||||
+ "where JOURNAL_ID = ?";
|
||||
insertLocalRevisionStmtSQL =
|
||||
"insert into " + schemaObjectPrefix + "LOCAL_REVISIONS "
|
||||
+ "(REVISION_ID, JOURNAL_ID) values (?,?)";
|
||||
updateLocalRevisionStmtSQL =
|
||||
"update " + schemaObjectPrefix + "LOCAL_REVISIONS "
|
||||
+ "set REVISION_ID = ? where JOURNAL_ID = ?";
|
||||
}
|
||||
|
||||
public String getDriver() {
|
||||
return driver;
|
||||
}
|
||||
|
||||
public String getUrl() {
|
||||
return url;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the database type.
|
||||
*
|
||||
* @return the database type
|
||||
*/
|
||||
public String getDatabaseType() {
|
||||
return databaseType;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the database type.
|
||||
* @deprecated
|
||||
* This method is deprecated; {@link #getDatabaseType} should be used instead.
|
||||
*
|
||||
* @return the database type
|
||||
*/
|
||||
public String getSchema() {
|
||||
return databaseType;
|
||||
}
|
||||
|
||||
public String getSchemaObjectPrefix() {
|
||||
return schemaObjectPrefix;
|
||||
}
|
||||
|
||||
public String getUser() {
|
||||
return user;
|
||||
}
|
||||
|
||||
public String getPassword() {
|
||||
return password;
|
||||
}
|
||||
|
||||
public boolean getJanitorEnabled() {
|
||||
return janitorEnabled;
|
||||
}
|
||||
|
||||
public int getJanitorSleep() {
|
||||
return janitorSleep;
|
||||
}
|
||||
|
||||
public int getJanitorFirstRunHourOfDay() {
|
||||
return janitorNextRun.get(Calendar.HOUR_OF_DAY);
|
||||
}
|
||||
|
||||
public void setDriver(String driver) {
|
||||
this.driver = driver;
|
||||
}
|
||||
|
||||
public void setUrl(String url) {
|
||||
this.url = url;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the database type.
|
||||
*
|
||||
* @param databaseType the database type
|
||||
*/
|
||||
public void setDatabaseType(String databaseType) {
|
||||
this.databaseType = databaseType;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the database type.
|
||||
* @deprecated
|
||||
* This method is deprecated; {@link #getDatabaseType} should be used instead.
|
||||
*
|
||||
* @param databaseType the database type
|
||||
*/
|
||||
public void setSchema(String databaseType) {
|
||||
this.databaseType = databaseType;
|
||||
}
|
||||
|
||||
public void setSchemaObjectPrefix(String schemaObjectPrefix) {
|
||||
this.schemaObjectPrefix = schemaObjectPrefix.toUpperCase();
|
||||
}
|
||||
|
||||
public void setUser(String user) {
|
||||
this.user = user;
|
||||
}
|
||||
|
||||
public void setPassword(String password) {
|
||||
this.password = password;
|
||||
}
|
||||
|
||||
public void setJanitorEnabled(boolean enabled) {
|
||||
this.janitorEnabled = enabled;
|
||||
}
|
||||
|
||||
public void setJanitorSleep(int sleep) {
|
||||
this.janitorSleep = sleep;
|
||||
}
|
||||
|
||||
public void setJanitorFirstRunHourOfDay(int hourOfDay) {
|
||||
janitorNextRun = Calendar.getInstance();
|
||||
if (janitorNextRun.get(Calendar.HOUR_OF_DAY) >= hourOfDay) {
|
||||
janitorNextRun.add(Calendar.DAY_OF_MONTH, 1);
|
||||
}
|
||||
janitorNextRun.set(Calendar.HOUR_OF_DAY, hourOfDay);
|
||||
janitorNextRun.set(Calendar.MINUTE, 0);
|
||||
janitorNextRun.set(Calendar.SECOND, 0);
|
||||
janitorNextRun.set(Calendar.MILLISECOND, 0);
|
||||
}
|
||||
|
||||
public String getDataSourceName() {
|
||||
return dataSourceName;
|
||||
}
|
||||
|
||||
public void setDataSourceName(String dataSourceName) {
|
||||
this.dataSourceName = dataSourceName;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return whether the schema check is enabled
|
||||
*/
|
||||
public final boolean isSchemaCheckEnabled() {
|
||||
return schemaCheckEnabled;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param enabled set whether the schema check is enabled
|
||||
*/
|
||||
public final void setSchemaCheckEnabled(boolean enabled) {
|
||||
schemaCheckEnabled = enabled;
|
||||
}
|
||||
|
||||
/**
|
||||
* This class manages the local revision of the cluster node. It
|
||||
* persists the local revision in the LOCAL_REVISIONS table in the
|
||||
* clustering database.
|
||||
*/
|
||||
public class DatabaseRevision implements InstanceRevision {
|
||||
|
||||
/**
|
||||
* The cached local revision of this cluster node.
|
||||
*/
|
||||
private long localRevision;
|
||||
|
||||
/**
|
||||
* Indicates whether the init method has been called.
|
||||
*/
|
||||
private boolean initialized = false;
|
||||
|
||||
/**
|
||||
* Checks whether there's a local revision value in the database for this
|
||||
* cluster node. If not, it writes the given default revision to the database.
|
||||
*
|
||||
* @param revision the default value for the local revision counter
|
||||
* @return the local revision
|
||||
* @throws JournalException on error
|
||||
*/
|
||||
protected synchronized long init(long revision) throws JournalException {
|
||||
ResultSet rs = null;
|
||||
try {
|
||||
// Check whether there is an entry in the database.
|
||||
rs = conHelper.exec(getLocalRevisionStmtSQL, new Object[]{getId()}, false, 0);
|
||||
boolean exists = rs.next();
|
||||
if (exists) {
|
||||
revision = rs.getLong(1);
|
||||
}
|
||||
|
||||
// Insert the given revision in the database
|
||||
if (!exists) {
|
||||
conHelper.exec(insertLocalRevisionStmtSQL, revision, getId());
|
||||
}
|
||||
|
||||
// Set the cached local revision and return
|
||||
localRevision = revision;
|
||||
initialized = true;
|
||||
return revision;
|
||||
|
||||
} catch (SQLException e) {
|
||||
log.warn("Failed to initialize local revision.", e);
|
||||
throw new JournalException("Failed to initialize local revision", e);
|
||||
} finally {
|
||||
DbUtility.close(rs);
|
||||
}
|
||||
}
|
||||
|
||||
public synchronized long get() {
|
||||
if (!initialized) {
|
||||
throw new IllegalStateException("instance has not yet been initialized");
|
||||
}
|
||||
return localRevision;
|
||||
}
|
||||
|
||||
public synchronized void set(long localRevision) throws JournalException {
|
||||
|
||||
if (!initialized) {
|
||||
throw new IllegalStateException("instance has not yet been initialized");
|
||||
}
|
||||
|
||||
// Update the cached value and the table with local revisions.
|
||||
try {
|
||||
conHelper.exec(updateLocalRevisionStmtSQL, localRevision, getId());
|
||||
this.localRevision = localRevision;
|
||||
} catch (SQLException e) {
|
||||
log.warn("Failed to update local revision.", e);
|
||||
throw new JournalException("Failed to update local revision.", e);
|
||||
}
|
||||
}
|
||||
|
||||
public void close() {
|
||||
// nothing to do
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Class for maintaining the revision table. This is only useful if all
|
||||
* JR information except the search index is in the database (i.e., node types
|
||||
* etc). In that case, revision data can safely be thrown away from the JOURNAL table.
|
||||
*/
|
||||
public class RevisionTableJanitor implements Runnable {
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public void run() {
|
||||
while (!Thread.currentThread().isInterrupted()) {
|
||||
try {
|
||||
log.info("Next clean-up run scheduled at " + janitorNextRun.getTime());
|
||||
long sleepTime = janitorNextRun.getTimeInMillis() - System.currentTimeMillis();
|
||||
if (sleepTime > 0) {
|
||||
Thread.sleep(sleepTime);
|
||||
}
|
||||
cleanUpOldRevisions();
|
||||
janitorNextRun.add(Calendar.SECOND, janitorSleep);
|
||||
} catch (InterruptedException e) {
|
||||
Thread.currentThread().interrupt();
|
||||
}
|
||||
}
|
||||
log.info("Interrupted: stopping clean-up task.");
|
||||
}
|
||||
|
||||
/**
|
||||
* Cleans old revisions from the clustering table.
|
||||
*/
|
||||
protected void cleanUpOldRevisions() {
|
||||
ResultSet rs = null;
|
||||
try {
|
||||
long minRevision = 0;
|
||||
rs = conHelper.exec(selectMinLocalRevisionStmtSQL, null, false, 0);
|
||||
boolean cleanUp = rs.next();
|
||||
if (cleanUp) {
|
||||
minRevision = rs.getLong(1);
|
||||
}
|
||||
|
||||
// Clean up if necessary:
|
||||
if (cleanUp) {
|
||||
conHelper.exec(cleanRevisionStmtSQL, minRevision);
|
||||
log.info("Cleaned old revisions up to revision " + minRevision + ".");
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
log.warn("Failed to clean up old revisions.", e);
|
||||
} finally {
|
||||
DbUtility.close(rs);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+156
@@ -0,0 +1,156 @@
|
||||
/*******************************************************************************
|
||||
* Copyright 2017 Bstek
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
||||
* use this file except in compliance with the License. You may obtain a copy
|
||||
* of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations under
|
||||
* the License.
|
||||
******************************************************************************/
|
||||
package com.itheima.sfbx.rule.console.repository.database.journal;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.IOException;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.NoSuchElementException;
|
||||
|
||||
import org.apache.jackrabbit.core.journal.JournalException;
|
||||
import org.apache.jackrabbit.core.journal.ReadRecord;
|
||||
import org.apache.jackrabbit.core.journal.Record;
|
||||
import org.apache.jackrabbit.core.journal.RecordIterator;
|
||||
import org.apache.jackrabbit.spi.commons.conversion.NamePathResolver;
|
||||
import org.apache.jackrabbit.spi.commons.namespace.NamespaceResolver;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* @author Jacky.gao
|
||||
* @since 2017年12月7日
|
||||
*/
|
||||
public class DatabaseRecordIterator implements RecordIterator {
|
||||
|
||||
/**
|
||||
* Logger.
|
||||
*/
|
||||
private static Logger log = LoggerFactory.getLogger(DatabaseRecordIterator.class);
|
||||
|
||||
/**
|
||||
* Underlying result set.
|
||||
*/
|
||||
private final ResultSet rs;
|
||||
|
||||
/**
|
||||
* Namespace resolver.
|
||||
*/
|
||||
private final NamespaceResolver resolver;
|
||||
|
||||
/**
|
||||
* Name and Path resolver.
|
||||
*/
|
||||
private final NamePathResolver npResolver;
|
||||
|
||||
/**
|
||||
* Current record.
|
||||
*/
|
||||
private ReadRecord record;
|
||||
|
||||
/**
|
||||
* Last record returned.
|
||||
*/
|
||||
private ReadRecord lastRecord;
|
||||
|
||||
/**
|
||||
* Flag indicating whether EOF was reached.
|
||||
*/
|
||||
private boolean isEOF;
|
||||
public DatabaseRecordIterator(ResultSet rs, NamespaceResolver resolver, NamePathResolver npResolver) {
|
||||
this.rs = rs;
|
||||
this.resolver = resolver;
|
||||
this.npResolver = npResolver;
|
||||
}
|
||||
public boolean hasNext() {
|
||||
try {
|
||||
if (!isEOF && record == null) {
|
||||
fetchRecord();
|
||||
}
|
||||
return !isEOF;
|
||||
} catch (SQLException e) {
|
||||
String msg = "Error while moving to next record.";
|
||||
log.error(msg, e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the next record. If there are no more records, throws
|
||||
* a <code>NoSuchElementException</code>. If an error occurs,
|
||||
* throws a <code>JournalException</code>.
|
||||
*
|
||||
* @return next record
|
||||
* @throws NoSuchElementException if there are no more records
|
||||
* @throws JournalException if another error occurs
|
||||
*/
|
||||
public Record nextRecord() throws NoSuchElementException, JournalException {
|
||||
if (!hasNext()) {
|
||||
String msg = "No current record.";
|
||||
throw new NoSuchElementException(msg);
|
||||
}
|
||||
close(lastRecord);
|
||||
lastRecord = record;
|
||||
record = null;
|
||||
|
||||
return lastRecord;
|
||||
}
|
||||
|
||||
public void close() {
|
||||
if (lastRecord != null) {
|
||||
close(lastRecord);
|
||||
lastRecord = null;
|
||||
}
|
||||
try {
|
||||
rs.close();
|
||||
} catch (SQLException e) {
|
||||
String msg = "Error while closing result set: " + e.getMessage();
|
||||
log.warn(msg);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch the next record.
|
||||
*/
|
||||
private void fetchRecord() throws SQLException {
|
||||
if (rs.next()) {
|
||||
long revision = rs.getLong(1);
|
||||
String journalId = rs.getString(2);
|
||||
String producerId = rs.getString(3);
|
||||
DataInputStream dataIn = new DataInputStream(rs.getBinaryStream(4));
|
||||
record = new ReadRecord(journalId, producerId, revision, dataIn, 0, resolver, npResolver);
|
||||
} else {
|
||||
isEOF = true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Close a record.
|
||||
*
|
||||
* @param record record
|
||||
*/
|
||||
private static void close(ReadRecord record) {
|
||||
if (record != null) {
|
||||
try {
|
||||
record.close();
|
||||
} catch (IOException e) {
|
||||
String msg = "Error while closing record.";
|
||||
log.warn(msg, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
+66
@@ -0,0 +1,66 @@
|
||||
/*******************************************************************************
|
||||
* Copyright 2017 Bstek
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
||||
* use this file except in compliance with the License. You may obtain a copy
|
||||
* of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations under
|
||||
* the License.
|
||||
******************************************************************************/
|
||||
package com.itheima.sfbx.rule.console.repository.database.journal;
|
||||
|
||||
import org.apache.jackrabbit.core.util.db.CheckSchemaOperation;
|
||||
|
||||
/**
|
||||
* @author Jacky.gao
|
||||
* @since 2017年12月7日
|
||||
*/
|
||||
public class MSSqlDatabaseJournal extends DatabaseJournal {
|
||||
|
||||
/** the MS SQL table space to use */
|
||||
protected String tableSpace = "";
|
||||
|
||||
/**
|
||||
* Initialize this instance with the default schema and
|
||||
* driver values.
|
||||
*/
|
||||
public MSSqlDatabaseJournal() {
|
||||
setDriver("com.microsoft.sqlserver.jdbc.SQLServerDriver");
|
||||
setDatabaseType("mssql");
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
protected CheckSchemaOperation createCheckSchemaOperation() {
|
||||
return super.createCheckSchemaOperation().addVariableReplacement(
|
||||
CheckSchemaOperation.TABLE_SPACE_VARIABLE, tableSpace);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the configured MS SQL table space.
|
||||
* @return the configured MS SQL table space.
|
||||
*/
|
||||
public String getTableSpace() {
|
||||
return tableSpace;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the MS SQL table space.
|
||||
* @param tableSpace the MS SQL table space.
|
||||
*/
|
||||
public void setTableSpace(String tableSpace) {
|
||||
if (tableSpace != null && tableSpace.length() > 0) {
|
||||
this.tableSpace = "on " + tableSpace.trim();
|
||||
} else {
|
||||
this.tableSpace = "";
|
||||
}
|
||||
}
|
||||
}
|
||||
+131
@@ -0,0 +1,131 @@
|
||||
/*******************************************************************************
|
||||
* Copyright 2017 Bstek
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
||||
* use this file except in compliance with the License. You may obtain a copy
|
||||
* of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations under
|
||||
* the License.
|
||||
******************************************************************************/
|
||||
package com.itheima.sfbx.rule.console.repository.database.journal;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
|
||||
import org.apache.jackrabbit.core.util.db.CheckSchemaOperation;
|
||||
import org.apache.jackrabbit.core.util.db.ConnectionHelper;
|
||||
import org.apache.jackrabbit.core.util.db.OracleConnectionHelper;
|
||||
|
||||
/**
|
||||
* @author Jacky.gao
|
||||
* @since 2017年12月7日
|
||||
*/
|
||||
public class OracleDatabaseJournal extends DatabaseJournal {
|
||||
/**
|
||||
* The default tablespace clause used when {@link #tablespace} or {@link #indexTablespace}
|
||||
* are not specified.
|
||||
*/
|
||||
protected static final String DEFAULT_TABLESPACE_CLAUSE = "";
|
||||
|
||||
/**
|
||||
* Name of the replacement variable in the DDL for {@link #tablespace}.
|
||||
*/
|
||||
protected static final String TABLESPACE_VARIABLE = "${tablespace}";
|
||||
|
||||
/**
|
||||
* Name of the replacement variable in the DDL for {@link #indexTablespace}.
|
||||
*/
|
||||
protected static final String INDEX_TABLESPACE_VARIABLE = "${indexTablespace}";
|
||||
|
||||
/** The Oracle tablespace to use for tables */
|
||||
protected String tablespace;
|
||||
|
||||
/** The Oracle tablespace to use for indexes */
|
||||
protected String indexTablespace;
|
||||
|
||||
public OracleDatabaseJournal() {
|
||||
setDatabaseType("oracle");
|
||||
setDriver("oracle.jdbc.OracleDriver");
|
||||
setSchemaObjectPrefix("");
|
||||
tablespace = DEFAULT_TABLESPACE_CLAUSE;
|
||||
indexTablespace = DEFAULT_TABLESPACE_CLAUSE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the configured Oracle tablespace for tables.
|
||||
* @return the configured Oracle tablespace for tables.
|
||||
*/
|
||||
public String getTablespace() {
|
||||
return tablespace;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the Oracle tablespace for tables.
|
||||
* @param tablespaceName the Oracle tablespace for tables.
|
||||
*/
|
||||
public void setTablespace(String tablespaceName) {
|
||||
this.tablespace = this.buildTablespaceClause(tablespaceName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the configured Oracle tablespace for indexes.
|
||||
* @return the configured Oracle tablespace for indexes.
|
||||
*/
|
||||
public String getIndexTablespace() {
|
||||
return indexTablespace;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the Oracle tablespace for indexes.
|
||||
* @param tablespaceName the Oracle tablespace for indexes.
|
||||
*/
|
||||
public void setIndexTablespace(String tablespaceName) {
|
||||
this.indexTablespace = this.buildTablespaceClause(tablespaceName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs the <code>tablespace <tbs name></code> clause from
|
||||
* the supplied tablespace name. If the name is empty, {@link #DEFAULT_TABLESPACE_CLAUSE}
|
||||
* is returned instead.
|
||||
*
|
||||
* @param tablespaceName A tablespace name
|
||||
* @return A tablespace clause using the supplied name or
|
||||
* <code>{@value #DEFAULT_TABLESPACE_CLAUSE}</code> if the name is empty
|
||||
*/
|
||||
private String buildTablespaceClause(String tablespaceName) {
|
||||
if (tablespaceName == null || tablespaceName.trim().length() == 0) {
|
||||
return DEFAULT_TABLESPACE_CLAUSE;
|
||||
} else {
|
||||
return "tablespace " + tablespaceName.trim();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
protected ConnectionHelper createConnectionHelper(DataSource dataSrc) throws Exception {
|
||||
OracleConnectionHelper helper = new OracleConnectionHelper(dataSrc, false);
|
||||
helper.init();
|
||||
return helper;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
protected CheckSchemaOperation createCheckSchemaOperation() {
|
||||
if (DEFAULT_TABLESPACE_CLAUSE.equals(indexTablespace) && !DEFAULT_TABLESPACE_CLAUSE.equals(tablespace)) {
|
||||
// tablespace was set but not indexTablespace : use the same for both
|
||||
indexTablespace = tablespace;
|
||||
}
|
||||
return super.createCheckSchemaOperation()
|
||||
.addVariableReplacement(TABLESPACE_VARIABLE, tablespace)
|
||||
.addVariableReplacement(INDEX_TABLESPACE_VARIABLE, indexTablespace);
|
||||
}
|
||||
}
|
||||
+277
@@ -0,0 +1,277 @@
|
||||
/*******************************************************************************
|
||||
* Copyright 2017 Bstek
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
||||
* use this file except in compliance with the License. You may obtain a copy
|
||||
* of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations under
|
||||
* the License.
|
||||
******************************************************************************/
|
||||
package com.itheima.sfbx.rule.console.repository.database.manager;
|
||||
|
||||
import java.sql.SQLException;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
|
||||
import org.apache.jackrabbit.core.persistence.PMContext;
|
||||
import org.apache.jackrabbit.core.persistence.pool.BundleDbPersistenceManager;
|
||||
import org.apache.jackrabbit.core.util.db.ConnectionHelper;
|
||||
import org.apache.jackrabbit.core.util.db.DerbyConnectionHelper;
|
||||
|
||||
import com.itheima.sfbx.rule.console.repository.database.DbPersistenceManager;
|
||||
|
||||
/**
|
||||
* @author Jacky.gao
|
||||
* @since 2017年12月7日
|
||||
*/
|
||||
public class DerbyPersistenceManager extends DbPersistenceManager {
|
||||
|
||||
/** name of the embedded driver */
|
||||
public static final String DERBY_EMBEDDED_DRIVER = "org.apache.derby.jdbc.EmbeddedDriver";
|
||||
|
||||
/** @see #setDerbyStorageInitialPages(String) */
|
||||
private int derbyStorageInitialPages = 16;
|
||||
|
||||
/** @see #setDerbyStorageMinimumRecordSize(String) */
|
||||
private int derbyStorageMinimumRecordSize = 512;
|
||||
|
||||
/** @see #setDerbyStoragePageCacheSize(String) */
|
||||
private int derbyStoragePageCacheSize = 1024;
|
||||
|
||||
/** @see #setDerbyStoragePageReservedSpace(String) */
|
||||
private int derbyStoragePageReservedSpace = 20;
|
||||
|
||||
/** @see #setDerbyStoragePageSize(String) */
|
||||
private int derbyStoragePageSize = 16384;
|
||||
|
||||
/**
|
||||
* @see #setDerbyStorageInitialPages
|
||||
* @return the initial pages property
|
||||
*/
|
||||
public String getDerbyStorageInitialPages() {
|
||||
return String.valueOf(derbyStorageInitialPages);
|
||||
}
|
||||
|
||||
/**
|
||||
* The on-disk size of a Derby table grows by one page at a time until eight
|
||||
* pages of user data (or nine pages of total disk use, one is used for
|
||||
* overhead) have been allocated. Then it will grow by eight pages at a time
|
||||
* if possible.
|
||||
* <p>
|
||||
* A Derby table or index can be created with a number of pages already
|
||||
* pre-allocated. To do so, specify the property prior to the CREATE TABLE
|
||||
* or CREATE INDEX statement.
|
||||
* <p>
|
||||
* Define the number of user pages the table or index is to be created with.
|
||||
* The purpose of this property is to preallocate a table or index of
|
||||
* reasonable size if the user expects that a large amount of data will be
|
||||
* inserted into the table or index. A table or index that has the
|
||||
* pre-allocated pages will enjoy a small performance improvement over a
|
||||
* table or index that has no pre-allocated pages when the data are loaded.
|
||||
* <p>
|
||||
* The total desired size of the table or index should be
|
||||
* <p>
|
||||
* <strong>(1+derby.storage.initialPages) * derby.storage.pageSize bytes.</strong>
|
||||
* <p>
|
||||
* When you create a table or an index after setting this property, Derby
|
||||
* attempts to preallocate the requested number of user pages. However, the
|
||||
* operations do not fail even if they are unable to preallocate the
|
||||
* requested number of pages, as long as they allocate at least one page.
|
||||
* <p>
|
||||
* Default is <code>16</code>
|
||||
*
|
||||
* @param derbyStorageInitialPages the number of initial pages
|
||||
*/
|
||||
public void setDerbyStorageInitialPages(String derbyStorageInitialPages) {
|
||||
this.derbyStorageInitialPages =
|
||||
Integer.decode(derbyStorageInitialPages).intValue();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see #setDerbyStorageMinimumRecordSize
|
||||
* @return the minimum record size
|
||||
*/
|
||||
public String getDerbyStorageMinimumRecordSize() {
|
||||
return String.valueOf(derbyStorageMinimumRecordSize);
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicates the minimum user row size in bytes for on-disk database pages
|
||||
* for tables when you are creating a table. This property ensures that
|
||||
* there is enough room for a row to grow on a page when updated without
|
||||
* having to overflow. This is generally most useful for VARCHAR and
|
||||
* VARCHAR FOR BIT DATA data types and for tables that are updated a lot,
|
||||
* in which the rows start small and grow due to updates. Reserving the
|
||||
* space at the time of insertion minimizes row overflow due to updates,
|
||||
* but it can result in wasted space. Set the property prior to issuing the
|
||||
* CREATE TABLE statement.
|
||||
* <p>
|
||||
* Default is <code>256</code>
|
||||
*
|
||||
* @param derbyStorageMinimumRecordSize the minimum record size
|
||||
*/
|
||||
public void setDerbyStorageMinimumRecordSize(String derbyStorageMinimumRecordSize) {
|
||||
this.derbyStorageMinimumRecordSize =
|
||||
Integer.decode(derbyStorageMinimumRecordSize).intValue();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see #setDerbyStoragePageCacheSize
|
||||
* @return the page cache size
|
||||
*/
|
||||
public String getDerbyStoragePageCacheSize() {
|
||||
return String.valueOf(derbyStoragePageCacheSize);
|
||||
}
|
||||
|
||||
/**
|
||||
* Defines the size, in number of pages, of the database's data page cache
|
||||
* (data pages kept in memory). The actual amount of memory the page cache
|
||||
* will use depends on the following:
|
||||
* <ul>
|
||||
* <li> the size of the cache (configured with {@link #setDerbyStoragePageCacheSize})
|
||||
* <li> the size of the pages (configured with {@link #setDerbyStoragePageSize})
|
||||
* <li> overhead (varies with JVMs)
|
||||
* </ul>
|
||||
* When increasing the size of the page cache, you typically have to allow
|
||||
* more memory for the Java heap when starting the embedding application
|
||||
* (taking into consideration, of course, the memory needs of the embedding
|
||||
* application as well). For example, using the default page size of 4K, a
|
||||
* page cache size of 2000 pages will require at least 8 MB of memory (and
|
||||
* probably more, given the overhead).
|
||||
* <p>
|
||||
* The minimum value is 40 pages. If you specify a lower value, Derby uses
|
||||
* the default value.
|
||||
* <p>
|
||||
* Default is <code>1024</code> (which gives about 16mb memory usage given
|
||||
* the default of 16384 as page size).
|
||||
*
|
||||
* @param derbyStoragePageCacheSize the page cache size
|
||||
*/
|
||||
public void setDerbyStoragePageCacheSize(String derbyStoragePageCacheSize) {
|
||||
this.derbyStoragePageCacheSize =
|
||||
Integer.decode(derbyStoragePageCacheSize).intValue();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @see #setDerbyStoragePageReservedSpace
|
||||
* @return the page reserved space
|
||||
*/
|
||||
public String getDerbyStoragePageReservedSpace() {
|
||||
return String.valueOf(derbyStoragePageReservedSpace);
|
||||
}
|
||||
|
||||
/**
|
||||
* Defines the percentage of space reserved for updates on an on-disk
|
||||
* database page for tables only (not indexes); indicates the percentage of
|
||||
* space to keep free on a page when inserting. Leaving reserved space on a
|
||||
* page can minimize row overflow (and the associated performance hit)
|
||||
* during updates. Once a page has been filled up to the reserved-space
|
||||
* threshold, no new rows are allowed on the page. This reserved space is
|
||||
* used only for rows that increase in size when updated, not for new
|
||||
* inserts. Set this property prior to issuing the CREATE TABLE statement.
|
||||
* <p>
|
||||
* Regardless of the value of derby.storage.pageReservedSpace, an empty page
|
||||
* always accepts at least one row.
|
||||
* <p>
|
||||
* Default is <code>20%</code>
|
||||
*
|
||||
* @param derbyStoragePageReservedSpace the page reserved space
|
||||
*/
|
||||
public void setDerbyStoragePageReservedSpace(String derbyStoragePageReservedSpace) {
|
||||
this.derbyStoragePageReservedSpace =
|
||||
Integer.decode(derbyStoragePageReservedSpace).intValue();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see #setDerbyStoragePageSize
|
||||
* @return the page size
|
||||
*/
|
||||
public String getDerbyStoragePageSize() {
|
||||
return String.valueOf(derbyStoragePageSize);
|
||||
}
|
||||
|
||||
/**
|
||||
* Defines the page size, in bytes, for on-disk database pages for tables or
|
||||
* indexes used during table or index creation. Page size can only be one
|
||||
* the following values: 4096, 8192, 16384, or 32768. Set this property
|
||||
* prior to issuing the CREATE TABLE or CREATE INDEX statement. This value
|
||||
* will be used for the lifetime of the newly created conglomerates.
|
||||
* <p>
|
||||
* Default is <code>16384</code>
|
||||
*
|
||||
* @param derbyStoragePageSize the storage page size
|
||||
*/
|
||||
public void setDerbyStoragePageSize(String derbyStoragePageSize) {
|
||||
this.derbyStoragePageSize = Integer.decode(derbyStoragePageSize).intValue();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public void init(PMContext context) throws Exception {
|
||||
// init default values
|
||||
if (getDriver() == null) {
|
||||
setDriver(DERBY_EMBEDDED_DRIVER);
|
||||
}
|
||||
if (getDatabaseType() == null) {
|
||||
setDatabaseType("derby");
|
||||
}
|
||||
if (getUrl() == null) {
|
||||
setUrl("jdbc:derby:" + context.getHomeDir().getPath() + "/db/itemState;create=true");
|
||||
}
|
||||
if (getSchemaObjectPrefix() == null) {
|
||||
setSchemaObjectPrefix("");
|
||||
}
|
||||
super.init(context);
|
||||
// set properties
|
||||
if (DERBY_EMBEDDED_DRIVER.equals(getDriver())) {
|
||||
conHelper.exec("CALL SYSCS_UTIL.SYSCS_SET_DATABASE_PROPERTY "
|
||||
+ "('derby.storage.initialPages', '" + derbyStorageInitialPages + "')");
|
||||
conHelper.exec("CALL SYSCS_UTIL.SYSCS_SET_DATABASE_PROPERTY "
|
||||
+ "('derby.storage.minimumRecordSize', '" + derbyStorageMinimumRecordSize + "')");
|
||||
conHelper.exec("CALL SYSCS_UTIL.SYSCS_SET_DATABASE_PROPERTY "
|
||||
+ "('derby.storage.pageCacheSize', '" + derbyStoragePageCacheSize + "')");
|
||||
conHelper.exec("CALL SYSCS_UTIL.SYSCS_SET_DATABASE_PROPERTY "
|
||||
+ "('derby.storage.pageReservedSpace', '" + derbyStoragePageReservedSpace + "')");
|
||||
conHelper.exec("CALL SYSCS_UTIL.SYSCS_SET_DATABASE_PROPERTY " + "('derby.storage.pageSize', '"
|
||||
+ derbyStoragePageSize + "')");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
protected ConnectionHelper createConnectionHelper(DataSource dataSrc) {
|
||||
return new DerbyConnectionHelper(dataSrc, blockOnConnectionLoss);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* Since Derby cannot handle binary indexes, we use long-long keys.
|
||||
*
|
||||
* @return {@link BundleDbPersistenceManager#SM_LONGLONG_KEYS}
|
||||
*/
|
||||
public int getStorageModel() {
|
||||
return BundleDbPersistenceManager.SM_LONGLONG_KEYS;
|
||||
}
|
||||
|
||||
/**
|
||||
* Closes the given connection by shutting down the embedded Derby
|
||||
* database.
|
||||
*
|
||||
* @throws SQLException if an error occurs
|
||||
*/
|
||||
public void close() throws Exception {
|
||||
super.close();
|
||||
((DerbyConnectionHelper) conHelper).shutDown(getDriver());
|
||||
}
|
||||
}
|
||||
+69
@@ -0,0 +1,69 @@
|
||||
/*******************************************************************************
|
||||
* Copyright 2017 Bstek
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
||||
* use this file except in compliance with the License. You may obtain a copy
|
||||
* of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations under
|
||||
* the License.
|
||||
******************************************************************************/
|
||||
package com.itheima.sfbx.rule.console.repository.database.manager;
|
||||
|
||||
import org.apache.jackrabbit.core.persistence.PMContext;
|
||||
|
||||
import com.itheima.sfbx.rule.console.repository.database.DbPersistenceManager;
|
||||
|
||||
/**
|
||||
* @author Jacky.gao
|
||||
* @since 2017年12月7日
|
||||
*/
|
||||
public class H2PersistenceManager extends DbPersistenceManager {
|
||||
|
||||
/** the lock time out. see*/
|
||||
private long lockTimeout = 10000;
|
||||
|
||||
/**
|
||||
* Returns the lock timeout.
|
||||
* @return the lock timeout
|
||||
*/
|
||||
public String getLockTimeout() {
|
||||
return String.valueOf(lockTimeout);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the lock timeout in milliseconds.
|
||||
* @param lockTimeout the lock timeout.
|
||||
*/
|
||||
public void setLockTimeout(String lockTimeout) {
|
||||
this.lockTimeout = Long.parseLong(lockTimeout);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public void init(PMContext context) throws Exception {
|
||||
// init default values
|
||||
if (getDriver() == null) {
|
||||
setDriver("org.h2.Driver");
|
||||
}
|
||||
if (getUrl() == null) {
|
||||
setUrl("jdbc:h2:file:" + context.getHomeDir().getPath() + "/db/itemState");
|
||||
}
|
||||
if (getDatabaseType() == null) {
|
||||
setDatabaseType("h2");
|
||||
}
|
||||
if (getSchemaObjectPrefix() == null) {
|
||||
setSchemaObjectPrefix("");
|
||||
}
|
||||
|
||||
super.init(context);
|
||||
|
||||
conHelper.exec("SET LOCK_TIMEOUT " + lockTimeout);
|
||||
}
|
||||
}
|
||||
+67
@@ -0,0 +1,67 @@
|
||||
/*******************************************************************************
|
||||
* Copyright 2017 Bstek
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
||||
* use this file except in compliance with the License. You may obtain a copy
|
||||
* of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations under
|
||||
* the License.
|
||||
******************************************************************************/
|
||||
package com.itheima.sfbx.rule.console.repository.database.manager;
|
||||
|
||||
import org.apache.jackrabbit.core.util.db.CheckSchemaOperation;
|
||||
|
||||
import com.itheima.sfbx.rule.console.repository.database.DbPersistenceManager;
|
||||
|
||||
/**
|
||||
* @author Jacky.gao
|
||||
* @since 2017年12月7日
|
||||
*/
|
||||
public class MSSqlPersistenceManager extends DbPersistenceManager {
|
||||
|
||||
/** the MS SQL table space to use */
|
||||
protected String tableSpace = "";
|
||||
|
||||
public MSSqlPersistenceManager() {
|
||||
setDriver("com.microsoft.sqlserver.jdbc.SQLServerDriver");
|
||||
setDatabaseType("mssql");
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
protected CheckSchemaOperation createCheckSchemaOperation() {
|
||||
return super.createCheckSchemaOperation().addVariableReplacement(
|
||||
CheckSchemaOperation.TABLE_SPACE_VARIABLE, tableSpace);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the configured MS SQL table space.
|
||||
*
|
||||
* @return the configured MS SQL table space.
|
||||
*/
|
||||
public String getTableSpace() {
|
||||
return tableSpace;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the MS SQL table space.
|
||||
*
|
||||
* @param tableSpace the MS SQL table space.
|
||||
*/
|
||||
public void setTableSpace(String tableSpace) {
|
||||
if (tableSpace != null && tableSpace.trim().length() > 0) {
|
||||
this.tableSpace = "on " + tableSpace.trim();
|
||||
} else {
|
||||
this.tableSpace = "";
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
+42
@@ -0,0 +1,42 @@
|
||||
/*******************************************************************************
|
||||
* Copyright 2017 Bstek
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
||||
* use this file except in compliance with the License. You may obtain a copy
|
||||
* of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations under
|
||||
* the License.
|
||||
******************************************************************************/
|
||||
package com.itheima.sfbx.rule.console.repository.database.manager;
|
||||
|
||||
import org.apache.jackrabbit.core.persistence.PMContext;
|
||||
|
||||
import com.itheima.sfbx.rule.console.repository.database.DbPersistenceManager;
|
||||
|
||||
/**
|
||||
* @author Jacky.gao
|
||||
* @since 2017年12月7日
|
||||
*/
|
||||
public class MySqlPersistenceManager extends DbPersistenceManager {
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public void init(PMContext context) throws Exception {
|
||||
// init default values
|
||||
if (getDriver() == null) {
|
||||
setDriver("org.gjt.mm.mysql.Driver");
|
||||
}
|
||||
if (getDatabaseType() == null) {
|
||||
setDatabaseType("mysql");
|
||||
}
|
||||
super.init(context);
|
||||
}
|
||||
|
||||
}
|
||||
+37
@@ -0,0 +1,37 @@
|
||||
/*******************************************************************************
|
||||
* Copyright 2017 Bstek
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
||||
* use this file except in compliance with the License. You may obtain a copy
|
||||
* of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations under
|
||||
* the License.
|
||||
******************************************************************************/
|
||||
package com.itheima.sfbx.rule.console.repository.database.manager;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
|
||||
import org.apache.jackrabbit.core.util.db.ConnectionHelper;
|
||||
import org.apache.jackrabbit.core.util.db.Oracle10R1ConnectionHelper;
|
||||
|
||||
/**
|
||||
* @author Jacky.gao
|
||||
* @since 2017年12月7日
|
||||
*/
|
||||
public class Oracle9PersistenceManager extends OraclePersistenceManager {
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
protected ConnectionHelper createConnectionHelper(DataSource dataSrc) throws Exception {
|
||||
Oracle10R1ConnectionHelper helper = new Oracle10R1ConnectionHelper(dataSrc, blockOnConnectionLoss);
|
||||
helper.init();
|
||||
return helper;
|
||||
}
|
||||
}
|
||||
+167
@@ -0,0 +1,167 @@
|
||||
/*******************************************************************************
|
||||
* Copyright 2017 Bstek
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
||||
* use this file except in compliance with the License. You may obtain a copy
|
||||
* of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations under
|
||||
* the License.
|
||||
******************************************************************************/
|
||||
package com.itheima.sfbx.rule.console.repository.database.manager;
|
||||
|
||||
import java.sql.SQLException;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
|
||||
import org.apache.jackrabbit.core.persistence.PMContext;
|
||||
import org.apache.jackrabbit.core.persistence.pool.DbNameIndex;
|
||||
import org.apache.jackrabbit.core.persistence.pool.NGKDbNameIndex;
|
||||
import org.apache.jackrabbit.core.util.db.CheckSchemaOperation;
|
||||
import org.apache.jackrabbit.core.util.db.ConnectionHelper;
|
||||
import org.apache.jackrabbit.core.util.db.OracleConnectionHelper;
|
||||
|
||||
import com.itheima.sfbx.rule.console.repository.database.DbPersistenceManager;
|
||||
|
||||
/**
|
||||
* @author Jacky.gao
|
||||
* @since 2017年12月7日
|
||||
*/
|
||||
public class OraclePersistenceManager extends DbPersistenceManager {
|
||||
/**
|
||||
* The default tablespace clause used when {@link #tablespace} or {@link #indexTablespace}
|
||||
* are not specified.
|
||||
*/
|
||||
protected static final String DEFAULT_TABLESPACE_CLAUSE = "";
|
||||
|
||||
/**
|
||||
* Name of the replacement variable in the DDL for {@link #tablespace}.
|
||||
*/
|
||||
protected static final String TABLESPACE_VARIABLE = "${tablespace}";
|
||||
|
||||
/**
|
||||
* Name of the replacement variable in the DDL for {@link #indexTablespace}.
|
||||
*/
|
||||
protected static final String INDEX_TABLESPACE_VARIABLE = "${indexTablespace}";
|
||||
|
||||
/** The Oracle tablespace to use for tables */
|
||||
protected String tablespace;
|
||||
|
||||
/** The Oracle tablespace to use for indexes */
|
||||
protected String indexTablespace;
|
||||
|
||||
/**
|
||||
* Creates a new oracle persistence manager
|
||||
*/
|
||||
public OraclePersistenceManager() {
|
||||
tablespace = DEFAULT_TABLESPACE_CLAUSE;
|
||||
indexTablespace = DEFAULT_TABLESPACE_CLAUSE;
|
||||
// enable db blob support
|
||||
setExternalBLOBs(false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the configured Oracle tablespace for tables.
|
||||
* @return the configured Oracle tablespace for tables.
|
||||
*/
|
||||
public String getTablespace() {
|
||||
return tablespace;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the Oracle tablespace for tables.
|
||||
* @param tablespaceName the Oracle tablespace for tables.
|
||||
*/
|
||||
public void setTablespace(String tablespaceName) {
|
||||
this.tablespace = this.buildTablespaceClause(tablespaceName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the configured Oracle tablespace for indexes.
|
||||
* @return the configured Oracle tablespace for indexes.
|
||||
*/
|
||||
public String getIndexTablespace() {
|
||||
return indexTablespace;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the Oracle tablespace for indexes.
|
||||
* @param tablespaceName the Oracle tablespace for indexes.
|
||||
*/
|
||||
public void setIndexTablespace(String tablespaceName) {
|
||||
this.indexTablespace = this.buildTablespaceClause(tablespaceName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs the <code>tablespace <tbs name></code> clause from
|
||||
* the supplied tablespace name. If the name is empty, {@link #DEFAULT_TABLESPACE_CLAUSE}
|
||||
* is returned instead.
|
||||
*
|
||||
* @param tablespaceName A tablespace name
|
||||
* @return A tablespace clause using the supplied name or
|
||||
* <code>{@value #DEFAULT_TABLESPACE_CLAUSE}</code> if the name is empty
|
||||
*/
|
||||
private String buildTablespaceClause(String tablespaceName) {
|
||||
if (tablespaceName == null || tablespaceName.trim().length() == 0) {
|
||||
return DEFAULT_TABLESPACE_CLAUSE;
|
||||
} else {
|
||||
return "tablespace " + tablespaceName.trim();
|
||||
}
|
||||
}
|
||||
|
||||
public void init(PMContext context) throws Exception {
|
||||
// init default values
|
||||
if (getDriver() == null) {
|
||||
setDriver("oracle.jdbc.OracleDriver");
|
||||
}
|
||||
if (getUrl() == null) {
|
||||
setUrl("jdbc:oracle:thin:@127.0.0.1:1521:xe");
|
||||
}
|
||||
if (getDatabaseType() == null) {
|
||||
setDatabaseType("oracle");
|
||||
}
|
||||
if (getSchemaObjectPrefix() == null) {
|
||||
setSchemaObjectPrefix(context.getHomeDir().getName() + "_");
|
||||
}
|
||||
super.init(context);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a new instance of a NGKDbNameIndex.
|
||||
*
|
||||
* @return a new instance of a NGKDbNameIndex.
|
||||
* @throws SQLException if an SQL error occurs.
|
||||
*/
|
||||
protected DbNameIndex createDbNameIndex() throws SQLException {
|
||||
return new NGKDbNameIndex(conHelper, schemaObjectPrefix);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
protected ConnectionHelper createConnectionHelper(DataSource dataSrc) throws Exception {
|
||||
OracleConnectionHelper helper = new OracleConnectionHelper(dataSrc, blockOnConnectionLoss);
|
||||
helper.init();
|
||||
return helper;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
protected CheckSchemaOperation createCheckSchemaOperation() {
|
||||
if (DEFAULT_TABLESPACE_CLAUSE.equals(indexTablespace) && !DEFAULT_TABLESPACE_CLAUSE.equals(tablespace)) {
|
||||
// tablespace was set but not indexTablespace : use the same for both
|
||||
indexTablespace = tablespace;
|
||||
}
|
||||
return super.createCheckSchemaOperation()
|
||||
.addVariableReplacement(TABLESPACE_VARIABLE, tablespace)
|
||||
.addVariableReplacement(INDEX_TABLESPACE_VARIABLE, indexTablespace);
|
||||
}
|
||||
}
|
||||
+75
@@ -0,0 +1,75 @@
|
||||
/*******************************************************************************
|
||||
* Copyright 2017 Bstek
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
||||
* use this file except in compliance with the License. You may obtain a copy
|
||||
* of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations under
|
||||
* the License.
|
||||
******************************************************************************/
|
||||
package com.itheima.sfbx.rule.console.repository.database.manager;
|
||||
|
||||
import java.sql.SQLException;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
|
||||
import org.apache.jackrabbit.core.persistence.PMContext;
|
||||
import org.apache.jackrabbit.core.persistence.pool.DbNameIndex;
|
||||
import org.apache.jackrabbit.core.persistence.pool.PostgreSQLNameIndex;
|
||||
import org.apache.jackrabbit.core.util.db.ConnectionHelper;
|
||||
import org.apache.jackrabbit.core.util.db.PostgreSQLConnectionHelper;
|
||||
|
||||
import com.itheima.sfbx.rule.console.repository.database.DbPersistenceManager;
|
||||
|
||||
/**
|
||||
* @author Jacky.gao
|
||||
* @since 2017年12月7日
|
||||
*/
|
||||
public class PostgreSQLPersistenceManager extends DbPersistenceManager {
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public void init(PMContext context) throws Exception {
|
||||
// init default values
|
||||
if (getDriver() == null) {
|
||||
setDriver("org.postgresql.Driver");
|
||||
}
|
||||
if (getDatabaseType() == null) {
|
||||
setDatabaseType("postgresql");
|
||||
}
|
||||
super.init(context);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a new instance of a DbNameIndex.
|
||||
* @return a new instance of a DbNameIndex.
|
||||
* @throws SQLException if an SQL error occurs.
|
||||
*/
|
||||
protected DbNameIndex createDbNameIndex() throws SQLException {
|
||||
return new PostgreSQLNameIndex(conHelper, schemaObjectPrefix);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
protected ConnectionHelper createConnectionHelper(DataSource dataSrc) throws Exception {
|
||||
return new PostgreSQLConnectionHelper(dataSrc, blockOnConnectionLoss);
|
||||
}
|
||||
|
||||
/**
|
||||
* returns the storage model
|
||||
* @return the storage model
|
||||
*/
|
||||
public int getStorageModel() {
|
||||
return SM_LONGLONG_KEYS;
|
||||
}
|
||||
|
||||
}
|
||||
+54
@@ -0,0 +1,54 @@
|
||||
/*******************************************************************************
|
||||
* Copyright 2017 Bstek
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
||||
* use this file except in compliance with the License. You may obtain a copy
|
||||
* of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations under
|
||||
* the License.
|
||||
******************************************************************************/
|
||||
package com.itheima.sfbx.rule.console.repository.database.store;
|
||||
|
||||
import java.sql.SQLException;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
|
||||
import org.apache.jackrabbit.core.data.DataStoreException;
|
||||
import org.apache.jackrabbit.core.util.db.ConnectionHelper;
|
||||
import org.apache.jackrabbit.core.util.db.DerbyConnectionHelper;
|
||||
|
||||
import com.itheima.sfbx.rule.console.repository.database.DatabaseDataStore;
|
||||
|
||||
/**
|
||||
* @author Jacky.gao
|
||||
* @since 2017年12月7日
|
||||
*/
|
||||
public class DerbyDataStore extends DatabaseDataStore {
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
protected ConnectionHelper createConnectionHelper(DataSource dataSrc) throws Exception {
|
||||
return new DerbyConnectionHelper(dataSrc, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public synchronized void close() throws DataStoreException {
|
||||
super.close();
|
||||
try {
|
||||
((DerbyConnectionHelper) conHelper).shutDown(getDriver());
|
||||
} catch (SQLException e) {
|
||||
throw new DataStoreException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
+69
@@ -0,0 +1,69 @@
|
||||
/*******************************************************************************
|
||||
* Copyright 2017 Bstek
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
||||
* use this file except in compliance with the License. You may obtain a copy
|
||||
* of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations under
|
||||
* the License.
|
||||
******************************************************************************/
|
||||
package com.itheima.sfbx.rule.console.repository.database.system;
|
||||
|
||||
import com.itheima.sfbx.rule.console.repository.database.BaseDbFileSystem;
|
||||
|
||||
/**
|
||||
* @author Jacky.gao
|
||||
* @since 2017年12月6日
|
||||
*/
|
||||
public class DB2FileSystem extends BaseDbFileSystem {
|
||||
|
||||
@Override
|
||||
public String databaseType() {
|
||||
return "db2";
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new <code>DB2FileSystem</code> instance.
|
||||
*/
|
||||
public DB2FileSystem() {
|
||||
// preset some attributes to reasonable defaults
|
||||
schema = "db2";
|
||||
driver = "com.ibm.db2.jcc.DB2Driver";
|
||||
}
|
||||
|
||||
//-----------------------------------------< DatabaseFileSystem overrides >
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
* <p>
|
||||
* Since DB2 requires parameter markers within the select clause to be
|
||||
* explicitly typed using <code>cast(? as type_name)</code> some statements
|
||||
* had to be changed accordingly.
|
||||
*/
|
||||
protected void buildSQLStatements() {
|
||||
super.buildSQLStatements();
|
||||
|
||||
copyFileSQL = "insert into "
|
||||
+ schemaObjectPrefix + "FSENTRY "
|
||||
+ "(FSENTRY_PATH, FSENTRY_NAME, FSENTRY_DATA, "
|
||||
+ "FSENTRY_LASTMOD, FSENTRY_LENGTH) "
|
||||
+ "select cast(? as varchar(745)), cast(? as varchar(255)), FSENTRY_DATA, "
|
||||
+ "FSENTRY_LASTMOD, FSENTRY_LENGTH from "
|
||||
+ schemaObjectPrefix + "FSENTRY where FSENTRY_PATH = ? "
|
||||
+ "and FSENTRY_NAME = ? and FSENTRY_DATA is not null";
|
||||
|
||||
copyFilesSQL = "insert into "
|
||||
+ schemaObjectPrefix + "FSENTRY "
|
||||
+ "(FSENTRY_PATH, FSENTRY_NAME, FSENTRY_DATA, "
|
||||
+ "FSENTRY_LASTMOD, FSENTRY_LENGTH) "
|
||||
+ "select cast(? as varchar(745)), FSENTRY_NAME, FSENTRY_DATA, "
|
||||
+ "FSENTRY_LASTMOD, FSENTRY_LENGTH from "
|
||||
+ schemaObjectPrefix + "FSENTRY where FSENTRY_PATH = ? "
|
||||
+ "and FSENTRY_DATA is not null";
|
||||
}
|
||||
}
|
||||
+91
@@ -0,0 +1,91 @@
|
||||
/*******************************************************************************
|
||||
* Copyright 2017 Bstek
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
||||
* use this file except in compliance with the License. You may obtain a copy
|
||||
* of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations under
|
||||
* the License.
|
||||
******************************************************************************/
|
||||
package com.itheima.sfbx.rule.console.repository.database.system;
|
||||
|
||||
import java.sql.SQLException;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
|
||||
import org.apache.jackrabbit.core.fs.FileSystemException;
|
||||
import org.apache.jackrabbit.core.util.db.ConnectionHelper;
|
||||
import org.apache.jackrabbit.core.util.db.DerbyConnectionHelper;
|
||||
|
||||
import com.itheima.sfbx.rule.console.repository.database.BaseDbFileSystem;
|
||||
|
||||
/**
|
||||
* @author Jacky.gao
|
||||
* @since 2017年12月6日
|
||||
*/
|
||||
public class DerbyFileSystem extends BaseDbFileSystem {
|
||||
|
||||
@Override
|
||||
public String databaseType() {
|
||||
return "derby";
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Flag indicating whether this derby database should be shutdown on close.
|
||||
*/
|
||||
protected boolean shutdownOnClose;
|
||||
|
||||
/**
|
||||
* Creates a new <code>DerbyFileSystem</code> instance.
|
||||
*/
|
||||
public DerbyFileSystem() {
|
||||
// preset some attributes to reasonable defaults
|
||||
schema = "derby";
|
||||
driver = "org.apache.derby.jdbc.EmbeddedDriver";
|
||||
shutdownOnClose = true;
|
||||
initialized = false;
|
||||
}
|
||||
|
||||
//----------------------------------------------------< setters & getters >
|
||||
|
||||
public boolean getShutdownOnClose() {
|
||||
return shutdownOnClose;
|
||||
}
|
||||
|
||||
public void setShutdownOnClose(boolean shutdownOnClose) {
|
||||
this.shutdownOnClose = shutdownOnClose;
|
||||
}
|
||||
|
||||
//-----------------------------------------------< DbFileSystem overrides >
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
protected ConnectionHelper createConnectionHelper(DataSource dataSrc) throws Exception {
|
||||
return new DerbyConnectionHelper(dataSrc, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public void close() throws FileSystemException {
|
||||
super.close();
|
||||
if (shutdownOnClose) {
|
||||
try {
|
||||
((DerbyConnectionHelper) conHelper).shutDown(driver);
|
||||
} catch (SQLException e) {
|
||||
throw new FileSystemException("failed to shutdown Derby", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+78
@@ -0,0 +1,78 @@
|
||||
/*******************************************************************************
|
||||
* Copyright 2017 Bstek
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
||||
* use this file except in compliance with the License. You may obtain a copy
|
||||
* of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations under
|
||||
* the License.
|
||||
******************************************************************************/
|
||||
package com.itheima.sfbx.rule.console.repository.database.system;
|
||||
|
||||
import org.apache.jackrabbit.core.util.db.CheckSchemaOperation;
|
||||
|
||||
import com.itheima.sfbx.rule.console.repository.database.BaseDbFileSystem;
|
||||
|
||||
/**
|
||||
* @author Jacky.gao
|
||||
* @since 2017年12月6日
|
||||
*/
|
||||
public class MSSqlFileSystem extends BaseDbFileSystem {
|
||||
@Override
|
||||
public String databaseType() {
|
||||
// TODO Auto-generated method stub
|
||||
return "mssql";
|
||||
}
|
||||
|
||||
|
||||
/** the variable for the MS SQL table space */
|
||||
public static final String TABLE_SPACE_VARIABLE = "${tableSpace}";
|
||||
|
||||
/** the MS SQL table space to use */
|
||||
protected String tableSpace = "";
|
||||
|
||||
/**
|
||||
* Returns the configured MS SQL table space.
|
||||
* @return the configured MS SQL table space.
|
||||
*/
|
||||
public String getTableSpace() {
|
||||
return tableSpace;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the MS SQL table space.
|
||||
* @param tableSpace the MS SQL table space.
|
||||
*/
|
||||
public void setTableSpace(String tableSpace) {
|
||||
if (tableSpace != null && tableSpace.length() > 0) {
|
||||
this.tableSpace = "on " + tableSpace.trim();
|
||||
} else {
|
||||
this.tableSpace = "";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new <code>MSSqlFileSystem</code> instance.
|
||||
*/
|
||||
public MSSqlFileSystem() {
|
||||
// preset some attributes to reasonable defaults
|
||||
schema = "mssql";
|
||||
driver = "com.microsoft.sqlserver.jdbc.SQLServerDriver";
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
protected CheckSchemaOperation createCheckSchemaOperation() {
|
||||
return super.createCheckSchemaOperation().addVariableReplacement(
|
||||
CheckSchemaOperation.TABLE_SPACE_VARIABLE, tableSpace);
|
||||
}
|
||||
|
||||
}
|
||||
+29
@@ -0,0 +1,29 @@
|
||||
/*******************************************************************************
|
||||
* Copyright 2017 Bstek
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
||||
* use this file except in compliance with the License. You may obtain a copy
|
||||
* of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations under
|
||||
* the License.
|
||||
******************************************************************************/
|
||||
package com.itheima.sfbx.rule.console.repository.database.system;
|
||||
|
||||
import com.itheima.sfbx.rule.console.repository.database.BaseDbFileSystem;
|
||||
|
||||
/**
|
||||
* @author Jacky.gao
|
||||
* @since 2017年12月6日
|
||||
*/
|
||||
public class MysqlFileSystem extends BaseDbFileSystem {
|
||||
@Override
|
||||
public String databaseType() {
|
||||
return "mysql";
|
||||
}
|
||||
}
|
||||
+37
@@ -0,0 +1,37 @@
|
||||
/*******************************************************************************
|
||||
* Copyright 2017 Bstek
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
||||
* use this file except in compliance with the License. You may obtain a copy
|
||||
* of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations under
|
||||
* the License.
|
||||
******************************************************************************/
|
||||
package com.itheima.sfbx.rule.console.repository.database.system;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
|
||||
import org.apache.jackrabbit.core.util.db.ConnectionHelper;
|
||||
import org.apache.jackrabbit.core.util.db.Oracle10R1ConnectionHelper;
|
||||
|
||||
/**
|
||||
* @author Jacky.gao
|
||||
* @since 2017年12月6日
|
||||
*/
|
||||
public class Oracle9FileSystem extends OracleFileSystem {
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
protected ConnectionHelper createConnectionHelper(DataSource dataSrc) throws Exception {
|
||||
Oracle10R1ConnectionHelper helper = new Oracle10R1ConnectionHelper(dataSrc, false);
|
||||
helper.init();
|
||||
return helper;
|
||||
}
|
||||
}
|
||||
+256
@@ -0,0 +1,256 @@
|
||||
/*******************************************************************************
|
||||
* Copyright 2017 Bstek
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
||||
* use this file except in compliance with the License. You may obtain a copy
|
||||
* of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations under
|
||||
* the License.
|
||||
******************************************************************************/
|
||||
package com.itheima.sfbx.rule.console.repository.database.system;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
|
||||
import org.apache.jackrabbit.core.util.db.CheckSchemaOperation;
|
||||
import org.apache.jackrabbit.core.util.db.ConnectionHelper;
|
||||
import org.apache.jackrabbit.core.util.db.OracleConnectionHelper;
|
||||
|
||||
import com.itheima.sfbx.rule.console.repository.database.BaseDbFileSystem;
|
||||
|
||||
/**
|
||||
* @author Jacky.gao
|
||||
* @since 2017年12月6日
|
||||
*/
|
||||
public class OracleFileSystem extends BaseDbFileSystem{
|
||||
@Override
|
||||
public String databaseType() {
|
||||
return "oracle";
|
||||
}
|
||||
|
||||
/**
|
||||
* The default tablespace clause used when {@link #tablespace} or {@link #indexTablespace}
|
||||
* are not specified.
|
||||
*/
|
||||
protected static final String DEFAULT_TABLESPACE_CLAUSE = "";
|
||||
|
||||
/**
|
||||
* Name of the replacement variable in the DDL for {@link #tablespace}.
|
||||
*/
|
||||
protected static final String TABLESPACE_VARIABLE = "${tablespace}";
|
||||
|
||||
/**
|
||||
* Name of the replacement variable in the DDL for {@link #indexTablespace}.
|
||||
*/
|
||||
protected static final String INDEX_TABLESPACE_VARIABLE = "${indexTablespace}";
|
||||
|
||||
/** The Oracle tablespace to use for tables */
|
||||
protected String tablespace;
|
||||
|
||||
/** The Oracle tablespace to use for indexes */
|
||||
protected String indexTablespace;
|
||||
|
||||
/**
|
||||
* Creates a new <code>OracleFileSystem</code> instance.
|
||||
*/
|
||||
public OracleFileSystem() {
|
||||
// preset some attributes to reasonable defaults
|
||||
schema = "oracle";
|
||||
driver = "oracle.jdbc.OracleDriver";
|
||||
schemaObjectPrefix = "";
|
||||
tablespace = DEFAULT_TABLESPACE_CLAUSE;
|
||||
indexTablespace = DEFAULT_TABLESPACE_CLAUSE;
|
||||
initialized = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the configured Oracle tablespace for tables.
|
||||
* @return the configured Oracle tablespace for tables.
|
||||
*/
|
||||
public String getTablespace() {
|
||||
return tablespace;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the Oracle tablespace for tables.
|
||||
* @param tablespaceName the Oracle tablespace for tables.
|
||||
*/
|
||||
public void setTablespace(String tablespaceName) {
|
||||
this.tablespace = this.buildTablespaceClause(tablespaceName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the configured Oracle tablespace for indexes.
|
||||
* @return the configured Oracle tablespace for indexes.
|
||||
*/
|
||||
public String getIndexTablespace() {
|
||||
return indexTablespace;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the Oracle tablespace for indexes.
|
||||
* @param tablespaceName the Oracle tablespace for indexes.
|
||||
*/
|
||||
public void setIndexTablespace(String tablespaceName) {
|
||||
this.indexTablespace = this.buildTablespaceClause(tablespaceName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs the <code>tablespace <tbs name></code> clause from
|
||||
* the supplied tablespace name. If the name is empty, {@link #DEFAULT_TABLESPACE_CLAUSE}
|
||||
* is returned instead.
|
||||
*
|
||||
* @param tablespaceName A tablespace name
|
||||
* @return A tablespace clause using the supplied name or
|
||||
* <code>{@value #DEFAULT_TABLESPACE_CLAUSE}</code> if the name is empty
|
||||
*/
|
||||
private String buildTablespaceClause(String tablespaceName) {
|
||||
if (tablespaceName == null || tablespaceName.trim().length() == 0) {
|
||||
return DEFAULT_TABLESPACE_CLAUSE;
|
||||
} else {
|
||||
return "tablespace " + tablespaceName.trim();
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------< DatabaseFileSystem overrides >
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
protected ConnectionHelper createConnectionHelper(DataSource dataSrc) throws Exception {
|
||||
OracleConnectionHelper helper = new OracleConnectionHelper(dataSrc, false);
|
||||
helper.init();
|
||||
return helper;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
protected CheckSchemaOperation createCheckSchemaOperation() {
|
||||
if (DEFAULT_TABLESPACE_CLAUSE.equals(indexTablespace) && !DEFAULT_TABLESPACE_CLAUSE.equals(tablespace)) {
|
||||
// tablespace was set but not indexTablespace : use the same for both
|
||||
indexTablespace = tablespace;
|
||||
}
|
||||
return super.createCheckSchemaOperation()
|
||||
.addVariableReplacement(TABLESPACE_VARIABLE, tablespace)
|
||||
.addVariableReplacement(INDEX_TABLESPACE_VARIABLE, indexTablespace);
|
||||
}
|
||||
|
||||
//-----------------------------------------< DatabaseFileSystem overrides >
|
||||
|
||||
/**
|
||||
* Builds the SQL statements
|
||||
* <p>
|
||||
* Since Oracle treats emtpy strings and BLOBs as null values the SQL
|
||||
* statements had to be adapated accordingly. The following changes were
|
||||
* necessary:
|
||||
* <ul>
|
||||
* <li>The distinction between file and folder entries is based on
|
||||
* FSENTRY_LENGTH being null/not null rather than FSENTRY_DATA being
|
||||
* null/not null because FSENTRY_DATA of a 0-length (i.e. empty) file is
|
||||
* null in Oracle.</li>
|
||||
* <li>Folder entries: Since the root folder has an empty name (which would
|
||||
* be null in Oracle), an empty name is automatically converted and treated
|
||||
* as " ".</li>
|
||||
* </ul>
|
||||
*/
|
||||
protected void buildSQLStatements() {
|
||||
insertFileSQL = "insert into "
|
||||
+ schemaObjectPrefix + "FSENTRY "
|
||||
+ "(FSENTRY_PATH, FSENTRY_NAME, FSENTRY_DATA, "
|
||||
+ "FSENTRY_LASTMOD, FSENTRY_LENGTH) "
|
||||
+ "values (?, ?, ?, ?, ?)";
|
||||
|
||||
insertFolderSQL = "insert into "
|
||||
+ schemaObjectPrefix + "FSENTRY "
|
||||
+ "(FSENTRY_PATH, FSENTRY_NAME, FSENTRY_LASTMOD, FSENTRY_LENGTH) "
|
||||
+ "values (?, nvl(?, ' '), ?, null)";
|
||||
|
||||
updateDataSQL = "update "
|
||||
+ schemaObjectPrefix + "FSENTRY "
|
||||
+ "set FSENTRY_DATA = ?, FSENTRY_LASTMOD = ?, FSENTRY_LENGTH = ? "
|
||||
+ "where FSENTRY_PATH = ? and FSENTRY_NAME = ? "
|
||||
+ "and FSENTRY_LENGTH is not null";
|
||||
|
||||
updateLastModifiedSQL = "update "
|
||||
+ schemaObjectPrefix + "FSENTRY set FSENTRY_LASTMOD = ? "
|
||||
+ "where FSENTRY_PATH = ? and FSENTRY_NAME = ? "
|
||||
+ "and FSENTRY_LENGTH is not null";
|
||||
|
||||
selectExistSQL = "select 1 from "
|
||||
+ schemaObjectPrefix + "FSENTRY where FSENTRY_PATH = ? "
|
||||
+ "and FSENTRY_NAME = nvl(?, ' ')";
|
||||
|
||||
selectFileExistSQL = "select 1 from "
|
||||
+ schemaObjectPrefix + "FSENTRY where FSENTRY_PATH = ? "
|
||||
+ "and FSENTRY_NAME = ? and FSENTRY_LENGTH is not null";
|
||||
|
||||
selectFolderExistSQL = "select 1 from "
|
||||
+ schemaObjectPrefix + "FSENTRY where FSENTRY_PATH = ? "
|
||||
+ "and FSENTRY_NAME = nvl(?, ' ') and FSENTRY_LENGTH is null";
|
||||
|
||||
selectFileNamesSQL = "select FSENTRY_NAME from "
|
||||
+ schemaObjectPrefix + "FSENTRY where FSENTRY_PATH = ? "
|
||||
+ "and FSENTRY_LENGTH is not null";
|
||||
|
||||
selectFolderNamesSQL = "select FSENTRY_NAME from "
|
||||
+ schemaObjectPrefix + "FSENTRY where FSENTRY_PATH = ? "
|
||||
+ "and FSENTRY_NAME != ' ' "
|
||||
+ "and FSENTRY_LENGTH is null";
|
||||
|
||||
selectFileAndFolderNamesSQL = "select FSENTRY_NAME from "
|
||||
+ schemaObjectPrefix + "FSENTRY where FSENTRY_PATH = ? "
|
||||
+ "and FSENTRY_NAME != ' '";
|
||||
|
||||
selectChildCountSQL = "select count(FSENTRY_NAME) from "
|
||||
+ schemaObjectPrefix + "FSENTRY where FSENTRY_PATH = ? "
|
||||
+ "and FSENTRY_NAME != ' '";
|
||||
|
||||
selectDataSQL = "select nvl(FSENTRY_DATA, empty_blob()) from "
|
||||
+ schemaObjectPrefix + "FSENTRY where FSENTRY_PATH = ? "
|
||||
+ "and FSENTRY_NAME = ? and FSENTRY_LENGTH is not null";
|
||||
|
||||
selectLastModifiedSQL = "select FSENTRY_LASTMOD from "
|
||||
+ schemaObjectPrefix + "FSENTRY where FSENTRY_PATH = ? "
|
||||
+ "and FSENTRY_NAME = nvl(?, ' ')";
|
||||
|
||||
selectLengthSQL = "select nvl(FSENTRY_LENGTH, 0) from "
|
||||
+ schemaObjectPrefix + "FSENTRY where FSENTRY_PATH = ? "
|
||||
+ "and FSENTRY_NAME = ? and FSENTRY_LENGTH is not null";
|
||||
|
||||
deleteFileSQL = "delete from "
|
||||
+ schemaObjectPrefix + "FSENTRY where FSENTRY_PATH = ? "
|
||||
+ "and FSENTRY_NAME = ? and FSENTRY_LENGTH is not null";
|
||||
|
||||
deleteFolderSQL = "delete from "
|
||||
+ schemaObjectPrefix + "FSENTRY where "
|
||||
+ "(FSENTRY_PATH = ? and FSENTRY_NAME = nvl(?, ' ') and FSENTRY_LENGTH is null) "
|
||||
+ "or (FSENTRY_PATH = ?) "
|
||||
+ "or (FSENTRY_PATH like ?) ";
|
||||
|
||||
copyFileSQL = "insert into "
|
||||
+ schemaObjectPrefix + "FSENTRY "
|
||||
+ "(FSENTRY_PATH, FSENTRY_NAME, FSENTRY_DATA, "
|
||||
+ "FSENTRY_LASTMOD, FSENTRY_LENGTH) "
|
||||
+ "select ?, ?, FSENTRY_DATA, "
|
||||
+ "FSENTRY_LASTMOD, FSENTRY_LENGTH from "
|
||||
+ schemaObjectPrefix + "FSENTRY where FSENTRY_PATH = ? "
|
||||
+ "and FSENTRY_NAME = ? and FSENTRY_LENGTH is not null";
|
||||
|
||||
copyFilesSQL = "insert into "
|
||||
+ schemaObjectPrefix + "FSENTRY "
|
||||
+ "(FSENTRY_PATH, FSENTRY_NAME, FSENTRY_DATA, "
|
||||
+ "FSENTRY_LASTMOD, FSENTRY_LENGTH) "
|
||||
+ "select ?, FSENTRY_NAME, FSENTRY_DATA, "
|
||||
+ "FSENTRY_LASTMOD, FSENTRY_LENGTH from "
|
||||
+ schemaObjectPrefix + "FSENTRY where FSENTRY_PATH = ? "
|
||||
+ "and FSENTRY_LENGTH is not null";
|
||||
}
|
||||
}
|
||||
+29
@@ -0,0 +1,29 @@
|
||||
/*******************************************************************************
|
||||
* Copyright 2017 Bstek
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
||||
* use this file except in compliance with the License. You may obtain a copy
|
||||
* of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations under
|
||||
* the License.
|
||||
******************************************************************************/
|
||||
package com.itheima.sfbx.rule.console.repository.database.system;
|
||||
|
||||
import com.itheima.sfbx.rule.console.repository.database.BaseDbFileSystem;
|
||||
|
||||
/**
|
||||
* @author Jacky.gao
|
||||
* @since 2017年12月6日
|
||||
*/
|
||||
public class PostgreSQLFileSystem extends BaseDbFileSystem {
|
||||
@Override
|
||||
public String databaseType() {
|
||||
return "postgresql";
|
||||
}
|
||||
}
|
||||
+117
@@ -0,0 +1,117 @@
|
||||
/*******************************************************************************
|
||||
* Copyright 2017 Bstek
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
||||
* use this file except in compliance with the License. You may obtain a copy
|
||||
* of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations under
|
||||
* the License.
|
||||
******************************************************************************/
|
||||
package com.itheima.sfbx.rule.console.repository.model;
|
||||
|
||||
import com.itheima.sfbx.framework.rule.RuleException;
|
||||
import com.itheima.sfbx.framework.rule.dsl.Constant;
|
||||
|
||||
/**
|
||||
* @author Jacky.gao
|
||||
* @since 2014年12月24日
|
||||
*/
|
||||
public enum FileType {
|
||||
Ruleset{
|
||||
@Override
|
||||
public String toString() {
|
||||
return "rs.xml";
|
||||
}
|
||||
},DecisionTable{
|
||||
@Override
|
||||
public String toString() {
|
||||
return "dt.xml";
|
||||
}
|
||||
},ScriptDecisionTable{
|
||||
@Override
|
||||
public String toString() {
|
||||
return "dts.xml";
|
||||
}
|
||||
},ActionLibrary{
|
||||
@Override
|
||||
public String toString() {
|
||||
return "al.xml";
|
||||
}
|
||||
},VariableLibrary{
|
||||
@Override
|
||||
public String toString() {
|
||||
return "vl.xml";
|
||||
}
|
||||
},ParameterLibrary{
|
||||
@Override
|
||||
public String toString() {
|
||||
return "pl.xml";
|
||||
}
|
||||
},ConstantLibrary{
|
||||
@Override
|
||||
public String toString() {
|
||||
return "cl.xml";
|
||||
}
|
||||
},RuleFlow{
|
||||
@Override
|
||||
public String toString() {
|
||||
return "rl.xml";
|
||||
}
|
||||
},UL{
|
||||
@Override
|
||||
public String toString() {
|
||||
return Constant.UL_SUFFIX;
|
||||
}
|
||||
},DecisionTree{
|
||||
@Override
|
||||
public String toString() {
|
||||
return "dtree.xml";
|
||||
}
|
||||
},Scorecard{
|
||||
@Override
|
||||
public String toString() {
|
||||
return "sc";
|
||||
}
|
||||
},DIR{
|
||||
@Override
|
||||
public String toString() {
|
||||
return "DIR";
|
||||
}
|
||||
};
|
||||
|
||||
public static FileType parse(String type){
|
||||
if(type.equals("rs.xml")){
|
||||
return FileType.Ruleset;
|
||||
}else if(type.equals("dt.xml")){
|
||||
return FileType.DecisionTable;
|
||||
}else if(type.equals("dts.xml")){
|
||||
return FileType.ScriptDecisionTable;
|
||||
}else if(type.equals("al.xml")){
|
||||
return FileType.ActionLibrary;
|
||||
}else if(type.equals("vl.xml")){
|
||||
return FileType.VariableLibrary;
|
||||
}else if(type.equals("pl.xml")){
|
||||
return FileType.ParameterLibrary;
|
||||
}else if(type.equals("cl.xml")){
|
||||
return FileType.ConstantLibrary;
|
||||
}else if(type.equals("rl.xml")){
|
||||
return FileType.RuleFlow;
|
||||
}else if(type.equals("ul")){
|
||||
return FileType.UL;
|
||||
}else if(type.equals("dtree.xml")){
|
||||
return FileType.DecisionTree;
|
||||
}else if(type.equals("sc")){
|
||||
return FileType.Scorecard;
|
||||
}else if(type.equals("DIR")){
|
||||
return FileType.DIR;
|
||||
}else{
|
||||
throw new RuleException("Unknow type:"+type);
|
||||
}
|
||||
}
|
||||
}
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
/*******************************************************************************
|
||||
* Copyright 2017 Bstek
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
||||
* use this file except in compliance with the License. You may obtain a copy
|
||||
* of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations under
|
||||
* the License.
|
||||
******************************************************************************/
|
||||
package com.itheima.sfbx.rule.console.repository.model;
|
||||
/**
|
||||
* @author Jacky.gao
|
||||
* @since 2016年3月3日
|
||||
*/
|
||||
public enum LibType {
|
||||
ruleset,decisiontable,decisiontree,ruleflow,scorecard,res,all;
|
||||
}
|
||||
+37
@@ -0,0 +1,37 @@
|
||||
/*******************************************************************************
|
||||
* Copyright 2017 Bstek
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
||||
* use this file except in compliance with the License. You may obtain a copy
|
||||
* of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations under
|
||||
* the License.
|
||||
******************************************************************************/
|
||||
package com.itheima.sfbx.rule.console.repository.model;
|
||||
|
||||
/**
|
||||
* @author Jacky.gao
|
||||
* @since 2015年5月7日
|
||||
*/
|
||||
public enum PermissionType {
|
||||
ProjectVisible, NewVar, NewParam, NewConst, NewAction,
|
||||
NewRule, NewDslRule, NewDecisionTable,NewDslDecisionTable,NewRuleFlow,NewDecisionTree,
|
||||
|
||||
DelVar,DelParam,DelConst,DelAction,DelRule,DelDslRule,
|
||||
DelDecisionTable,DelDslDecisionTable,DelRuleFlow,DelDecisionTree,
|
||||
|
||||
ModVar,ModParam,ModConst,ModAction,ModRule,ModDslRule,
|
||||
ModDecisionTable,ModDslDecisionTable,ModRuleFlow,ModDecisionTree,
|
||||
|
||||
InsertRow, DelRow, InsertConditionCol, ModConditionCol, DelConditionCol,
|
||||
InsertActionCol, ModActionCol, DelActionCol,
|
||||
|
||||
InsertDslRow, DelDslRow, InsertDslConditionCol, ModDslConditionCol, DelDslConditionCol,
|
||||
InsertDslActionCol, ModDslActionCol, DelDslActionCol
|
||||
}
|
||||
+135
@@ -0,0 +1,135 @@
|
||||
/*******************************************************************************
|
||||
* Copyright 2017 Bstek
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
||||
* use this file except in compliance with the License. You may obtain a copy
|
||||
* of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations under
|
||||
* the License.
|
||||
******************************************************************************/
|
||||
package com.itheima.sfbx.rule.console.repository.model;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.codehaus.jackson.annotate.JsonIgnore;
|
||||
|
||||
/**
|
||||
* @author Jacky.gao
|
||||
* @since 2014年12月24日
|
||||
*/
|
||||
public class RepositoryFile {
|
||||
private String id;
|
||||
private String name;
|
||||
private String fullPath;
|
||||
private Type type;
|
||||
private Type folderType;
|
||||
private boolean lock;
|
||||
private String lockInfo;
|
||||
@JsonIgnore
|
||||
private LibType libType;
|
||||
@JsonIgnore
|
||||
private RepositoryFile parentFile;
|
||||
private List<RepositoryFile> children;
|
||||
public RepositoryFile() {
|
||||
this.id=UUID.randomUUID().toString();
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
public RepositoryFile getParentFile() {
|
||||
return parentFile;
|
||||
}
|
||||
public void setParentFile(RepositoryFile parentFile) {
|
||||
this.parentFile = parentFile;
|
||||
}
|
||||
public LibType getLibType() {
|
||||
return libType;
|
||||
}
|
||||
public void setLibType(LibType libType) {
|
||||
this.libType = libType;
|
||||
}
|
||||
public List<RepositoryFile> getChildren() {
|
||||
return children;
|
||||
}
|
||||
public void addChild(RepositoryFile fileInfo,boolean isdir) {
|
||||
if(this.children==null){
|
||||
this.children=new ArrayList<RepositoryFile>();
|
||||
}
|
||||
fileInfo.setParentFile(this);
|
||||
if(isdir){
|
||||
this.children.add(0,fileInfo);
|
||||
}else{
|
||||
this.children.add(fileInfo);
|
||||
}
|
||||
}
|
||||
public void setChildren(List<RepositoryFile> children) {
|
||||
this.children = children;
|
||||
}
|
||||
public String getFullPath(){
|
||||
if(fullPath==null){
|
||||
if(parentFile!=null){
|
||||
fullPath=parentFile.getFullPath();
|
||||
}else{
|
||||
fullPath="";
|
||||
}
|
||||
if(fullPath.equals("/")){
|
||||
fullPath="";
|
||||
}
|
||||
fullPath+="/"+name;
|
||||
}
|
||||
return fullPath;
|
||||
}
|
||||
public void setFullPath(String fullPath) {
|
||||
this.fullPath = fullPath;
|
||||
}
|
||||
public Type getType() {
|
||||
return type;
|
||||
}
|
||||
public void setType(Type type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public Type getFolderType() {
|
||||
return folderType;
|
||||
}
|
||||
|
||||
public void setFolderType(Type folderType) {
|
||||
this.folderType = folderType;
|
||||
}
|
||||
|
||||
public boolean isLock() {
|
||||
return lock;
|
||||
}
|
||||
|
||||
public void setLock(boolean lock) {
|
||||
this.lock = lock;
|
||||
}
|
||||
|
||||
public String getLockInfo() {
|
||||
return lockInfo;
|
||||
}
|
||||
|
||||
public void setLockInfo(String lockInfo) {
|
||||
this.lockInfo = lockInfo;
|
||||
}
|
||||
}
|
||||
+53
@@ -0,0 +1,53 @@
|
||||
/*******************************************************************************
|
||||
* Copyright 2017 Bstek
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
||||
* use this file except in compliance with the License. You may obtain a copy
|
||||
* of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations under
|
||||
* the License.
|
||||
******************************************************************************/
|
||||
package com.itheima.sfbx.rule.console.repository.model;
|
||||
|
||||
|
||||
/**
|
||||
* @author Jacky.gao
|
||||
* @since 2015年1月7日
|
||||
*/
|
||||
public class ResourceItem {
|
||||
private String name;
|
||||
private String path;
|
||||
private String packageId;
|
||||
private String version;
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
public String getPath() {
|
||||
return path;
|
||||
}
|
||||
public void setPath(String path) {
|
||||
this.path = path;
|
||||
}
|
||||
public String getPackageId() {
|
||||
return packageId;
|
||||
}
|
||||
public void setPackageId(String packageId) {
|
||||
this.packageId = packageId;
|
||||
}
|
||||
public String getVersion() {
|
||||
return version;
|
||||
}
|
||||
public void setVersion(String version) {
|
||||
this.version = version;
|
||||
}
|
||||
}
|
||||
+63
@@ -0,0 +1,63 @@
|
||||
/*******************************************************************************
|
||||
* Copyright 2017 Bstek
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
||||
* use this file except in compliance with the License. You may obtain a copy
|
||||
* of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations under
|
||||
* the License.
|
||||
******************************************************************************/
|
||||
package com.itheima.sfbx.rule.console.repository.model;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Jacky.gao
|
||||
* @since 2015年1月7日
|
||||
*/
|
||||
|
||||
public class ResourcePackage {
|
||||
|
||||
private String id;
|
||||
private String name;
|
||||
private String project;
|
||||
private Date createDate;
|
||||
private List<ResourceItem> resourceItems;
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
public String getProject() {
|
||||
return project;
|
||||
}
|
||||
public void setProject(String project) {
|
||||
this.project = project;
|
||||
}
|
||||
public Date getCreateDate() {
|
||||
return createDate;
|
||||
}
|
||||
public void setCreateDate(Date createDate) {
|
||||
this.createDate = createDate;
|
||||
}
|
||||
public List<ResourceItem> getResourceItems() {
|
||||
return resourceItems;
|
||||
}
|
||||
public void setResourceItems(List<ResourceItem> resourceItems) {
|
||||
this.resourceItems = resourceItems;
|
||||
}
|
||||
}
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
/*******************************************************************************
|
||||
* Copyright 2017 Bstek
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
||||
* use this file except in compliance with the License. You may obtain a copy
|
||||
* of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations under
|
||||
* the License.
|
||||
******************************************************************************/
|
||||
package com.itheima.sfbx.rule.console.repository.model;
|
||||
|
||||
/**
|
||||
* @author Jacky.gao
|
||||
* @since 2016年5月26日
|
||||
*/
|
||||
public enum Type {
|
||||
root, project, resource, resourcePackage, lib, action, parameter, constant, variable, ruleLib, decisionTableLib, decisionTreeLib, scorecardLib,flowLib, scorecard,rule, ul, decisionTable, scriptDecisionTable, decisionTree, flow, all, folder;
|
||||
}
|
||||
+62
@@ -0,0 +1,62 @@
|
||||
/*******************************************************************************
|
||||
* Copyright 2017 Bstek
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
||||
* use this file except in compliance with the License. You may obtain a copy
|
||||
* of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations under
|
||||
* the License.
|
||||
******************************************************************************/
|
||||
package com.itheima.sfbx.rule.console.repository.model;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* @author Jacky.gao
|
||||
* @since 2015年3月25日
|
||||
*/
|
||||
public class VersionFile {
|
||||
private String path;
|
||||
private String createUser;
|
||||
private String name;
|
||||
private String comment;
|
||||
private Date createDate;
|
||||
|
||||
public String getPath() {
|
||||
return path;
|
||||
}
|
||||
public void setPath(String path) {
|
||||
this.path = path;
|
||||
}
|
||||
public String getCreateUser() {
|
||||
return createUser;
|
||||
}
|
||||
public void setCreateUser(String createUser) {
|
||||
this.createUser = createUser;
|
||||
}
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getComment() {
|
||||
return comment;
|
||||
}
|
||||
public void setComment(String comment) {
|
||||
this.comment = comment;
|
||||
}
|
||||
public Date getCreateDate() {
|
||||
return createDate;
|
||||
}
|
||||
public void setCreateDate(Date createDate) {
|
||||
this.createDate = createDate;
|
||||
}
|
||||
}
|
||||
+31
@@ -0,0 +1,31 @@
|
||||
/*******************************************************************************
|
||||
* Copyright 2017 Bstek
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
||||
* use this file except in compliance with the License. You may obtain a copy
|
||||
* of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations under
|
||||
* the License.
|
||||
******************************************************************************/
|
||||
package com.itheima.sfbx.rule.console.repository.permission;
|
||||
/**
|
||||
* @author Jacky.gao
|
||||
* @since 2016年9月1日
|
||||
*/
|
||||
public interface PermissionService {
|
||||
boolean isAdmin();
|
||||
|
||||
boolean projectHasPermission(String path);
|
||||
|
||||
boolean projectPackageHasReadPermission(String path);
|
||||
boolean projectPackageHasWritePermission(String path);
|
||||
|
||||
boolean fileHasWritePermission(String path);
|
||||
boolean fileHasReadPermission(String path);
|
||||
}
|
||||
+229
@@ -0,0 +1,229 @@
|
||||
/*******************************************************************************
|
||||
* Copyright 2017 Bstek
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
||||
* use this file except in compliance with the License. You may obtain a copy
|
||||
* of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations under
|
||||
* the License.
|
||||
******************************************************************************/
|
||||
package com.itheima.sfbx.rule.console.repository.permission;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.itheima.sfbx.framework.rule.RuleException;
|
||||
import com.itheima.sfbx.rule.console.EnvironmentUtils;
|
||||
import com.itheima.sfbx.rule.console.User;
|
||||
import com.itheima.sfbx.rule.console.repository.RepositoryService;
|
||||
import com.itheima.sfbx.rule.console.repository.model.FileType;
|
||||
import com.itheima.sfbx.rule.console.servlet.RequestHolder;
|
||||
import com.itheima.sfbx.rule.console.servlet.permission.ProjectConfig;
|
||||
import com.itheima.sfbx.rule.console.servlet.permission.UserPermission;
|
||||
|
||||
/**
|
||||
* @author Jacky.gao
|
||||
* @since 2016年9月1日
|
||||
*/
|
||||
public class PermissionServiceImpl implements PermissionStore,PermissionService {
|
||||
private RepositoryService repositoryService;
|
||||
|
||||
@Override
|
||||
public boolean projectHasPermission(String path) {
|
||||
if(isAdmin()){
|
||||
return true;
|
||||
}
|
||||
path=processPath(path);
|
||||
int slashPos=path.indexOf("/");
|
||||
if(slashPos==-1){
|
||||
slashPos=path.length();
|
||||
}
|
||||
String project=path.substring(0,slashPos);
|
||||
ProjectConfig config=loadProjectPermission(project);
|
||||
if(config==null){
|
||||
return false;
|
||||
}
|
||||
return config.isReadProject();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean projectPackageHasReadPermission(String path) {
|
||||
return projectPackagePermission(path, 0);
|
||||
}
|
||||
@Override
|
||||
public boolean projectPackageHasWritePermission(String path) {
|
||||
return projectPackagePermission(path, 1);
|
||||
}
|
||||
|
||||
private boolean projectPackagePermission(String path,int type){
|
||||
if(isAdmin()){
|
||||
return true;
|
||||
}
|
||||
path=processPath(path);
|
||||
int slashPos=path.indexOf("/");
|
||||
if(slashPos==-1){
|
||||
slashPos=path.length();
|
||||
}
|
||||
String project=path.substring(0,slashPos);
|
||||
ProjectConfig config=loadProjectPermission(project);
|
||||
if(config==null){
|
||||
return false;
|
||||
}
|
||||
if(type==0){
|
||||
return config.isReadPackage();
|
||||
}else{
|
||||
return config.isWritePackage();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean fileHasReadPermission(String path) {
|
||||
return fileHasPermission(path, 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean fileHasWritePermission(String path) {
|
||||
return fileHasPermission(path, 1);
|
||||
}
|
||||
|
||||
private boolean fileHasPermission(String path,int permissionType){
|
||||
if(isAdmin()){
|
||||
return true;
|
||||
}
|
||||
path=processPath(path);
|
||||
int slashPos=path.indexOf("/");
|
||||
if(slashPos==-1){
|
||||
throw new RuleException("Invalid file ["+path+"] for permission check.");
|
||||
}
|
||||
String project=path.substring(0,slashPos);
|
||||
int pointPos=path.indexOf(".");
|
||||
if(pointPos==-1){
|
||||
return true;
|
||||
}
|
||||
ProjectConfig config=loadProjectPermission(project);
|
||||
if(config==null){
|
||||
return false;
|
||||
}
|
||||
String extName=path.substring(pointPos+1,path.length());
|
||||
FileType type=FileType.parse(extName);
|
||||
switch(type){
|
||||
case VariableLibrary:
|
||||
if(permissionType==0){
|
||||
return config.isReadVariableFile();
|
||||
}else{
|
||||
return config.isWriteVariableFile();
|
||||
}
|
||||
case ActionLibrary:
|
||||
if(permissionType==0){
|
||||
return config.isReadActionFile();
|
||||
}else{
|
||||
return config.isWriteActionFile();
|
||||
}
|
||||
case ConstantLibrary:
|
||||
if(permissionType==0){
|
||||
return config.isReadConstantFile();
|
||||
}else{
|
||||
return config.isWriteConstantFile();
|
||||
}
|
||||
case DecisionTable:
|
||||
if(permissionType==0){
|
||||
return config.isReadDecisionTableFile();
|
||||
}else{
|
||||
return config.isWriteDecisionTableFile();
|
||||
}
|
||||
case DecisionTree:
|
||||
if(permissionType==0){
|
||||
return config.isReadDecisionTreeFile();
|
||||
}else{
|
||||
return config.isWriteDecisionTreeFile();
|
||||
}
|
||||
case ParameterLibrary:
|
||||
if(permissionType==0){
|
||||
return config.isReadParameterFile();
|
||||
}else{
|
||||
return config.isWriteParameterFile();
|
||||
}
|
||||
case RuleFlow:
|
||||
if(permissionType==0){
|
||||
return config.isReadFlowFile();
|
||||
}else{
|
||||
return config.isWriteFlowFile();
|
||||
}
|
||||
case Ruleset:
|
||||
if(permissionType==0){
|
||||
return config.isReadRuleFile();
|
||||
}else{
|
||||
return config.isWriteRuleFile();
|
||||
}
|
||||
case ScriptDecisionTable:
|
||||
if(permissionType==0){
|
||||
return config.isReadDecisionTableFile();
|
||||
}else{
|
||||
return config.isWriteDecisionTableFile();
|
||||
}
|
||||
case UL:
|
||||
if(permissionType==0){
|
||||
return config.isReadRuleFile();
|
||||
}else{
|
||||
return config.isWriteRuleFile();
|
||||
}
|
||||
case Scorecard:
|
||||
if(permissionType==0){
|
||||
return config.isReadScorecardFile();
|
||||
}else{
|
||||
return config.isWriteScorecardFile();
|
||||
}
|
||||
case DIR:
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private String processPath(String path) {
|
||||
if (path.startsWith("/")) {
|
||||
return path.substring(1, path.length());
|
||||
}
|
||||
return path;
|
||||
}
|
||||
@Override
|
||||
public boolean isAdmin(){
|
||||
User user=EnvironmentUtils.getLoginUser(RequestHolder.newRequestContext());
|
||||
return user.isAdmin();
|
||||
}
|
||||
private ProjectConfig loadProjectPermission(String project){
|
||||
User user=EnvironmentUtils.getLoginUser(RequestHolder.newRequestContext());
|
||||
String companyId=user.getCompanyId();
|
||||
try{
|
||||
List<UserPermission> permissions=repositoryService.loadResourceSecurityConfigs(companyId);
|
||||
ProjectConfig target=null;
|
||||
for(UserPermission p:permissions){
|
||||
if(p.getUsername().equals(user.getUsername())){
|
||||
for(ProjectConfig pc:p.getProjectConfigs()){
|
||||
if(pc.getProject().equals(project)){
|
||||
target=pc;
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
return target;
|
||||
}catch(Exception ex){
|
||||
throw new RuleException(ex);
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void refreshPermissionStore() {
|
||||
//do nothing...
|
||||
}
|
||||
|
||||
public void setRepositoryService(RepositoryService repositoryService) {
|
||||
this.repositoryService = repositoryService;
|
||||
}
|
||||
}
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
/*******************************************************************************
|
||||
* Copyright 2017 Bstek
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
||||
* use this file except in compliance with the License. You may obtain a copy
|
||||
* of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations under
|
||||
* the License.
|
||||
******************************************************************************/
|
||||
package com.itheima.sfbx.rule.console.repository.permission;
|
||||
/**
|
||||
* @author Jacky.gao
|
||||
* @since 2016年9月1日
|
||||
*/
|
||||
public interface PermissionStore {
|
||||
void refreshPermissionStore();
|
||||
}
|
||||
+46
@@ -0,0 +1,46 @@
|
||||
/*******************************************************************************
|
||||
* Copyright 2017 Bstek
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
||||
* use this file except in compliance with the License. You may obtain a copy
|
||||
* of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations under
|
||||
* the License.
|
||||
******************************************************************************/
|
||||
package com.itheima.sfbx.rule.console.repository.updater;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.StringWriter;
|
||||
|
||||
import org.dom4j.Document;
|
||||
import org.dom4j.io.OutputFormat;
|
||||
import org.dom4j.io.XMLWriter;
|
||||
|
||||
import com.itheima.sfbx.framework.rule.RuleException;
|
||||
|
||||
/**
|
||||
* @author Jacky.gao
|
||||
* @since 2015年8月4日
|
||||
*/
|
||||
public abstract class AbstractReferenceUpdater implements ReferenceUpdater {
|
||||
protected String xmlToString(Document doc){
|
||||
StringWriter stringWriter = new StringWriter();
|
||||
OutputFormat xmlFormat = new OutputFormat();
|
||||
xmlFormat.setEncoding("UTF-8");
|
||||
XMLWriter xmlWriter = new XMLWriter(stringWriter, xmlFormat);
|
||||
try {
|
||||
xmlWriter.write(doc);
|
||||
xmlWriter.close();
|
||||
return stringWriter.toString();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
throw new RuleException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
+105
@@ -0,0 +1,105 @@
|
||||
/*******************************************************************************
|
||||
* Copyright 2017 Bstek
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
||||
* use this file except in compliance with the License. You may obtain a copy
|
||||
* of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations under
|
||||
* the License.
|
||||
******************************************************************************/
|
||||
package com.itheima.sfbx.rule.console.repository.updater;
|
||||
|
||||
import org.dom4j.Document;
|
||||
import org.dom4j.DocumentHelper;
|
||||
import org.dom4j.Element;
|
||||
|
||||
import com.itheima.sfbx.framework.rule.RuleException;
|
||||
import com.itheima.sfbx.rule.console.repository.model.FileType;
|
||||
|
||||
/**
|
||||
* @author Jacky.gao
|
||||
* @since 2015年8月4日
|
||||
*/
|
||||
public class DecisionTableReferenceUpdater extends AbstractReferenceUpdater {
|
||||
public boolean contain(String path, String xml) {
|
||||
try{
|
||||
Document doc=DocumentHelper.parseText(xml);
|
||||
Element element=doc.getRootElement();
|
||||
for(Object obj:element.elements()){
|
||||
if(!(obj instanceof Element)){
|
||||
continue;
|
||||
}
|
||||
Element ele=(Element)obj;
|
||||
String name=ele.getName();
|
||||
boolean match=false;
|
||||
if(name.equals("import-variable-library")){
|
||||
match=true;
|
||||
}else if(name.equals("import-constant-library")){
|
||||
match=true;
|
||||
}else if(name.equals("import-action-library")){
|
||||
match=true;
|
||||
}else if(name.equals("import-parameter-library")){
|
||||
match=true;
|
||||
}
|
||||
if(!match){
|
||||
continue;
|
||||
}
|
||||
String filePath=ele.attributeValue("path");
|
||||
if(filePath.endsWith(path)){
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}catch(Exception ex){
|
||||
throw new RuleException(ex);
|
||||
}
|
||||
}
|
||||
public String update(String oldPath, String newPath, String xml) {
|
||||
try{
|
||||
boolean modify=false;
|
||||
Document doc=DocumentHelper.parseText(xml);
|
||||
Element element=doc.getRootElement();
|
||||
for(Object obj:element.elements()){
|
||||
if(!(obj instanceof Element)){
|
||||
continue;
|
||||
}
|
||||
Element ele=(Element)obj;
|
||||
String name=ele.getName();
|
||||
boolean match=false;
|
||||
if(name.equals("import-variable-library")){
|
||||
match=true;
|
||||
}else if(name.equals("import-constant-library")){
|
||||
match=true;
|
||||
}else if(name.equals("import-action-library")){
|
||||
match=true;
|
||||
}else if(name.equals("import-parameter-library")){
|
||||
match=true;
|
||||
}
|
||||
if(!match){
|
||||
continue;
|
||||
}
|
||||
String path=ele.attributeValue("path");
|
||||
if(path.endsWith(oldPath)){
|
||||
ele.addAttribute("path", newPath);
|
||||
modify=true;
|
||||
}
|
||||
}
|
||||
if(modify){
|
||||
return xmlToString(doc);
|
||||
}
|
||||
return null;
|
||||
}catch(Exception ex){
|
||||
throw new RuleException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean support(String path) {
|
||||
return path.endsWith(FileType.DecisionTable.toString());
|
||||
}
|
||||
}
|
||||
+105
@@ -0,0 +1,105 @@
|
||||
/*******************************************************************************
|
||||
* Copyright 2017 Bstek
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
||||
* use this file except in compliance with the License. You may obtain a copy
|
||||
* of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations under
|
||||
* the License.
|
||||
******************************************************************************/
|
||||
package com.itheima.sfbx.rule.console.repository.updater;
|
||||
|
||||
import org.dom4j.Document;
|
||||
import org.dom4j.DocumentHelper;
|
||||
import org.dom4j.Element;
|
||||
|
||||
import com.itheima.sfbx.framework.rule.RuleException;
|
||||
import com.itheima.sfbx.rule.console.repository.model.FileType;
|
||||
|
||||
/**
|
||||
* @author Jacky.gao
|
||||
* @since 2015年8月4日
|
||||
*/
|
||||
public class FlowDefinitionReferenceUpdater extends AbstractReferenceUpdater {
|
||||
public boolean contain(String path, String xml) {
|
||||
try{
|
||||
Document doc=DocumentHelper.parseText(xml);
|
||||
Element element=doc.getRootElement();
|
||||
for(Object obj:element.elements()){
|
||||
if(!(obj instanceof Element)){
|
||||
continue;
|
||||
}
|
||||
Element ele=(Element)obj;
|
||||
String name=ele.getName();
|
||||
boolean match=false;
|
||||
if(name.equals("import-variable-library")){
|
||||
match=true;
|
||||
}else if(name.equals("import-constant-library")){
|
||||
match=true;
|
||||
}else if(name.equals("import-action-library")){
|
||||
match=true;
|
||||
}else if(name.equals("import-parameter-library")){
|
||||
match=true;
|
||||
}
|
||||
if(!match){
|
||||
continue;
|
||||
}
|
||||
String filePath=ele.attributeValue("path");
|
||||
if(filePath.endsWith(path)){
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}catch(Exception ex){
|
||||
throw new RuleException(ex);
|
||||
}
|
||||
}
|
||||
public String update(String oldPath, String newPath, String xml) {
|
||||
try{
|
||||
boolean modify=false;
|
||||
Document doc=DocumentHelper.parseText(xml);
|
||||
Element element=doc.getRootElement();
|
||||
for(Object obj:element.elements()){
|
||||
if(!(obj instanceof Element)){
|
||||
continue;
|
||||
}
|
||||
Element ele=(Element)obj;
|
||||
String name=ele.getName();
|
||||
boolean match=false;
|
||||
if(name.equals("import-variable-library")){
|
||||
match=true;
|
||||
}else if(name.equals("import-constant-library")){
|
||||
match=true;
|
||||
}else if(name.equals("import-action-library")){
|
||||
match=true;
|
||||
}else if(name.equals("import-parameter-library")){
|
||||
match=true;
|
||||
}
|
||||
if(!match){
|
||||
continue;
|
||||
}
|
||||
String path=ele.attributeValue("path");
|
||||
if(path.endsWith(oldPath)){
|
||||
ele.addAttribute("path", newPath);
|
||||
modify=true;
|
||||
}
|
||||
}
|
||||
if(modify){
|
||||
return xmlToString(doc);
|
||||
}
|
||||
return null;
|
||||
}catch(Exception ex){
|
||||
throw new RuleException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean support(String path) {
|
||||
return path.endsWith(FileType.RuleFlow.toString());
|
||||
}
|
||||
}
|
||||
+25
@@ -0,0 +1,25 @@
|
||||
/*******************************************************************************
|
||||
* Copyright 2017 Bstek
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
||||
* use this file except in compliance with the License. You may obtain a copy
|
||||
* of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations under
|
||||
* the License.
|
||||
******************************************************************************/
|
||||
package com.itheima.sfbx.rule.console.repository.updater;
|
||||
/**
|
||||
* @author Jacky.gao
|
||||
* @since 2015年8月4日
|
||||
*/
|
||||
public interface ReferenceUpdater {
|
||||
boolean contain(String path, String xml);
|
||||
String update(String path, String newPath, String xml);
|
||||
boolean support(String path);
|
||||
}
|
||||
+105
@@ -0,0 +1,105 @@
|
||||
/*******************************************************************************
|
||||
* Copyright 2017 Bstek
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
||||
* use this file except in compliance with the License. You may obtain a copy
|
||||
* of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations under
|
||||
* the License.
|
||||
******************************************************************************/
|
||||
package com.itheima.sfbx.rule.console.repository.updater;
|
||||
|
||||
import org.dom4j.Document;
|
||||
import org.dom4j.DocumentHelper;
|
||||
import org.dom4j.Element;
|
||||
|
||||
import com.itheima.sfbx.framework.rule.RuleException;
|
||||
import com.itheima.sfbx.rule.console.repository.model.FileType;
|
||||
|
||||
/**
|
||||
* @author Jacky.gao
|
||||
* @since 2015年8月4日
|
||||
*/
|
||||
public class RuleSetReferenceUpdater extends AbstractReferenceUpdater {
|
||||
public boolean contain(String path, String xml) {
|
||||
try{
|
||||
Document doc=DocumentHelper.parseText(xml);
|
||||
Element element=doc.getRootElement();
|
||||
for(Object obj:element.elements()){
|
||||
if(!(obj instanceof Element)){
|
||||
continue;
|
||||
}
|
||||
Element ele=(Element)obj;
|
||||
String name=ele.getName();
|
||||
boolean match=false;
|
||||
if(name.equals("import-variable-library")){
|
||||
match=true;
|
||||
}else if(name.equals("import-constant-library")){
|
||||
match=true;
|
||||
}else if(name.equals("import-action-library")){
|
||||
match=true;
|
||||
}else if(name.equals("import-parameter-library")){
|
||||
match=true;
|
||||
}
|
||||
if(!match){
|
||||
continue;
|
||||
}
|
||||
String filePath=ele.attributeValue("path");
|
||||
if(filePath.endsWith(path)){
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}catch(Exception ex){
|
||||
throw new RuleException(ex);
|
||||
}
|
||||
}
|
||||
public String update(String oldPath, String newPath, String xml) {
|
||||
try{
|
||||
boolean modify=false;
|
||||
Document doc=DocumentHelper.parseText(xml);
|
||||
Element element=doc.getRootElement();
|
||||
for(Object obj:element.elements()){
|
||||
if(!(obj instanceof Element)){
|
||||
continue;
|
||||
}
|
||||
Element ele=(Element)obj;
|
||||
String name=ele.getName();
|
||||
boolean match=false;
|
||||
if(name.equals("import-variable-library")){
|
||||
match=true;
|
||||
}else if(name.equals("import-constant-library")){
|
||||
match=true;
|
||||
}else if(name.equals("import-action-library")){
|
||||
match=true;
|
||||
}else if(name.equals("import-parameter-library")){
|
||||
match=true;
|
||||
}
|
||||
if(!match){
|
||||
continue;
|
||||
}
|
||||
String path=ele.attributeValue("path");
|
||||
if(path.endsWith(oldPath)){
|
||||
ele.addAttribute("path", newPath);
|
||||
modify=true;
|
||||
}
|
||||
}
|
||||
if(modify){
|
||||
return xmlToString(doc);
|
||||
}
|
||||
return null;
|
||||
}catch(Exception ex){
|
||||
throw new RuleException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean support(String path) {
|
||||
return path.endsWith(FileType.Ruleset.toString());
|
||||
}
|
||||
}
|
||||
+105
@@ -0,0 +1,105 @@
|
||||
/*******************************************************************************
|
||||
* Copyright 2017 Bstek
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
||||
* use this file except in compliance with the License. You may obtain a copy
|
||||
* of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations under
|
||||
* the License.
|
||||
******************************************************************************/
|
||||
package com.itheima.sfbx.rule.console.repository.updater;
|
||||
|
||||
import org.dom4j.Document;
|
||||
import org.dom4j.DocumentHelper;
|
||||
import org.dom4j.Element;
|
||||
|
||||
import com.itheima.sfbx.framework.rule.RuleException;
|
||||
import com.itheima.sfbx.rule.console.repository.model.FileType;
|
||||
|
||||
/**
|
||||
* @author Jacky.gao
|
||||
* @since 2015年8月4日
|
||||
*/
|
||||
public class ScriptDecisionTableReferenceUpdater extends AbstractReferenceUpdater {
|
||||
public boolean contain(String path, String xml) {
|
||||
try{
|
||||
Document doc=DocumentHelper.parseText(xml);
|
||||
Element element=doc.getRootElement();
|
||||
for(Object obj:element.elements()){
|
||||
if(!(obj instanceof Element)){
|
||||
continue;
|
||||
}
|
||||
Element ele=(Element)obj;
|
||||
String name=ele.getName();
|
||||
boolean match=false;
|
||||
if(name.equals("import-variable-library")){
|
||||
match=true;
|
||||
}else if(name.equals("import-constant-library")){
|
||||
match=true;
|
||||
}else if(name.equals("import-action-library")){
|
||||
match=true;
|
||||
}else if(name.equals("import-parameter-library")){
|
||||
match=true;
|
||||
}
|
||||
if(!match){
|
||||
continue;
|
||||
}
|
||||
String filePath=ele.attributeValue("path");
|
||||
if(filePath.endsWith(path)){
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}catch(Exception ex){
|
||||
throw new RuleException(ex);
|
||||
}
|
||||
}
|
||||
public String update(String oldPath, String newPath, String xml) {
|
||||
try{
|
||||
boolean modify=false;
|
||||
Document doc=DocumentHelper.parseText(xml);
|
||||
Element element=doc.getRootElement();
|
||||
for(Object obj:element.elements()){
|
||||
if(!(obj instanceof Element)){
|
||||
continue;
|
||||
}
|
||||
Element ele=(Element)obj;
|
||||
String name=ele.getName();
|
||||
boolean match=false;
|
||||
if(name.equals("import-variable-library")){
|
||||
match=true;
|
||||
}else if(name.equals("import-constant-library")){
|
||||
match=true;
|
||||
}else if(name.equals("import-action-library")){
|
||||
match=true;
|
||||
}else if(name.equals("import-parameter-library")){
|
||||
match=true;
|
||||
}
|
||||
if(!match){
|
||||
continue;
|
||||
}
|
||||
String path=ele.attributeValue("path");
|
||||
if(path.endsWith(oldPath)){
|
||||
ele.addAttribute("path", newPath);
|
||||
modify=true;
|
||||
}
|
||||
}
|
||||
if(modify){
|
||||
return xmlToString(doc);
|
||||
}
|
||||
return null;
|
||||
}catch(Exception ex){
|
||||
throw new RuleException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean support(String path) {
|
||||
return path.endsWith(FileType.ScriptDecisionTable.toString());
|
||||
}
|
||||
}
|
||||
+59
@@ -0,0 +1,59 @@
|
||||
/*******************************************************************************
|
||||
* Copyright 2017 Bstek
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
||||
* use this file except in compliance with the License. You may obtain a copy
|
||||
* of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations under
|
||||
* the License.
|
||||
******************************************************************************/
|
||||
package com.itheima.sfbx.rule.console.repository.updater;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
import com.itheima.sfbx.framework.rule.RuleException;
|
||||
import com.itheima.sfbx.rule.console.repository.model.FileType;
|
||||
import com.itheima.sfbx.framework.rule.dsl.DSLRuleSetBuilder;
|
||||
import com.itheima.sfbx.framework.rule.model.rule.Library;
|
||||
import com.itheima.sfbx.framework.rule.model.rule.RuleSet;
|
||||
|
||||
/**
|
||||
* @author Jacky.gao
|
||||
* @since 2015年8月4日
|
||||
*/
|
||||
public class ScriptRuleSetReferenceUpdater extends AbstractReferenceUpdater {
|
||||
private DSLRuleSetBuilder builder;
|
||||
public boolean contain(String path, String xml) {
|
||||
try {
|
||||
RuleSet rs=builder.build(xml);
|
||||
List<Library> libs=rs.getLibraries();
|
||||
if(libs!=null){
|
||||
for(Library lib:libs){
|
||||
String libpath=lib.getPath();
|
||||
if(libpath.indexOf(path)!=-1){
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
} catch (IOException e) {
|
||||
throw new RuleException(e);
|
||||
}
|
||||
}
|
||||
public String update(String path, String newPath, String xml) {
|
||||
return null;
|
||||
}
|
||||
public void setBuilder(DSLRuleSetBuilder builder) {
|
||||
this.builder = builder;
|
||||
}
|
||||
public boolean support(String path) {
|
||||
return path.endsWith(FileType.UL.toString());
|
||||
}
|
||||
}
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
Copyright 2017 Bstek
|
||||
|
||||
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.
|
||||
-->
|
||||
<Workspace>
|
||||
<FileSystem class="org.apache.jackrabbit.core.fs.local.LocalFileSystem">
|
||||
<param name="path" value="${wsp.home}"/>
|
||||
</FileSystem>
|
||||
<PersistenceManager class="org.apache.jackrabbit.core.persistence.bundle.BundleFsPersistenceManager">
|
||||
</PersistenceManager>
|
||||
</Workspace>
|
||||
+55
@@ -0,0 +1,55 @@
|
||||
/*******************************************************************************
|
||||
* Copyright 2017 Bstek
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
||||
* use this file except in compliance with the License. You may obtain a copy
|
||||
* of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations under
|
||||
* the License.
|
||||
******************************************************************************/
|
||||
package com.itheima.sfbx.rule.console.servlet;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import com.itheima.sfbx.framework.rule.RuleException;
|
||||
|
||||
|
||||
/**
|
||||
* @author Jacky.gao
|
||||
* @since 2016年6月3日
|
||||
*/
|
||||
public abstract class BaseServletHandler implements ServletHandler {
|
||||
|
||||
protected void invokeMethod(String methodName,HttpServletRequest req,HttpServletResponse resp){
|
||||
Method method;
|
||||
try {
|
||||
method = this.getClass().getMethod(methodName, new Class<?>[]{HttpServletRequest.class,HttpServletResponse.class});
|
||||
method.invoke(this, new Object[]{req,resp});
|
||||
} catch (NoSuchMethodException | SecurityException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
|
||||
throw new RuleException(e);
|
||||
}
|
||||
}
|
||||
|
||||
protected String retriveMethod(HttpServletRequest req) throws ServletException{
|
||||
String path=req.getContextPath()+URuleServlet.URL;
|
||||
String uri=req.getRequestURI();
|
||||
String targetUrl=uri.substring(path.length());
|
||||
int slashPos=targetUrl.indexOf("/",1);
|
||||
if(slashPos>-1){
|
||||
String methodName=targetUrl.substring(slashPos+1).trim();
|
||||
return methodName.length()>0 ? methodName : null;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
+58
@@ -0,0 +1,58 @@
|
||||
/*******************************************************************************
|
||||
* Copyright 2017 Bstek
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
||||
* use this file except in compliance with the License. You may obtain a copy
|
||||
* of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations under
|
||||
* the License.
|
||||
******************************************************************************/
|
||||
package com.itheima.sfbx.rule.console.servlet;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.apache.velocity.app.Velocity;
|
||||
import org.apache.velocity.app.VelocityEngine;
|
||||
import org.apache.velocity.runtime.RuntimeConstants;
|
||||
import org.apache.velocity.runtime.log.NullLogChute;
|
||||
import org.springframework.beans.BeansException;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.ApplicationContextAware;
|
||||
|
||||
import com.itheima.sfbx.framework.rule.Utils;
|
||||
|
||||
|
||||
/**
|
||||
* @author Jacky.gao
|
||||
* @since 2016年6月6日
|
||||
*/
|
||||
public abstract class RenderPageServletHandler extends WriteJsonServletHandler implements ApplicationContextAware{
|
||||
protected VelocityEngine ve;
|
||||
protected ApplicationContext applicationContext;
|
||||
protected String buildProjectNameFromFile(String file) {
|
||||
String project=null;
|
||||
if(StringUtils.isNotBlank(file)){
|
||||
file=Utils.decodeURL(file);
|
||||
if(file.startsWith("/")){
|
||||
file=file.substring(1,file.length());
|
||||
int pos=file.indexOf("/");
|
||||
project=file.substring(0,pos);
|
||||
}
|
||||
}
|
||||
return project;
|
||||
}
|
||||
@Override
|
||||
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
|
||||
this.applicationContext=applicationContext;
|
||||
ve = new VelocityEngine();
|
||||
ve.setProperty(Velocity.RESOURCE_LOADER, "class");
|
||||
ve.setProperty("class.resource.loader.class","org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader");
|
||||
ve.setProperty(RuntimeConstants.RUNTIME_LOG_LOGSYSTEM,new NullLogChute());
|
||||
ve.init();
|
||||
}
|
||||
}
|
||||
+38
@@ -0,0 +1,38 @@
|
||||
/*******************************************************************************
|
||||
* Copyright 2017 Bstek
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
||||
* use this file except in compliance with the License. You may obtain a copy
|
||||
* of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations under
|
||||
* the License.
|
||||
******************************************************************************/
|
||||
package com.itheima.sfbx.rule.console.servlet;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
/**
|
||||
* @author Jacky.gao
|
||||
* @since 2016年5月25日
|
||||
*/
|
||||
public class RequestContext {
|
||||
private HttpServletRequest req;
|
||||
private HttpServletResponse resp;
|
||||
public RequestContext(HttpServletRequest req, HttpServletResponse resp) {
|
||||
this.req=req;
|
||||
this.resp=resp;
|
||||
}
|
||||
public HttpServletRequest getRequest() {
|
||||
return req;
|
||||
}
|
||||
public HttpServletResponse getResponse() {
|
||||
return resp;
|
||||
}
|
||||
}
|
||||
+45
@@ -0,0 +1,45 @@
|
||||
/*******************************************************************************
|
||||
* Copyright 2017 Bstek
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
||||
* use this file except in compliance with the License. You may obtain a copy
|
||||
* of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations under
|
||||
* the License.
|
||||
******************************************************************************/
|
||||
package com.itheima.sfbx.rule.console.servlet;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
/**
|
||||
* @author Jacky.gao
|
||||
* @since 2016年9月1日
|
||||
*/
|
||||
public class RequestHolder {
|
||||
private static ThreadLocal<HttpServletRequest> request=new ThreadLocal<HttpServletRequest>();
|
||||
private static ThreadLocal<HttpServletResponse> response=new ThreadLocal<HttpServletResponse>();
|
||||
public static void set(HttpServletRequest request,HttpServletResponse response) {
|
||||
RequestHolder.request.set(request);
|
||||
RequestHolder.response.set(response);
|
||||
}
|
||||
public static RequestContext newRequestContext(){
|
||||
return new RequestContext(request.get(),response.get());
|
||||
}
|
||||
public static void reset(){
|
||||
request.remove();
|
||||
response.remove();
|
||||
}
|
||||
public static HttpServletRequest getRequest() {
|
||||
return request.get();
|
||||
}
|
||||
public static HttpServletResponse getResponse() {
|
||||
return response.get();
|
||||
}
|
||||
}
|
||||
+79
@@ -0,0 +1,79 @@
|
||||
/*******************************************************************************
|
||||
* Copyright 2017 Bstek
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
||||
* use this file except in compliance with the License. You may obtain a copy
|
||||
* of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations under
|
||||
* the License.
|
||||
******************************************************************************/
|
||||
package com.itheima.sfbx.rule.console.servlet;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.springframework.beans.BeansException;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.ApplicationContextAware;
|
||||
|
||||
/**
|
||||
* @author Jacky.gao
|
||||
* @since 2016年6月6日
|
||||
*/
|
||||
public class ResourceLoaderServletHandler implements ServletHandler,ApplicationContextAware{
|
||||
public static final String URL="/res";
|
||||
private ApplicationContext applicationContext;
|
||||
@Override
|
||||
public void execute(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
|
||||
String path=req.getContextPath()+URuleServlet.URL+URL;
|
||||
String uri=req.getRequestURI();
|
||||
String resPath=uri.substring(path.length()+1);
|
||||
String p="classpath:"+resPath;
|
||||
if(p.endsWith(".js")){
|
||||
resp.setContentType("text/javascript");
|
||||
}else if(p.endsWith(".css")){
|
||||
resp.setContentType("text/css");
|
||||
}else if(p.endsWith(".png")){
|
||||
resp.setContentType("image/png");
|
||||
}else if(p.endsWith(".jpg")){
|
||||
resp.setContentType("image/jpeg");
|
||||
}else{
|
||||
resp.setContentType("application/octet-stream");
|
||||
}
|
||||
InputStream input=applicationContext.getResource(p).getInputStream();
|
||||
OutputStream output=resp.getOutputStream();
|
||||
try{
|
||||
IOUtils.copy(input, output);
|
||||
}finally{
|
||||
if(input!=null){
|
||||
input.close();
|
||||
}
|
||||
if(output!=null){
|
||||
output.flush();
|
||||
output.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
|
||||
this.applicationContext=applicationContext;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String url() {
|
||||
return URL;
|
||||
}
|
||||
}
|
||||
+31
@@ -0,0 +1,31 @@
|
||||
/*******************************************************************************
|
||||
* Copyright 2017 Bstek
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
||||
* use this file except in compliance with the License. You may obtain a copy
|
||||
* of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations under
|
||||
* the License.
|
||||
******************************************************************************/
|
||||
package com.itheima.sfbx.rule.console.servlet;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
/**
|
||||
* @author Jacky.gao
|
||||
* @since 2016年5月23日
|
||||
*/
|
||||
public interface ServletHandler {
|
||||
void execute(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException;
|
||||
String url();
|
||||
}
|
||||
+129
@@ -0,0 +1,129 @@
|
||||
/*******************************************************************************
|
||||
* Copyright 2017 Bstek
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
||||
* use this file except in compliance with the License. You may obtain a copy
|
||||
* of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations under
|
||||
* the License.
|
||||
******************************************************************************/
|
||||
package com.itheima.sfbx.rule.console.servlet;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.servlet.ServletConfig;
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.http.HttpServlet;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.springframework.web.context.WebApplicationContext;
|
||||
import org.springframework.web.context.support.WebApplicationContextUtils;
|
||||
|
||||
import com.itheima.sfbx.rule.console.exception.NoPermissionException;
|
||||
import com.itheima.sfbx.rule.console.repository.NodeLockException;
|
||||
|
||||
/**
|
||||
* @author Jacky.gao
|
||||
* @since 2016年5月23日
|
||||
*/
|
||||
public class URuleServlet extends HttpServlet{
|
||||
private static final long serialVersionUID = -5067484267904906233L;
|
||||
private Map<String,ServletHandler> handlerMap=new HashMap<String,ServletHandler>();
|
||||
public static final String URL="/urule";
|
||||
|
||||
@Override
|
||||
public void init(ServletConfig config) throws ServletException {
|
||||
super.init(config);
|
||||
WebApplicationContext applicationContext=getWebApplicationContext(config);
|
||||
Collection<ServletHandler> handlers=applicationContext.getBeansOfType(ServletHandler.class).values();
|
||||
for(ServletHandler handler:handlers){
|
||||
String url=handler.url();
|
||||
if(handlerMap.containsKey(url)){
|
||||
throw new RuntimeException("Handler ["+url+"] already exist.");
|
||||
}
|
||||
handlerMap.put(url, handler);
|
||||
}
|
||||
}
|
||||
|
||||
protected WebApplicationContext getWebApplicationContext(ServletConfig config){
|
||||
return WebApplicationContextUtils.getWebApplicationContext(config.getServletContext());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
|
||||
RequestHolder.set(req, resp);
|
||||
try{
|
||||
String path=req.getContextPath()+URL;
|
||||
String uri=req.getRequestURI();
|
||||
String targetUrl=uri.substring(path.length());
|
||||
if(targetUrl.length()<1){
|
||||
resp.sendRedirect(req.getContextPath()+"/urule/frame");
|
||||
return;
|
||||
}
|
||||
int slashPos=targetUrl.indexOf("/",1);
|
||||
if(slashPos>-1){
|
||||
targetUrl=targetUrl.substring(0,slashPos);
|
||||
}
|
||||
ServletHandler targetHandler=handlerMap.get(targetUrl);
|
||||
if(targetHandler==null){
|
||||
outContent(resp,"Handler ["+targetUrl+"] not exist.");
|
||||
return;
|
||||
}
|
||||
targetHandler.execute(req, resp);
|
||||
}catch(Exception ex){
|
||||
Throwable e=getCause(ex);
|
||||
resp.setCharacterEncoding("UTF-8");
|
||||
PrintWriter pw=resp.getWriter();
|
||||
if(e instanceof NoPermissionException){
|
||||
resp.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
|
||||
pw.write("<h1>Permission denied!</h1>");
|
||||
pw.close();
|
||||
}else{
|
||||
resp.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
|
||||
String errorMsg = e.getMessage();
|
||||
if(StringUtils.isBlank(errorMsg)){
|
||||
errorMsg=e.getClass().getName();
|
||||
}
|
||||
pw.write(errorMsg);
|
||||
pw.close();
|
||||
if(!(e instanceof NodeLockException)){
|
||||
throw new ServletException(ex);
|
||||
}
|
||||
}
|
||||
}finally{
|
||||
RequestHolder.reset();
|
||||
}
|
||||
}
|
||||
|
||||
private void outContent(HttpServletResponse resp,String msg) throws IOException {
|
||||
resp.setContentType("text/html");
|
||||
PrintWriter pw=resp.getWriter();
|
||||
pw.write("<html>");
|
||||
pw.write("<header><title>URule Console</title></header>");
|
||||
pw.write("<body>");
|
||||
pw.write(msg);
|
||||
pw.write("</body>");
|
||||
pw.write("</html>");
|
||||
pw.flush();
|
||||
pw.close();
|
||||
}
|
||||
|
||||
private Throwable getCause(Throwable e){
|
||||
if(e.getCause()!=null){
|
||||
return getCause(e.getCause());
|
||||
}
|
||||
return e;
|
||||
}
|
||||
}
|
||||
+52
@@ -0,0 +1,52 @@
|
||||
/*******************************************************************************
|
||||
* Copyright 2017 Bstek
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
||||
* use this file except in compliance with the License. You may obtain a copy
|
||||
* of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations under
|
||||
* the License.
|
||||
******************************************************************************/
|
||||
package com.itheima.sfbx.rule.console.servlet;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.text.SimpleDateFormat;
|
||||
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.codehaus.jackson.map.ObjectMapper;
|
||||
import org.codehaus.jackson.map.SerializationConfig;
|
||||
import org.codehaus.jackson.map.annotate.JsonSerialize.Inclusion;
|
||||
|
||||
import com.itheima.sfbx.framework.rule.Configure;
|
||||
|
||||
/**
|
||||
* @author Jacky.gao
|
||||
* @since 2016年5月23日
|
||||
*/
|
||||
public abstract class WriteJsonServletHandler extends BaseServletHandler{
|
||||
protected void writeObjectToJson(HttpServletResponse resp,Object obj) throws ServletException, IOException{
|
||||
resp.setHeader("Access-Control-Allow-Origin", "*");
|
||||
resp.setContentType("text/json");
|
||||
resp.setCharacterEncoding("UTF-8");
|
||||
ObjectMapper mapper=new ObjectMapper();
|
||||
mapper.setSerializationInclusion(Inclusion.NON_NULL);
|
||||
mapper.configure(SerializationConfig.Feature.WRITE_DATES_AS_TIMESTAMPS,false);
|
||||
mapper.setDateFormat(new SimpleDateFormat(Configure.getDateFormat()));
|
||||
OutputStream out = resp.getOutputStream();
|
||||
try {
|
||||
mapper.writeValue(out, obj);
|
||||
} finally {
|
||||
out.flush();
|
||||
out.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
+185
@@ -0,0 +1,185 @@
|
||||
/*******************************************************************************
|
||||
* Copyright 2017 Bstek
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
||||
* use this file except in compliance with the License. You may obtain a copy
|
||||
* of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations under
|
||||
* the License.
|
||||
******************************************************************************/
|
||||
package com.itheima.sfbx.rule.console.servlet.action;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
import java.lang.reflect.Field;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.apache.velocity.Template;
|
||||
import org.apache.velocity.VelocityContext;
|
||||
import org.springframework.aop.framework.AdvisedSupport;
|
||||
import org.springframework.aop.framework.AopProxy;
|
||||
import org.springframework.aop.support.AopUtils;
|
||||
|
||||
import com.itheima.sfbx.rule.console.servlet.RenderPageServletHandler;
|
||||
import com.itheima.sfbx.framework.rule.model.ExposeAction;
|
||||
import com.itheima.sfbx.framework.rule.model.library.Datatype;
|
||||
import com.itheima.sfbx.framework.rule.model.library.action.Method;
|
||||
import com.itheima.sfbx.framework.rule.model.library.action.Parameter;
|
||||
|
||||
public class ActionServletHandler extends RenderPageServletHandler{
|
||||
@Override
|
||||
public void execute(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
|
||||
String method=retriveMethod(req);
|
||||
if(method!=null){
|
||||
invokeMethod(method, req, resp);
|
||||
}else{
|
||||
VelocityContext context = new VelocityContext();
|
||||
context.put("contextPath", req.getContextPath());
|
||||
resp.setContentType("text/html");
|
||||
resp.setCharacterEncoding("utf-8");
|
||||
Template template=ve.getTemplate("html/action-editor.html","utf-8");
|
||||
PrintWriter writer=resp.getWriter();
|
||||
template.merge(context, writer);
|
||||
writer.close();
|
||||
}
|
||||
}
|
||||
public void loadMethods(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
|
||||
String beanId=req.getParameter("beanId");
|
||||
Object o=applicationContext.getBean(beanId);
|
||||
Object bean=getTarget(o);
|
||||
List<Method> list=new ArrayList<Method>();
|
||||
java.lang.reflect.Method[] methods=bean.getClass().getMethods();
|
||||
for(java.lang.reflect.Method m:methods){
|
||||
ExposeAction action=m.getAnnotation(ExposeAction.class);
|
||||
if(action==null){
|
||||
continue;
|
||||
}
|
||||
String name=m.getName();
|
||||
Method method=new Method();
|
||||
method.setMethodName(name);
|
||||
method.setName(action.value());
|
||||
method.setParameters(buildParameters(m));
|
||||
list.add(method);
|
||||
}
|
||||
writeObjectToJson(resp, list);
|
||||
}
|
||||
|
||||
private Object getTarget(Object proxy){
|
||||
if(!AopUtils.isAopProxy(proxy)) {
|
||||
return proxy;//不是代理对象
|
||||
}
|
||||
try {
|
||||
if(AopUtils.isJdkDynamicProxy(proxy)) {
|
||||
return getJdkDynamicProxyTargetObject(proxy);
|
||||
} else { //cglib
|
||||
return getCglibProxyTargetObject(proxy);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
private Object getCglibProxyTargetObject(Object proxy) throws Exception {
|
||||
Field h = proxy.getClass().getDeclaredField("CGLIB$CALLBACK_0");
|
||||
h.setAccessible(true);
|
||||
Object dynamicAdvisedInterceptor = h.get(proxy);
|
||||
Field advised = dynamicAdvisedInterceptor.getClass().getDeclaredField("advised");
|
||||
advised.setAccessible(true);
|
||||
|
||||
Object target = ((AdvisedSupport)advised.get(dynamicAdvisedInterceptor)).getTargetSource().getTarget();
|
||||
|
||||
return target;
|
||||
}
|
||||
|
||||
|
||||
private Object getJdkDynamicProxyTargetObject(Object proxy) throws Exception {
|
||||
Field h = proxy.getClass().getSuperclass().getDeclaredField("h");
|
||||
h.setAccessible(true);
|
||||
AopProxy aopProxy = (AopProxy) h.get(proxy);
|
||||
Field advised = aopProxy.getClass().getDeclaredField("advised");
|
||||
advised.setAccessible(true);
|
||||
Object target = ((AdvisedSupport)advised.get(aopProxy)).getTargetSource().getTarget();
|
||||
return target;
|
||||
}
|
||||
|
||||
private List<Parameter> buildParameters(java.lang.reflect.Method m){
|
||||
List<Parameter> parameters=new ArrayList<Parameter>();
|
||||
Class<?>[] classes=m.getParameterTypes();
|
||||
for(int i=0;i<classes.length;i++){
|
||||
Class<?> c=classes[i];
|
||||
Parameter p=new Parameter();
|
||||
p.setName("参数"+i);
|
||||
p.setType(buildDatatype(c));
|
||||
parameters.add(p);
|
||||
}
|
||||
return parameters;
|
||||
}
|
||||
|
||||
private Datatype buildDatatype(Class<?> clazz) {
|
||||
if(clazz.equals(String.class)){
|
||||
return Datatype.String;
|
||||
}else if(clazz.equals(BigDecimal.class)){
|
||||
return Datatype.BigDecimal;
|
||||
}else if(clazz.equals(Boolean.class)){
|
||||
return Datatype.Boolean;
|
||||
}else if(clazz.equals(Boolean.class)){
|
||||
return Datatype.Boolean;
|
||||
}else if(clazz.equals(boolean.class)){
|
||||
return Datatype.Boolean;
|
||||
}else if(clazz.equals(Date.class)){
|
||||
return Datatype.Date;
|
||||
}else if(clazz.equals(Double.class)){
|
||||
return Datatype.Double;
|
||||
}else if(clazz.equals(double.class)){
|
||||
return Datatype.Double;
|
||||
}else if(Enum.class.isAssignableFrom(clazz)){
|
||||
return Datatype.Enum;
|
||||
}else if(clazz.equals(Float.class)){
|
||||
return Datatype.Float;
|
||||
}else if(clazz.equals(float.class)){
|
||||
return Datatype.Float;
|
||||
}else if(clazz.equals(Integer.class)){
|
||||
return Datatype.Integer;
|
||||
}else if(clazz.equals(int.class)){
|
||||
return Datatype.Integer;
|
||||
}else if(clazz.equals(Character.class)){
|
||||
return Datatype.Char;
|
||||
}else if(clazz.equals(char.class)){
|
||||
return Datatype.Char;
|
||||
}else if(List.class.isAssignableFrom(clazz)){
|
||||
return Datatype.List;
|
||||
}else if(clazz.equals(long.class)){
|
||||
return Datatype.Long;
|
||||
}else if(clazz.equals(Long.class)){
|
||||
return Datatype.Long;
|
||||
}else if(Map.class.isAssignableFrom(clazz)){
|
||||
return Datatype.Map;
|
||||
}else if(Set.class.isAssignableFrom(clazz)){
|
||||
return Datatype.Set;
|
||||
}else{
|
||||
return Datatype.Object;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String url() {
|
||||
return "/actioneditor";
|
||||
}
|
||||
|
||||
}
|
||||
+85
@@ -0,0 +1,85 @@
|
||||
/*******************************************************************************
|
||||
* Copyright 2017 Bstek
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
||||
* use this file except in compliance with the License. You may obtain a copy
|
||||
* of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations under
|
||||
* the License.
|
||||
******************************************************************************/
|
||||
package com.itheima.sfbx.rule.console.servlet.client;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.apache.velocity.Template;
|
||||
import org.apache.velocity.VelocityContext;
|
||||
|
||||
import com.itheima.sfbx.framework.rule.RuleException;
|
||||
import com.itheima.sfbx.framework.rule.Utils;
|
||||
import com.itheima.sfbx.rule.console.EnvironmentUtils;
|
||||
import com.itheima.sfbx.rule.console.User;
|
||||
import com.itheima.sfbx.rule.console.repository.RepositoryService;
|
||||
import com.itheima.sfbx.rule.console.repository.RepositoryServiceImpl;
|
||||
import com.itheima.sfbx.rule.console.servlet.RenderPageServletHandler;
|
||||
import com.itheima.sfbx.rule.console.servlet.RequestContext;
|
||||
|
||||
/**
|
||||
* @author Jacky.gao
|
||||
* @since 2016年8月11日
|
||||
*/
|
||||
public class ClientConfigServletHandler extends RenderPageServletHandler{
|
||||
private RepositoryService repositoryService;
|
||||
@Override
|
||||
public void execute(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
|
||||
String method=retriveMethod(req);
|
||||
if(method!=null){
|
||||
invokeMethod(method, req, resp);
|
||||
}else{
|
||||
VelocityContext context = new VelocityContext();
|
||||
context.put("contextPath", req.getContextPath());
|
||||
resp.setContentType("text/html");
|
||||
resp.setCharacterEncoding("utf-8");
|
||||
Template template=ve.getTemplate("html/client-config-editor.html","utf-8");
|
||||
PrintWriter writer=resp.getWriter();
|
||||
template.merge(context, writer);
|
||||
writer.close();
|
||||
}
|
||||
}
|
||||
public void loadData(HttpServletRequest req, HttpServletResponse resp) throws Exception {
|
||||
String project=req.getParameter("project");
|
||||
project=Utils.decodeURL(project);
|
||||
writeObjectToJson(resp, repositoryService.loadClientConfigs(project));
|
||||
}
|
||||
public void save(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
|
||||
String project=req.getParameter("project");
|
||||
project=Utils.decodeURL(project);
|
||||
String file=project+"/"+RepositoryServiceImpl.CLIENT_CONFIG_FILE;
|
||||
String content=req.getParameter("content");
|
||||
User user=EnvironmentUtils.getLoginUser(new RequestContext(req, resp));
|
||||
try{
|
||||
repositoryService.saveFile(file, content, false,null,user);
|
||||
}catch(Exception ex){
|
||||
throw new RuleException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
public void setRepositoryService(RepositoryService repositoryService) {
|
||||
this.repositoryService = repositoryService;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String url() {
|
||||
return "/clientconfig";
|
||||
}
|
||||
}
|
||||
+384
@@ -0,0 +1,384 @@
|
||||
/*******************************************************************************
|
||||
* Copyright 2017 Bstek
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
||||
* use this file except in compliance with the License. You may obtain a copy
|
||||
* of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations under
|
||||
* the License.
|
||||
******************************************************************************/
|
||||
package com.itheima.sfbx.rule.console.servlet.common;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.antlr.v4.runtime.ANTLRInputStream;
|
||||
import org.antlr.v4.runtime.CommonTokenStream;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.dom4j.Document;
|
||||
import org.dom4j.DocumentException;
|
||||
import org.dom4j.Element;
|
||||
import org.dom4j.io.SAXReader;
|
||||
import org.springframework.beans.BeansException;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
|
||||
import com.itheima.sfbx.framework.rule.RuleException;
|
||||
import com.itheima.sfbx.framework.rule.Utils;
|
||||
import com.itheima.sfbx.rule.console.EnvironmentUtils;
|
||||
import com.itheima.sfbx.rule.console.User;
|
||||
import com.itheima.sfbx.rule.console.repository.Repository;
|
||||
import com.itheima.sfbx.rule.console.repository.RepositoryResourceProvider;
|
||||
import com.itheima.sfbx.rule.console.repository.RepositoryService;
|
||||
import com.itheima.sfbx.rule.console.repository.model.FileType;
|
||||
import com.itheima.sfbx.rule.console.servlet.RenderPageServletHandler;
|
||||
import com.itheima.sfbx.rule.console.servlet.RequestContext;
|
||||
import com.itheima.sfbx.framework.rule.dsl.RuleParserLexer;
|
||||
import com.itheima.sfbx.framework.rule.dsl.RuleParserParser;
|
||||
import com.itheima.sfbx.framework.rule.model.function.FunctionDescriptor;
|
||||
import com.itheima.sfbx.framework.rule.model.library.action.ActionLibrary;
|
||||
import com.itheima.sfbx.framework.rule.model.library.action.SpringBean;
|
||||
import com.itheima.sfbx.framework.rule.parse.deserializer.ActionLibraryDeserializer;
|
||||
import com.itheima.sfbx.framework.rule.parse.deserializer.ConstantLibraryDeserializer;
|
||||
import com.itheima.sfbx.framework.rule.parse.deserializer.DecisionTableDeserializer;
|
||||
import com.itheima.sfbx.framework.rule.parse.deserializer.DecisionTreeDeserializer;
|
||||
import com.itheima.sfbx.framework.rule.parse.deserializer.Deserializer;
|
||||
import com.itheima.sfbx.framework.rule.parse.deserializer.ParameterLibraryDeserializer;
|
||||
import com.itheima.sfbx.framework.rule.parse.deserializer.RuleSetDeserializer;
|
||||
import com.itheima.sfbx.framework.rule.parse.deserializer.ScorecardDeserializer;
|
||||
import com.itheima.sfbx.framework.rule.parse.deserializer.ScriptDecisionTableDeserializer;
|
||||
import com.itheima.sfbx.framework.rule.parse.deserializer.VariableLibraryDeserializer;
|
||||
import com.itheima.sfbx.framework.rule.runtime.BuiltInActionLibraryBuilder;
|
||||
|
||||
/**
|
||||
* @author Jacky.gao
|
||||
* @since 2016年7月25日
|
||||
*/
|
||||
public class CommonServletHandler extends RenderPageServletHandler{
|
||||
private RepositoryService repositoryService;
|
||||
private BuiltInActionLibraryBuilder builtInActionLibraryBuilder;
|
||||
private List<Deserializer<?>> deserializers=new ArrayList<Deserializer<?>>();
|
||||
private List<FunctionDescriptor> functionDescriptors=new ArrayList<FunctionDescriptor>();
|
||||
|
||||
@Override
|
||||
public void execute(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
|
||||
String method=retriveMethod(req);
|
||||
if(method!=null){
|
||||
invokeMethod(method, req, resp);
|
||||
}else{
|
||||
throw new ServletException("Unsupport this operation.");
|
||||
}
|
||||
}
|
||||
public void saveFile(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
|
||||
String file=req.getParameter("file");
|
||||
String content = Utils.decodeURL(req.getParameter("content"));
|
||||
String versionComment=req.getParameter("versionComment");
|
||||
Boolean newVersion = Boolean.valueOf(req.getParameter("newVersion"));
|
||||
User user=EnvironmentUtils.getLoginUser(new RequestContext(req, resp));
|
||||
try{
|
||||
repositoryService.saveFile(file,content,newVersion,versionComment,user);
|
||||
}catch(Exception ex){
|
||||
throw new RuleException(ex);
|
||||
}
|
||||
}
|
||||
public void loadReferenceFiles(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
|
||||
String path=req.getParameter("path");
|
||||
path=Utils.decodeURL(path);
|
||||
String searchText=buildSearchText(path,req,false);
|
||||
try{
|
||||
List<String> files=repositoryService.getReferenceFiles(path,searchText);
|
||||
searchText=buildSearchText(path,req,true);
|
||||
List<String> scriptFiles=repositoryService.getReferenceFiles(path,searchText);
|
||||
if(scriptFiles.size()>0){
|
||||
files.addAll(scriptFiles);
|
||||
}
|
||||
List<RefFile> refFiles=new ArrayList<RefFile>();
|
||||
for(String file:files){
|
||||
RefFile ref=new RefFile();
|
||||
refFiles.add(ref);
|
||||
ref.setPath(file);
|
||||
if(file.endsWith(FileType.Ruleset.toString())){
|
||||
ref.setEditor("/ruleseteditor");
|
||||
ref.setType("决策集");
|
||||
}else if(file.endsWith(FileType.UL.toString())){
|
||||
ref.setEditor("/uleditor");
|
||||
ref.setType("脚本决策集");
|
||||
}else if(file.endsWith(FileType.DecisionTable.toString())){
|
||||
ref.setEditor("/decisiontableeditor");
|
||||
ref.setType("决策表");
|
||||
}else if(file.endsWith(FileType.ScriptDecisionTable.toString())){
|
||||
ref.setEditor("/scriptdecisiontableeditor");
|
||||
ref.setType("脚本决策表");
|
||||
}else if(file.endsWith(FileType.DecisionTree.toString())){
|
||||
ref.setEditor("/decisiontreeeditor");
|
||||
ref.setType("决策树");
|
||||
}else if(file.endsWith(FileType.RuleFlow.toString())){
|
||||
ref.setEditor("/ruleflowdesigner");
|
||||
ref.setType("决策流");
|
||||
}
|
||||
int pos=file.lastIndexOf("/");
|
||||
String name=file;
|
||||
if(pos>-1){
|
||||
name=file.substring(pos+1,file.length());
|
||||
}
|
||||
ref.setName(name);
|
||||
}
|
||||
writeObjectToJson(resp, refFiles);
|
||||
}catch(Exception ex){
|
||||
throw new RuleException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
private String buildSearchText(String path,HttpServletRequest req,boolean isScript){
|
||||
StringBuilder sb=new StringBuilder();
|
||||
if(path.endsWith(FileType.ActionLibrary.toString())){
|
||||
if(isScript){
|
||||
sb.append(req.getParameter("beanLabel"));
|
||||
sb.append(".");
|
||||
sb.append(req.getParameter("methodLabel"));
|
||||
}else{
|
||||
sb.append("bean=\""+req.getParameter("beanName")+"\"");
|
||||
sb.append(" bean-label=\""+req.getParameter("beanLabel")+"\"");
|
||||
sb.append(" method-label=\""+req.getParameter("methodLabel")+"\"");
|
||||
sb.append(" method-name=\""+req.getParameter("methodName")+"\"");
|
||||
}
|
||||
return sb.toString();
|
||||
}else if(path.endsWith(FileType.ConstantLibrary.toString())){
|
||||
if(isScript){
|
||||
sb.append(req.getParameter("constCategoryLabel"));
|
||||
sb.append(".");
|
||||
sb.append(req.getParameter("constLabel"));
|
||||
}else{
|
||||
sb.append("const-category=\""+req.getParameter("constCategoryLabel")+"\"");
|
||||
sb.append(" const=\""+req.getParameter("constName")+"\"");
|
||||
}
|
||||
return sb.toString();
|
||||
}else if(path.endsWith(FileType.ParameterLibrary.toString())){
|
||||
if(isScript){
|
||||
sb.append("参数.");
|
||||
sb.append(req.getParameter("varLabel"));
|
||||
}else{
|
||||
sb.append("var-category=\"参数\"");
|
||||
sb.append(" var=\""+req.getParameter("varName")+"\"");
|
||||
}
|
||||
return sb.toString();
|
||||
}else if(path.endsWith(FileType.VariableLibrary.toString())){
|
||||
if(isScript){
|
||||
sb.append(req.getParameter("varCategory"));
|
||||
sb.append(".");
|
||||
sb.append(req.getParameter("varLabel"));
|
||||
}else{
|
||||
sb.append("var-category=\""+req.getParameter("varCategory")+"\"");
|
||||
sb.append(" var=\""+req.getParameter("varName")+"\"");
|
||||
}
|
||||
return sb.toString();
|
||||
|
||||
}else{
|
||||
throw new RuleException("Unknow file : "+ path);
|
||||
}
|
||||
}
|
||||
|
||||
public void loadResourceTreeData(HttpServletRequest req, HttpServletResponse resp) throws Exception {
|
||||
String project=req.getParameter("project");
|
||||
project=Utils.decodeURL(project);
|
||||
String forLib=req.getParameter("forLib");
|
||||
String fileType=req.getParameter("fileType");
|
||||
String searchFileName=req.getParameter("searchFileName");
|
||||
|
||||
User user=EnvironmentUtils.getLoginUser(new RequestContext(req,resp));
|
||||
FileType[] types=null;
|
||||
if(StringUtils.isNotBlank(forLib) && forLib.equals("true")){
|
||||
types=new FileType[]{FileType.ActionLibrary,FileType.ConstantLibrary,FileType.VariableLibrary,FileType.ParameterLibrary};
|
||||
}else if(StringUtils.isNotBlank(fileType)){
|
||||
String[] fileTypes=fileType.split(",");
|
||||
types=new FileType[fileTypes.length];
|
||||
for(int i=0;i<fileTypes.length;i++){
|
||||
types[i]=FileType.valueOf(fileTypes[i]);
|
||||
}
|
||||
}else{
|
||||
types=new FileType[]{FileType.UL,FileType.Ruleset,FileType.RuleFlow,FileType.DecisionTable,FileType.ScriptDecisionTable,FileType.DecisionTree,FileType.Scorecard};
|
||||
}
|
||||
try{
|
||||
Repository repo=repositoryService.loadRepository(project,user,false,types,searchFileName);
|
||||
writeObjectToJson(resp, repo.getRootFile());
|
||||
}catch(Exception ex){
|
||||
throw new RuleException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
public void loadFunctions(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
|
||||
writeObjectToJson(resp, functionDescriptors);
|
||||
}
|
||||
|
||||
public void scriptValidation(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
|
||||
String content=req.getParameter("content");
|
||||
if(StringUtils.isNotBlank(content)){
|
||||
ScriptType type=ScriptType.valueOf(req.getParameter("type"));
|
||||
ANTLRInputStream antlrInputStream=new ANTLRInputStream(content);
|
||||
RuleParserLexer lexer=new RuleParserLexer(antlrInputStream);
|
||||
CommonTokenStream steam=new CommonTokenStream(lexer);
|
||||
RuleParserParser parser=new RuleParserParser(steam);
|
||||
parser.removeErrorListeners();
|
||||
ScriptErrorListener errorListener=new ScriptErrorListener();
|
||||
parser.addErrorListener(errorListener);
|
||||
switch(type){
|
||||
case Script:
|
||||
parser.ruleSet();
|
||||
break;
|
||||
case DecisionNode:
|
||||
parser.condition();
|
||||
break;
|
||||
case ScriptNode:
|
||||
parser.actions();
|
||||
|
||||
}
|
||||
List<ErrorInfo> infos=errorListener.getInfos();
|
||||
writeObjectToJson(resp, infos);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void loadXml(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
|
||||
List<Object> result=new ArrayList<Object>();
|
||||
String files=req.getParameter("files");
|
||||
files=Utils.decodeURL(files);
|
||||
boolean isaction=false;
|
||||
if(files!=null){
|
||||
if(files.startsWith("builtinactions")){
|
||||
isaction=true;
|
||||
}else{
|
||||
String[] paths=files.split(";");
|
||||
for(String path:paths){
|
||||
if(path.startsWith(RepositoryResourceProvider.JCR)){
|
||||
path=path.substring(4,path.length());
|
||||
}
|
||||
String[] subpaths=path.split(",");
|
||||
path=subpaths[0];
|
||||
String version=null;
|
||||
if(subpaths.length==2){
|
||||
version=subpaths[1];
|
||||
}
|
||||
try{
|
||||
InputStream inputStream=null;
|
||||
if(StringUtils.isEmpty(version)){
|
||||
inputStream=repositoryService.readFile(path,null);
|
||||
}else{
|
||||
inputStream=repositoryService.readFile(path,version);
|
||||
}
|
||||
// System.out.println(getStringByInputStream_1(inputStream));
|
||||
Element element=parseXml(inputStream);
|
||||
for(Deserializer<?> des:deserializers){
|
||||
if(des.support(element)){
|
||||
result.add(des.deserialize(element));
|
||||
if(des instanceof ActionLibraryDeserializer){
|
||||
isaction=true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
inputStream.close();
|
||||
}catch(Exception ex){
|
||||
throw new RuleException(ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if(isaction){
|
||||
List<SpringBean> beans=builtInActionLibraryBuilder.getBuiltInActions();
|
||||
if(beans.size()>0){
|
||||
ActionLibrary al=new ActionLibrary();
|
||||
al.setSpringBeans(beans);
|
||||
result.add(al);
|
||||
}
|
||||
}
|
||||
writeObjectToJson(resp, result);
|
||||
}
|
||||
|
||||
protected Element parseXml(InputStream stream){
|
||||
SAXReader reader=new SAXReader();
|
||||
Document document;
|
||||
try {
|
||||
document = reader.read(stream);
|
||||
Element root=document.getRootElement();
|
||||
return root;
|
||||
} catch (DocumentException e) {
|
||||
throw new RuleException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public void setBuiltInActionLibraryBuilder(BuiltInActionLibraryBuilder builtInActionLibraryBuilder) {
|
||||
this.builtInActionLibraryBuilder = builtInActionLibraryBuilder;
|
||||
}
|
||||
public void setRepositoryService(RepositoryService repositoryService) {
|
||||
this.repositoryService = repositoryService;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String url() {
|
||||
return "/common";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
|
||||
super.setApplicationContext(applicationContext);
|
||||
ActionLibraryDeserializer actionLibraryDeserializer=(ActionLibraryDeserializer)applicationContext.getBean(ActionLibraryDeserializer.BEAN_ID);
|
||||
VariableLibraryDeserializer variableLibraryDeserializer=(VariableLibraryDeserializer)applicationContext.getBean(VariableLibraryDeserializer.BEAN_ID);
|
||||
ConstantLibraryDeserializer constantLibraryDeserializer=(ConstantLibraryDeserializer)applicationContext.getBean(ConstantLibraryDeserializer.BEAN_ID);
|
||||
RuleSetDeserializer ruleSetDeserializer=(RuleSetDeserializer)applicationContext.getBean(RuleSetDeserializer.BEAN_ID);
|
||||
DecisionTableDeserializer decisionTableDeserializer=(DecisionTableDeserializer)applicationContext.getBean(DecisionTableDeserializer.BEAN_ID);
|
||||
ScriptDecisionTableDeserializer scriptDecisionTableDeserializer=(ScriptDecisionTableDeserializer)applicationContext.getBean(ScriptDecisionTableDeserializer.BEAN_ID);
|
||||
DecisionTreeDeserializer decisionTreeDeserializer=(DecisionTreeDeserializer)applicationContext.getBean(DecisionTreeDeserializer.BEAN_ID);
|
||||
ScorecardDeserializer scorecardDeserializer=(ScorecardDeserializer)applicationContext.getBean(ScorecardDeserializer.BEAN_ID);
|
||||
|
||||
ParameterLibraryDeserializer parameterLibraryDeserializer=(ParameterLibraryDeserializer)applicationContext.getBean(ParameterLibraryDeserializer.BEAN_ID);
|
||||
deserializers.add(actionLibraryDeserializer);
|
||||
deserializers.add(variableLibraryDeserializer);
|
||||
deserializers.add(constantLibraryDeserializer);
|
||||
deserializers.add(ruleSetDeserializer);
|
||||
deserializers.add(decisionTableDeserializer);
|
||||
deserializers.add(scriptDecisionTableDeserializer);
|
||||
deserializers.add(decisionTreeDeserializer);
|
||||
deserializers.add(parameterLibraryDeserializer);
|
||||
deserializers.add(scorecardDeserializer);
|
||||
|
||||
Collection<FunctionDescriptor> coll=applicationContext.getBeansOfType(FunctionDescriptor.class).values();
|
||||
for(FunctionDescriptor fun:coll){
|
||||
if(fun.isDisabled()){
|
||||
continue;
|
||||
}
|
||||
functionDescriptors.add(fun);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static String getStringByInputStream_1(InputStream inputStream) {
|
||||
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
||||
try {
|
||||
byte[] b = new byte[10240];
|
||||
int n;
|
||||
while ((n = inputStream.read(b)) != -1) {
|
||||
outputStream.write(b, 0, n);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
try {
|
||||
inputStream.close();
|
||||
outputStream.close();
|
||||
} catch (Exception e1) {
|
||||
}
|
||||
}
|
||||
return outputStream.toString();
|
||||
}
|
||||
}
|
||||
+49
@@ -0,0 +1,49 @@
|
||||
/*******************************************************************************
|
||||
* Copyright 2017 Bstek
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
||||
* use this file except in compliance with the License. You may obtain a copy
|
||||
* of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations under
|
||||
* the License.
|
||||
******************************************************************************/
|
||||
package com.itheima.sfbx.rule.console.servlet.common;
|
||||
/**
|
||||
* @author Jacky.gao
|
||||
* @since 2016年7月26日
|
||||
*/
|
||||
public class ErrorInfo {
|
||||
private int line;
|
||||
private int charPositionInLine;
|
||||
private String message;
|
||||
|
||||
public ErrorInfo(int line,int charPositionInLine,String message) {
|
||||
this.line = line;
|
||||
this.charPositionInLine=charPositionInLine;
|
||||
this.message = message;
|
||||
}
|
||||
public int getLine() {
|
||||
return line;
|
||||
}
|
||||
public void setLine(int line) {
|
||||
this.line = line;
|
||||
}
|
||||
public String getMessage() {
|
||||
return message;
|
||||
}
|
||||
public void setMessage(String message) {
|
||||
this.message = message;
|
||||
}
|
||||
public int getCharPositionInLine() {
|
||||
return charPositionInLine;
|
||||
}
|
||||
public void setCharPositionInLine(int charPositionInLine) {
|
||||
this.charPositionInLine = charPositionInLine;
|
||||
}
|
||||
}
|
||||
+51
@@ -0,0 +1,51 @@
|
||||
/*******************************************************************************
|
||||
* Copyright 2017 Bstek
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
||||
* use this file except in compliance with the License. You may obtain a copy
|
||||
* of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations under
|
||||
* the License.
|
||||
******************************************************************************/
|
||||
package com.itheima.sfbx.rule.console.servlet.common;
|
||||
/**
|
||||
* @author Jacky.gao
|
||||
* @since 2016年8月9日
|
||||
*/
|
||||
public class RefFile {
|
||||
private String name;
|
||||
private String path;
|
||||
private String editor;
|
||||
private String type;
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
public String getPath() {
|
||||
return path;
|
||||
}
|
||||
public void setPath(String path) {
|
||||
this.path = path;
|
||||
}
|
||||
public String getEditor() {
|
||||
return editor;
|
||||
}
|
||||
public void setEditor(String editor) {
|
||||
this.editor = editor;
|
||||
}
|
||||
public String getType() {
|
||||
return type;
|
||||
}
|
||||
public void setType(String type) {
|
||||
this.type = type;
|
||||
}
|
||||
}
|
||||
+38
@@ -0,0 +1,38 @@
|
||||
/*******************************************************************************
|
||||
* Copyright 2017 Bstek
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
||||
* use this file except in compliance with the License. You may obtain a copy
|
||||
* of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations under
|
||||
* the License.
|
||||
******************************************************************************/
|
||||
package com.itheima.sfbx.rule.console.servlet.common;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.antlr.v4.runtime.BaseErrorListener;
|
||||
import org.antlr.v4.runtime.RecognitionException;
|
||||
import org.antlr.v4.runtime.Recognizer;
|
||||
|
||||
/**
|
||||
* @author Jacky.gao
|
||||
* @since 2016年7月26日
|
||||
*/
|
||||
public class ScriptErrorListener extends BaseErrorListener {
|
||||
private List<ErrorInfo> infos=new ArrayList<ErrorInfo>();
|
||||
@Override
|
||||
public void syntaxError(Recognizer<?, ?> recognizer,Object offendingSymbol, int line, int charPositionInLine,String msg, RecognitionException e) {
|
||||
infos.add(new ErrorInfo(line,charPositionInLine,msg));
|
||||
}
|
||||
public List<ErrorInfo> getInfos() {
|
||||
return infos;
|
||||
}
|
||||
}
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
/*******************************************************************************
|
||||
* Copyright 2017 Bstek
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
||||
* use this file except in compliance with the License. You may obtain a copy
|
||||
* of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations under
|
||||
* the License.
|
||||
******************************************************************************/
|
||||
package com.itheima.sfbx.rule.console.servlet.common;
|
||||
/**
|
||||
* @author Jacky.gao
|
||||
* @since 2016年7月26日
|
||||
*/
|
||||
public enum ScriptType {
|
||||
DecisionNode,ScriptNode,Script;
|
||||
}
|
||||
+43
@@ -0,0 +1,43 @@
|
||||
/*******************************************************************************
|
||||
* Copyright 2017 Bstek
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
||||
* use this file except in compliance with the License. You may obtain a copy
|
||||
* of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations under
|
||||
* the License.
|
||||
******************************************************************************/
|
||||
package com.itheima.sfbx.rule.console.servlet.console;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
import com.itheima.sfbx.framework.rule.debug.DebugWriter;
|
||||
import com.itheima.sfbx.framework.rule.debug.MessageItem;
|
||||
|
||||
/**
|
||||
* @author Jacky.gao
|
||||
* @since 2017年11月28日
|
||||
*/
|
||||
public class ConsoleDebugWriter implements DebugWriter {
|
||||
private DebugMessageHolder debugMessageHolder;
|
||||
@Override
|
||||
public void write(List<MessageItem> items) throws IOException {
|
||||
StringBuilder sb=new StringBuilder();
|
||||
for(MessageItem item:items){
|
||||
sb.append(item.toHtml());
|
||||
}
|
||||
String key=debugMessageHolder.generateKey();
|
||||
System.out.println("Console key : "+key);
|
||||
debugMessageHolder.putDebugMessage(key, sb.toString());
|
||||
}
|
||||
public void setDebugMessageHolder(DebugMessageHolder debugMessageHolder) {
|
||||
this.debugMessageHolder = debugMessageHolder;
|
||||
}
|
||||
}
|
||||
+65
@@ -0,0 +1,65 @@
|
||||
/*******************************************************************************
|
||||
* Copyright 2017 Bstek
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
||||
* use this file except in compliance with the License. You may obtain a copy
|
||||
* of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations under
|
||||
* the License.
|
||||
******************************************************************************/
|
||||
package com.itheima.sfbx.rule.console.servlet.console;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.apache.velocity.Template;
|
||||
import org.apache.velocity.VelocityContext;
|
||||
|
||||
import com.itheima.sfbx.rule.console.servlet.RenderPageServletHandler;
|
||||
|
||||
/**
|
||||
* @author Jacky.gao
|
||||
* @since 2017年11月28日
|
||||
*/
|
||||
public class ConsoleServletHandler extends RenderPageServletHandler {
|
||||
private DebugMessageHolder debugMessageHolder;
|
||||
@Override
|
||||
public void execute(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
|
||||
String key=req.getParameter("key");
|
||||
String msg=null;
|
||||
if(StringUtils.isBlank(key)){
|
||||
msg="<h2 style='color:red'>请指定要查看的调试消息的key值</h2>";
|
||||
}else{
|
||||
msg=debugMessageHolder.getDebugMessage(key);
|
||||
}
|
||||
VelocityContext context = new VelocityContext();
|
||||
context.put("title", "URule Console");
|
||||
context.put("msg", msg);
|
||||
resp.setContentType("text/html");
|
||||
resp.setCharacterEncoding("utf-8");
|
||||
Template template=ve.getTemplate("html/console.html","utf-8");
|
||||
PrintWriter writer=resp.getWriter();
|
||||
template.merge(context, writer);
|
||||
writer.close();
|
||||
}
|
||||
|
||||
public void setDebugMessageHolder(DebugMessageHolder debugMessageHolder) {
|
||||
this.debugMessageHolder = debugMessageHolder;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String url() {
|
||||
return "/console";
|
||||
}
|
||||
}
|
||||
+35
@@ -0,0 +1,35 @@
|
||||
/*******************************************************************************
|
||||
* Copyright 2017 Bstek
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
||||
* use this file except in compliance with the License. You may obtain a copy
|
||||
* of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations under
|
||||
* the License.
|
||||
******************************************************************************/
|
||||
package com.itheima.sfbx.rule.console.servlet.console;
|
||||
|
||||
/**
|
||||
* @author Jacky.gao
|
||||
* @since 2017年11月28日
|
||||
*/
|
||||
public class DebugMessage {
|
||||
private String message;
|
||||
private long timestamp;
|
||||
public DebugMessage(String message) {
|
||||
this.message=message;
|
||||
this.timestamp=System.currentTimeMillis();
|
||||
}
|
||||
public String getMessage() {
|
||||
return message;
|
||||
}
|
||||
public long getTimestamp() {
|
||||
return timestamp;
|
||||
}
|
||||
}
|
||||
+64
@@ -0,0 +1,64 @@
|
||||
/*******************************************************************************
|
||||
* Copyright 2017 Bstek
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
||||
* use this file except in compliance with the License. You may obtain a copy
|
||||
* of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations under
|
||||
* the License.
|
||||
******************************************************************************/
|
||||
package com.itheima.sfbx.rule.console.servlet.console;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author Jacky.gao
|
||||
* @since 2017年11月28日
|
||||
*/
|
||||
public class DebugMessageHolder {
|
||||
private int num=0;
|
||||
private Map<String,DebugMessage> messageMap=new HashMap<String,DebugMessage>();
|
||||
public String getDebugMessage(String key){
|
||||
DebugMessage msg=messageMap.get(key);
|
||||
String info=null;
|
||||
if(msg==null){
|
||||
info="<h2 style='color:red'>Key为["+key+"]的调试信息已失效,不能查看,当前key值为:"+this.num+"。<br>调试消息有效期为3分钟,请在有效期内查看!</h2>";
|
||||
}else{
|
||||
info=msg.getMessage();
|
||||
}
|
||||
clean();
|
||||
return info;
|
||||
}
|
||||
public void putDebugMessage(String key,String msg){
|
||||
clean();
|
||||
DebugMessage m=new DebugMessage(msg);
|
||||
messageMap.put(key, m);
|
||||
}
|
||||
private void clean(){
|
||||
long current=System.currentTimeMillis();
|
||||
List<String> list=new ArrayList<String>();
|
||||
for(String key:messageMap.keySet()){
|
||||
DebugMessage msg=messageMap.get(key);
|
||||
long dif=current-msg.getTimestamp();
|
||||
if(dif>180000){
|
||||
list.add(key);
|
||||
}
|
||||
}
|
||||
for(String key:list){
|
||||
messageMap.remove(key);
|
||||
}
|
||||
}
|
||||
public synchronized String generateKey(){
|
||||
num++;
|
||||
return String.valueOf(num);
|
||||
}
|
||||
}
|
||||
+52
@@ -0,0 +1,52 @@
|
||||
/*******************************************************************************
|
||||
* Copyright 2017 Bstek
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
||||
* use this file except in compliance with the License. You may obtain a copy
|
||||
* of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations under
|
||||
* the License.
|
||||
******************************************************************************/
|
||||
package com.itheima.sfbx.rule.console.servlet.constant;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.apache.velocity.Template;
|
||||
import org.apache.velocity.VelocityContext;
|
||||
|
||||
import com.itheima.sfbx.rule.console.servlet.RenderPageServletHandler;
|
||||
|
||||
public class ConstantServletHandler extends RenderPageServletHandler{
|
||||
@Override
|
||||
public void execute(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
|
||||
String method=retriveMethod(req);
|
||||
if(method!=null){
|
||||
invokeMethod(method, req, resp);
|
||||
}else{
|
||||
VelocityContext context = new VelocityContext();
|
||||
context.put("contextPath", req.getContextPath());
|
||||
resp.setContentType("text/html");
|
||||
resp.setCharacterEncoding("utf-8");
|
||||
Template template=ve.getTemplate("html/constant-editor.html","utf-8");
|
||||
PrintWriter writer=resp.getWriter();
|
||||
template.merge(context, writer);
|
||||
writer.close();
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public String url() {
|
||||
return "/constanteditor";
|
||||
}
|
||||
|
||||
}
|
||||
+60
@@ -0,0 +1,60 @@
|
||||
/*******************************************************************************
|
||||
* Copyright 2017 Bstek
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
||||
* use this file except in compliance with the License. You may obtain a copy
|
||||
* of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations under
|
||||
* the License.
|
||||
******************************************************************************/
|
||||
package com.itheima.sfbx.rule.console.servlet.decisiontable;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.apache.velocity.Template;
|
||||
import org.apache.velocity.VelocityContext;
|
||||
|
||||
import com.itheima.sfbx.rule.console.servlet.RenderPageServletHandler;
|
||||
|
||||
/**
|
||||
* @author Jacky.gao
|
||||
* @since 2016年8月1日
|
||||
*/
|
||||
public class DecisiontableEditorServletHandler extends RenderPageServletHandler{
|
||||
@Override
|
||||
public void execute(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
|
||||
String method=retriveMethod(req);
|
||||
if(method!=null){
|
||||
invokeMethod(method, req, resp);
|
||||
}else{
|
||||
VelocityContext context = new VelocityContext();
|
||||
context.put("contextPath", req.getContextPath());
|
||||
String file=req.getParameter("file");
|
||||
String project = buildProjectNameFromFile(file);
|
||||
if(project!=null){
|
||||
context.put("project", project);
|
||||
}
|
||||
resp.setContentType("text/html");
|
||||
resp.setCharacterEncoding("utf-8");
|
||||
Template template=ve.getTemplate("html/decisiontable-editor.html","utf-8");
|
||||
PrintWriter writer=resp.getWriter();
|
||||
template.merge(context, writer);
|
||||
writer.close();
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public String url() {
|
||||
return "/decisiontableeditor";
|
||||
}
|
||||
}
|
||||
+60
@@ -0,0 +1,60 @@
|
||||
/*******************************************************************************
|
||||
* Copyright 2017 Bstek
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
||||
* use this file except in compliance with the License. You may obtain a copy
|
||||
* of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations under
|
||||
* the License.
|
||||
******************************************************************************/
|
||||
package com.itheima.sfbx.rule.console.servlet.decisiontree;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.apache.velocity.Template;
|
||||
import org.apache.velocity.VelocityContext;
|
||||
|
||||
import com.itheima.sfbx.rule.console.servlet.RenderPageServletHandler;
|
||||
|
||||
/**
|
||||
* @author Jacky.gao
|
||||
* @since 2016年8月1日
|
||||
*/
|
||||
public class DecisionTreeEditorServletHandler extends RenderPageServletHandler{
|
||||
@Override
|
||||
public void execute(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
|
||||
String method=retriveMethod(req);
|
||||
if(method!=null){
|
||||
invokeMethod(method, req, resp);
|
||||
}else{
|
||||
VelocityContext context = new VelocityContext();
|
||||
context.put("contextPath", req.getContextPath());
|
||||
String file=req.getParameter("file");
|
||||
String project = buildProjectNameFromFile(file);
|
||||
if(project!=null){
|
||||
context.put("project", project);
|
||||
}
|
||||
resp.setContentType("text/html");
|
||||
resp.setCharacterEncoding("utf-8");
|
||||
Template template=ve.getTemplate("html/decisiontree-editor.html","utf-8");
|
||||
PrintWriter writer=resp.getWriter();
|
||||
template.merge(context, writer);
|
||||
writer.close();
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public String url() {
|
||||
return "/decisiontreeeditor";
|
||||
}
|
||||
}
|
||||
+36
@@ -0,0 +1,36 @@
|
||||
/*******************************************************************************
|
||||
* Copyright 2017 Bstek
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
||||
* use this file except in compliance with the License. You may obtain a copy
|
||||
* of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations under
|
||||
* the License.
|
||||
******************************************************************************/
|
||||
package com.itheima.sfbx.rule.console.servlet.diagram;
|
||||
/**
|
||||
* @author Jacky.gao
|
||||
* @since 2015年3月2日
|
||||
*/
|
||||
public class Box {
|
||||
private int width;
|
||||
private int height;
|
||||
public int getWidth() {
|
||||
return width;
|
||||
}
|
||||
public void setWidth(int width) {
|
||||
this.width = width;
|
||||
}
|
||||
public int getHeight() {
|
||||
return height;
|
||||
}
|
||||
public void setHeight(int height) {
|
||||
this.height = height;
|
||||
}
|
||||
}
|
||||
+57
@@ -0,0 +1,57 @@
|
||||
/*******************************************************************************
|
||||
* Copyright 2017 Bstek
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
||||
* use this file except in compliance with the License. You may obtain a copy
|
||||
* of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations under
|
||||
* the License.
|
||||
******************************************************************************/
|
||||
package com.itheima.sfbx.rule.console.servlet.diagram;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Jacky.gao
|
||||
* @since 2015年1月6日
|
||||
*/
|
||||
public class Diagram {
|
||||
private List<Edge> edges;
|
||||
private NodeInfo rootNode;
|
||||
private int width;
|
||||
private int height;
|
||||
public Diagram(List<Edge> edges, NodeInfo rootNode) {
|
||||
this.edges = edges;
|
||||
this.rootNode = rootNode;
|
||||
}
|
||||
public List<Edge> getEdges() {
|
||||
return edges;
|
||||
}
|
||||
public void setEdges(List<Edge> edges) {
|
||||
this.edges = edges;
|
||||
}
|
||||
public NodeInfo getRootNode() {
|
||||
return rootNode;
|
||||
}
|
||||
public void setRootNode(NodeInfo rootNode) {
|
||||
this.rootNode = rootNode;
|
||||
}
|
||||
public int getWidth() {
|
||||
return width;
|
||||
}
|
||||
public void setWidth(int width) {
|
||||
this.width = width;
|
||||
}
|
||||
public int getHeight() {
|
||||
return height;
|
||||
}
|
||||
public void setHeight(int height) {
|
||||
this.height = height;
|
||||
}
|
||||
}
|
||||
+52
@@ -0,0 +1,52 @@
|
||||
/*******************************************************************************
|
||||
* Copyright 2017 Bstek
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
||||
* use this file except in compliance with the License. You may obtain a copy
|
||||
* of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations under
|
||||
* the License.
|
||||
******************************************************************************/
|
||||
package com.itheima.sfbx.rule.console.servlet.diagram;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import com.itheima.sfbx.framework.rule.model.Node;
|
||||
|
||||
/**
|
||||
* @author Jacky.gao
|
||||
* @since 2015年1月6日
|
||||
*/
|
||||
public class DiagramContext {
|
||||
private int id;
|
||||
private List<Edge> edges;
|
||||
private Map<Node,NodeInfo> nodeMap;
|
||||
public DiagramContext(List<Edge> edges,Map<Node, NodeInfo> nodeMap) {
|
||||
this.edges = edges;
|
||||
this.nodeMap = nodeMap;
|
||||
}
|
||||
|
||||
public List<Edge> getEdges() {
|
||||
return edges;
|
||||
}
|
||||
public void addEdge(Edge edge) {
|
||||
edges.add(edge);
|
||||
}
|
||||
public Map<Node, NodeInfo> getNodeMap() {
|
||||
return nodeMap;
|
||||
}
|
||||
public void setNodeMap(Map<Node, NodeInfo> nodeMap) {
|
||||
this.nodeMap = nodeMap;
|
||||
}
|
||||
public int nextId(){
|
||||
id++;
|
||||
return id;
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user