提交 92836a13 编写于 作者: Z zhourui

remove index

上级 86da86ee
......@@ -922,7 +922,7 @@
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-slf4j-impl</artifactId>
<version>2.15</version>
<version>2.18.0</version>
</dependency>
<dependency>
<groupId>o2oa</groupId>
......
......@@ -490,25 +490,25 @@ public class Config {
return dir;
}
public static Path path_servers_webServer_x_desktop_res_config(Boolean force) throws Exception {
public static Path path_servers_webServer_x_desktop_res_config(boolean force) throws Exception {
Path path = Paths.get(base(), DIR_SERVERS_WEBSERVER_X_DESKTOP_RES_CONFIG);
if (!Files.exists(path)) {
if (!Files.exists(path) && force) {
Files.createDirectories(path);
}
return path;
}
public static Path path_config_coverToWebServer(Boolean force) throws Exception {
public static Path path_config_coverToWebServer(boolean force) throws Exception {
Path path = Paths.get(base(), DIR_CONFIG_COVERTOWEBSERVER);
if (!Files.exists(path)) {
if (!Files.exists(path) && force) {
Files.createDirectories(path);
}
return path;
}
public static Path path_servers_webServer(Boolean force) throws Exception {
public static Path path_servers_webServer(boolean force) throws Exception {
Path path = Paths.get(base(), DIR_SERVERS_WEBSERVER);
if (!Files.exists(path)) {
if (!Files.exists(path) && force) {
Files.createDirectories(path);
}
return path;
......
......@@ -63,7 +63,7 @@ public class ExtractTextTools {
public static final List<String> SUPPORT_IMAGE_TYPES = UnmodifiableList
.unmodifiableList(ListTools.toList(".bmp", ".jpg", ".png", ".gif", ".jpeg", "jpe"));
public static String extract(byte[] bytes, String name, Boolean office, Boolean pdf, Boolean txt, Boolean image)
public static String extract(byte[] bytes, String name, boolean office, boolean pdf, boolean txt, boolean image)
throws Exception {
if ((null != bytes) && bytes.length > 0 && bytes.length < 1024 * 1024 * 10) {
if (office) {
......@@ -74,26 +74,21 @@ public class ExtractTextTools {
return excel(bytes);
}
}
if (pdf) {
if (StringUtils.endsWithIgnoreCase(name, ".pdf")) {
return pdf(bytes);
}
if (pdf && StringUtils.endsWithIgnoreCase(name, ".pdf")) {
return pdf(bytes);
}
if (txt) {
if (StringUtils.endsWithIgnoreCase(name, ".txt")) {
return text(bytes);
}
if (txt && StringUtils.endsWithIgnoreCase(name, ".txt")) {
return text(bytes);
}
if (image) {
if (StringUtils.endsWithIgnoreCase(name, ".jpg") || StringUtils.endsWithIgnoreCase(name, ".png")
|| StringUtils.endsWithIgnoreCase(name, ".gif") || StringUtils.endsWithIgnoreCase(name, ".bmp")
|| StringUtils.endsWithIgnoreCase(name, ".jpeg")
|| StringUtils.endsWithIgnoreCase(name, ".jpe")) {
return image(bytes);
}
if (image && (StringUtils.endsWithIgnoreCase(name, ".jpg") || StringUtils.endsWithIgnoreCase(name, ".png")
|| StringUtils.endsWithIgnoreCase(name, ".gif") || StringUtils.endsWithIgnoreCase(name, ".bmp")
|| StringUtils.endsWithIgnoreCase(name, ".jpeg") || StringUtils.endsWithIgnoreCase(name, ".jpe"))) {
return image(bytes);
}
}
return null;
}
public static String pdf(byte[] bytes) {
......
......@@ -5,35 +5,6 @@ import com.x.base.core.project.annotation.Module;
import com.x.base.core.project.annotation.ModuleCategory;
import com.x.base.core.project.annotation.ModuleType;
//@Module(type = ModuleType.SERVICE, category = ModuleCategory.OFFICIAL, name = "流程服务", packageName = "com.x.processplatform.service.processing", containerEntities = {
// "com.x.processplatform.core.entity.content.Snap", "com.x.processplatform.core.entity.content.Draft",
// "com.x.processplatform.core.entity.content.Attachment",
// "com.x.processplatform.core.entity.content.TaskCompleted",
// "com.x.processplatform.core.entity.content.ReadCompleted", "com.x.processplatform.core.entity.content.Review",
// "com.x.processplatform.core.entity.content.Record", "com.x.processplatform.core.entity.content.WorkCompleted",
// "com.x.processplatform.core.entity.content.WorkLog", "com.x.processplatform.core.entity.content.Record",
// "com.x.processplatform.core.entity.content.Task", "com.x.processplatform.core.entity.content.Work",
// "com.x.processplatform.core.entity.content.Read", "com.x.processplatform.core.entity.content.DocumentVersion",
// "com.x.processplatform.core.entity.content.SerialNumber", "com.x.processplatform.core.entity.element.End",
// "com.x.processplatform.core.entity.content.DocSign", "com.x.processplatform.core.entity.content.DocSignScrawl",
// "com.x.processplatform.core.entity.element.Application",
// "com.x.processplatform.core.entity.element.ApplicationDict",
// "com.x.processplatform.core.entity.element.ApplicationDictItem",
// "com.x.processplatform.core.entity.element.Script", "com.x.processplatform.core.entity.element.Cancel",
// "com.x.processplatform.core.entity.element.Merge", "com.x.processplatform.core.entity.element.Route",
// "com.x.processplatform.core.entity.element.Choice", "com.x.processplatform.core.entity.element.Invoke",
// "com.x.processplatform.core.entity.element.Manual", "com.x.processplatform.core.entity.element.Parallel",
// "com.x.processplatform.core.entity.element.Begin", "com.x.processplatform.core.entity.element.Split",
// "com.x.processplatform.core.entity.element.Process", "com.x.processplatform.core.entity.element.Service",
// "com.x.processplatform.core.entity.element.Agent", "com.x.processplatform.core.entity.element.Delay",
// "com.x.processplatform.core.entity.element.File", "com.x.processplatform.core.entity.element.Form",
// "com.x.processplatform.core.entity.element.FormField", "com.x.processplatform.core.entity.element.Embed",
// "com.x.processplatform.core.entity.element.Mapping", "com.x.processplatform.core.entity.log.SignalStackLog",
// "com.x.query.core.entity.Item", "com.x.cms.core.entity.element.Script", "com.x.portal.core.entity.Script",
// "com.x.query.dynamic.entity.*" }, storageTypes = { StorageType.processPlatform }, storeJars = {
// "x_organization_core_entity", "x_organization_core_express", "x_processplatform_core_entity",
// "x_processplatform_core_express", "x_query_core_entity", "x_cms_core_entity",
// "x_portal_core_entity" }, dynamicJars = { "x_query_dynamic_entity" })
@Module(type = ModuleType.SERVICE, category = ModuleCategory.OFFICIAL, name = "流程服务", packageName = "com.x.processplatform.service.processing", containerEntities = {
"com.x.processplatform.core.entity.content.Snap", "com.x.processplatform.core.entity.content.Draft",
"com.x.processplatform.core.entity.content.Attachment",
......
......@@ -13,8 +13,8 @@ import com.x.base.core.project.annotation.ModuleType;
"com.x.query.core.entity.neural.OutText", "com.x.query.core.entity.neural.InValue",
"com.x.query.core.entity.neural.OutValue", "com.x.query.core.entity.neural.Model",
"com.x.query.core.entity.schema.*", "com.x.processplatform.core.entity.content.Review",
"com.x.query.core.entity.ImportModel",
"com.x.processplatform.core.entity.content.Work", "com.x.processplatform.core.entity.content.WorkCompleted",
"com.x.query.core.entity.ImportModel", "com.x.processplatform.core.entity.content.Work",
"com.x.processplatform.core.entity.content.WorkCompleted",
"com.x.processplatform.core.entity.content.Attachment", "com.x.cms.core.entity.Document",
"com.x.cms.core.entity.FileInfo", "com.x.cms.core.entity.AppInfo",
"com.x.cms.core.entity.CategoryInfo" }, storageTypes = { StorageType.processPlatform,
......
......@@ -103,12 +103,4 @@ public final class PersistenceProperties extends AbstractPersistenceProperties {
}
public static class Index {
public static class State {
public static final String table = "QRY_IDX_STATE";
}
}
}
package com.x.query.core.entity.index;
import java.util.Date;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.UniqueConstraint;
import com.x.base.core.entity.JpaObject;
import com.x.base.core.entity.SliceJpaObject;
import com.x.base.core.entity.annotation.CheckPersist;
import com.x.base.core.entity.annotation.ContainerEntity;
import com.x.base.core.entity.annotation.Flag;
import com.x.base.core.project.annotation.FieldDescribe;
import com.x.query.core.entity.PersistenceProperties;
@Entity
@ContainerEntity(dumpSize = 1000, type = ContainerEntity.Type.content, reference = ContainerEntity.Reference.strong)
@javax.persistence.Table(name = PersistenceProperties.Index.State.table, uniqueConstraints = {
@UniqueConstraint(name = PersistenceProperties.Index.State.table + JpaObject.IndexNameMiddle
+ JpaObject.DefaultUniqueConstraintSuffix, columnNames = { JpaObject.IDCOLUMN,
JpaObject.CREATETIMECOLUMN, JpaObject.UPDATETIMECOLUMN, JpaObject.SEQUENCECOLUMN }) })
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
public class State extends SliceJpaObject {
private static final long serialVersionUID = -5610293696763235753L;
private static final String TABLE = PersistenceProperties.Index.State.table;
public static final String TYPE_WORKCOMPLETED = "workCompleted";
public static final String TYPE_CMS = "cms";
public static final String FREQUENCY_LOW = "low";
public static final String FREQUENCY_HIGH = "high";
@Override
public String getId() {
return id;
}
@Override
public void setId(String id) {
this.id = id;
}
@FieldDescribe("数据库主键,自动生成.")
@Id
@Column(length = length_id, name = ColumnNamePrefix + id_FIELDNAME)
private String id = createId();
@Override
public void onPersist() throws Exception {
// nothing
}
public static final String LATESTID_FIELDNAME = "latestId";
@FieldDescribe("最后查询标识.")
@Column(length = JpaObject.length_id, name = ColumnNamePrefix + LATESTID_FIELDNAME)
@CheckPersist(allowEmpty = false)
private String latestId;
public static final String LATESTCREATETIME_FIELDNAME = "latestCreateTime";
@FieldDescribe("最后查询创建时间.")
@Temporal(TemporalType.TIMESTAMP)
@Column(name = ColumnNamePrefix + LATESTSEQUENCE_FIELDNAME)
@CheckPersist(allowEmpty = false)
private Date latestCreateTime;
public static final String LATESTSEQUENCE_FIELDNAME = "latestSequence";
@FieldDescribe("最后查询顺序标识.")
@Column(length = JpaObject.length_128B, name = ColumnNamePrefix + LATESTSEQUENCE_FIELDNAME)
@CheckPersist(allowEmpty = false)
private String latestSequence;
public static final String TYPE_FIELDNAME = "type";
@Flag
@FieldDescribe("类型.")
@Column(length = length_32B, name = ColumnNamePrefix + TYPE_FIELDNAME)
@CheckPersist(allowEmpty = false)
private String type;
public static final String NODE_FIELDNAME = "node";
@Flag
@FieldDescribe("节点.")
@Column(length = length_255B, name = ColumnNamePrefix + NODE_FIELDNAME)
@CheckPersist(allowEmpty = false)
private String node;
public static final String FREQUENCY_FIELDNAME = "frequency";
@FieldDescribe("频率.")
@Column(length = length_8B, name = ColumnNamePrefix + FREQUENCY_FIELDNAME)
@CheckPersist(allowEmpty = false)
private String frequency;
public String getLatestId() {
return latestId;
}
public void setLatestId(String latestId) {
this.latestId = latestId;
}
public Date getLatestCreateTime() {
return latestCreateTime;
}
public void setLatestCreateTime(Date latestCreateTime) {
this.latestCreateTime = latestCreateTime;
}
public String getLatestSequence() {
return latestSequence;
}
public void setLatestSequence(String latestSequence) {
this.latestSequence = latestSequence;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public String getNode() {
return node;
}
public void setNode(String node) {
this.node = node;
}
public String getFrequency() {
return frequency;
}
public void setFrequency(String frequency) {
this.frequency = frequency;
}
}
package com.x.query.service.processing;
import java.io.IOException;
import java.net.URISyntaxException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Map;
import java.util.Properties;
import java.util.concurrent.ConcurrentHashMap;
import org.apache.commons.lang3.StringUtils;
import org.apache.solr.client.solrj.embedded.EmbeddedSolrServer;
import org.apache.solr.core.CoreContainer;
import com.x.base.core.project.config.Config;
import com.x.base.core.project.logger.Logger;
import com.x.base.core.project.logger.LoggerFactory;
public class Solr {
private static final Logger LOGGER = LoggerFactory.getLogger(Solr.class);
private CoreContainer coreContainer;
private static Map<String, EmbeddedSolrServer> cores = new ConcurrentHashMap<>();
private Path coreTemplateProcessPlatform;
private Path coreTemplateCms;
private Path home;
private static final String CORENAME_FULLTEXT = "FULLTEXT";
public EmbeddedSolrServer get(String type, String id) {
String key = key(type, id);
return cores.computeIfAbsent(key, s -> {
try {
Path source = StringUtils.equals(type, "processPlatfom") ? coreTemplateProcessPlatform
: coreTemplateCms;
Path target = home.resolve(key);
if (!Files.exists(target)) {
Files.createDirectories(target);
Files.copy(source, target);
}
} catch (Exception e) {
LOGGER.error(e);
}
return new EmbeddedSolrServer(coreContainer, key);
});
}
private String key(String type, String id) {
return type + "#" + id;
}
public void shutdown() {
cores.entrySet().stream().forEach(o -> {
try {
o.getValue().close();
} catch (IOException e) {
LOGGER.error(e);
}
});
this.coreContainer.shutdown();
}
public EmbeddedSolrServer fullText() {
return cores.get(CORENAME_FULLTEXT);
}
public static class Builder {
private Path coreTemplateProcessPlatform;
private Path coreTemplateCms;
private Path home;
public Builder() {
// nothing
}
public Builder coreTemplateProcessPlatform(Path path) {
this.coreTemplateProcessPlatform = path;
return this;
}
public Builder coreTemplateCms(Path path) {
this.coreTemplateCms = path;
return this;
}
public Builder home(Path path) {
this.home = path;
return this;
}
public Solr build() throws IOException, URISyntaxException {
Solr solr = new Solr();
solr.coreTemplateProcessPlatform = this.coreTemplateProcessPlatform;
solr.coreTemplateCms = this.coreTemplateCms;
solr.home = this.home;
solr.home = Config.pathLocalRepositorySolr(false);
if (!Files.exists(solr.home)) {
Files.createDirectories(solr.home);
Files.copy(Config.pathCommonsSolr(false), solr.home);
}
solr.coreContainer = new CoreContainer(solr.home, new Properties());
solr.coreContainer.load();
solr.coreContainer.getAllCoreNames()
.forEach(s -> cores.put(s, new EmbeddedSolrServer(solr.coreContainer, s)));
return solr;
}
}
}
package com.x.query.service.processing.schedule;
import java.util.List;
import javax.persistence.EntityManager;
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root;
import org.apache.commons.lang.BooleanUtils;
import org.apache.solr.client.solrj.embedded.EmbeddedSolrServer;
import org.apache.solr.common.SolrInputDocument;
import org.quartz.JobExecutionContext;
import com.google.gson.Gson;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonPrimitive;
import com.x.base.core.container.EntityManagerContainer;
import com.x.base.core.container.factory.EntityManagerContainerFactory;
import com.x.base.core.entity.JpaObject_;
import com.x.base.core.entity.dataitem.DataItem;
import com.x.base.core.entity.dataitem.DataItemConverter;
import com.x.base.core.entity.dataitem.ItemCategory;
import com.x.base.core.project.config.Config;
import com.x.base.core.project.gson.XGsonBuilder;
import com.x.base.core.project.logger.Logger;
import com.x.base.core.project.logger.LoggerFactory;
import com.x.base.core.project.schedule.AbstractJob;
import com.x.base.core.project.tools.DateTools;
import com.x.processplatform.core.entity.content.Data;
import com.x.processplatform.core.entity.content.WorkCompleted;
import com.x.processplatform.core.entity.content.WorkCompleted_;
import com.x.query.core.entity.Item;
import com.x.query.core.entity.index.State;
import com.x.query.service.processing.Business;
import com.x.query.service.processing.Solr;
import com.x.query.service.processing.ThisApplication;
public class HighFrequencyIndexWorkCompleted extends AbstractJob {
private static final Logger LOGGER = LoggerFactory.getLogger(HighFrequencyIndexWorkCompleted.class);
private final DataItemConverter<Item> converter = new DataItemConverter<>(Item.class);
private final Gson gson = XGsonBuilder.instance();
@Override
public void schedule(JobExecutionContext jobExecutionContext) throws Exception {
State state = null;
try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
Business business = new Business(emc);
state = emc.firstEqualAndEqual(State.class, State.NODE_FIELDNAME, Config.node(), State.FREQUENCY_FIELDNAME,
State.FREQUENCY_HIGH);
List<String> ids = this.list(business, state);
if (!ids.isEmpty()) {
Solr solr = ThisApplication.solr();
if (null != solr) {
index(solr, ids);
}
}
}
}
private List<String> list(Business business, State state) throws Exception {
EntityManager em = business.entityManagerContainer().get(WorkCompleted.class);
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<String> cq = cb.createQuery(String.class);
Root<WorkCompleted> root = cq.from(WorkCompleted.class);
Predicate p = null;
if (null != state) {
p = cb.notEqual(root.get(WorkCompleted_.id), state.getLatestId());
p = cb.and(p, cb.greaterThanOrEqualTo(root.get(JpaObject_.createTime), state.getLatestCreateTime()));
p = cb.and(p, cb.greaterThanOrEqualTo(root.get(JpaObject_.sequence), state.getLatestSequence()));
} else {
p = cb.conjunction();
}
cq.select(root.get(WorkCompleted_.id)).where(p);
return em.createQuery(cq).setMaxResults(100).getResultList();
}
private void index(Solr solr, List<String> ids) {
for (String id : ids) {
try {
index(solr, id);
} catch (Exception e) {
LOGGER.error(e);
}
}
}
private void index(Solr solr, String id) throws Exception {
try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
Business business = new Business(emc);
WorkCompleted workCompleted = emc.find(id, WorkCompleted.class);
if (null != workCompleted) {
EmbeddedSolrServer server = solr.get("processPlatform", id);
if (null != server) {
add(business, server, workCompleted);
}
}
}
}
private void add(Business business, EmbeddedSolrServer server, WorkCompleted workCompleted) throws Exception {
JsonObject json = XGsonBuilder.convert(data(business, workCompleted), JsonObject.class);
json.addProperty(WorkCompleted.title_FIELDNAME, workCompleted.getTitle());
json.addProperty(WorkCompleted.job_FIELDNAME, workCompleted.getJob());
json.addProperty(WorkCompleted.createTime_FIELDNAME, DateTools.format(workCompleted.getCompletedTime()));
json.addProperty(WorkCompleted.updateTime_FIELDNAME, DateTools.format(workCompleted.getUpdateTime()));
json.addProperty(WorkCompleted.job_FIELDNAME, workCompleted.getJob());
json.addProperty(WorkCompleted.id_FIELDNAME, workCompleted.getId());
json.addProperty(WorkCompleted.application_FIELDNAME, workCompleted.getApplication());
json.addProperty(WorkCompleted.process_FIELDNAME, workCompleted.getProcess());
json.addProperty("className", WorkCompleted.class.getName());
server.add(document);
server.commit();
}
private Data data(Business business, WorkCompleted workCompleted) throws Exception {
Data data = null;
if (BooleanUtils.isTrue(workCompleted.getMerged())) {
data = workCompleted.getProperties().getData();
} else {
List<Item> items = business.entityManagerContainer().listEqualAndEqual(Item.class,
DataItem.bundle_FIELDNAME, workCompleted.getJob(), DataItem.itemCategory_FIELDNAME,
ItemCategory.pp);
JsonElement jsonElement = converter.assemble(items);
if (jsonElement.isJsonObject()) {
data = gson.fromJson(jsonElement, Data.class);
} else {
data = new Data();
}
}
data.removeWork();
data.removeAttachmentList();
return data;
}
private SolrInputDocument concrete(WorkCompleted workCompleted, JsonObject jsonObject) {
SolrInputDocument document = new SolrInputDocument();
jsonObject.entrySet().forEach(en -> {
set(en.getKey(), en.getValue(), document);
});
document.setField(WorkCompleted.title_FIELDNAME, workCompleted.getTitle());
return document;
}
private void set(String property, JsonElement jsonElement, SolrInputDocument document) {
if (jsonElement.isJsonPrimitive()) {
JsonPrimitive jsonPrimitive = jsonElement.getAsJsonPrimitive();
if (jsonPrimitive.isBoolean()) {
document.setField(property, jsonPrimitive.getAsBoolean());
} else if (jsonPrimitive.isNumber()) {
document.setField(property, jsonPrimitive.getAsFloat());
} else {
document.setField(property, jsonPrimitive.getAsString());
}
}
}
}
\ No newline at end of file
package com.x.query.service.processing.schedule;
public class LowFrequencyRetrievalWorkCompleted {
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册