Skip to content

Commit

Permalink
Fix 3.5.3 (#699)
Browse files Browse the repository at this point in the history
* Update @rbv

* be: 通知邮件保持 html

* feat: report nref

* be: Bad JSONArray format

* out API Filter <Body>

* pageSize max=1000

* fix: DATE DATETIME 比较

* fix: SafeObservable

* v3.5.3
  • Loading branch information
getrebuild authored Dec 22, 2023
1 parent 87737a9 commit 8649f81
Show file tree
Hide file tree
Showing 28 changed files with 189 additions and 80 deletions.
2 changes: 1 addition & 1 deletion @rbv
Submodule @rbv updated from fecdd9 to d3707a
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
</parent>
<groupId>com.rebuild</groupId>
<artifactId>rebuild</artifactId>
<version>3.5.2</version>
<version>3.5.3</version>
<name>rebuild</name>
<description>Building your business-systems freely!</description>
<url>https://getrebuild.com/</url>
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/com/rebuild/core/Application.java
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,11 @@ public class Application implements ApplicationListener<ApplicationStartedEvent>
/**
* Rebuild Version
*/
public static final String VER = "3.5.2";
public static final String VER = "3.5.3";
/**
* Rebuild Build [MAJOR]{1}[MINOR]{2}[PATCH]{2}[BUILD]{2}
*/
public static final int BUILD = 3050207;
public static final int BUILD = 3050308;

static {
// Driver for DB
Expand Down Expand Up @@ -373,11 +373,11 @@ public static EntityService getEntityService(int entityCode) {
}

public static GeneralEntityService getGeneralEntityService() {
return (GeneralEntityService) getContext().getBean("generalEntityService");
return (GeneralEntityService) getContext().getBean("rbGeneralEntityService");
}

public static CommonsService getCommonsService() {
return getBean(CommonsService.class);
return (CommonsService) getContext().getBean("rbCommonsService");
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/rebuild/core/service/CommonsService.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
* @author Zixin (RB)
* @since 11/06/2019
*/
@Service
@Service("rbCommonsService")
public class CommonsService extends InternalPersistService {

protected CommonsService(PersistManagerFactory aPMFactory) {
Expand Down
45 changes: 45 additions & 0 deletions src/main/java/com/rebuild/core/service/SafeObservable.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*!
Copyright (c) REBUILD <https://getrebuild.com/> and/or its owners. All rights reserved.
rebuild is dual-licensed under commercial and open source licenses (GPLv3).
See LICENSE and COMMERCIAL in the project root for license information.
*/

package com.rebuild.core.service;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;

/**
* Thread-Safe <tt>Observable</tt>
*
* @author devezhao
* @since 2023/12/22
*/
public class SafeObservable {

final private List<SafeObserver> obs;

public SafeObservable() {
obs = new ArrayList<>();
}

public void addObserver(SafeObserver o) {
if (o == null) throw new NullPointerException();
if (!obs.contains(o)) {
obs.add(o);
obs.sort(Comparator.comparingInt(SafeObserver::getOrder));
}
}

public void notifyObservers(Object arg) {
for (SafeObserver o : obs) {
o.update(this, arg);
}
}

public int countObservers() {
return obs.size();
}
}
21 changes: 21 additions & 0 deletions src/main/java/com/rebuild/core/service/SafeObserver.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*!
Copyright (c) REBUILD <https://getrebuild.com/> and/or its owners. All rights reserved.
rebuild is dual-licensed under commercial and open source licenses (GPLv3).
See LICENSE and COMMERCIAL in the project root for license information.
*/

package com.rebuild.core.service;

/**
* Thread-Safe <tt>Observer</tt>
*
* @author devezhao
* @since 2023/12/22
*/
public interface SafeObserver {

void update(SafeObservable o, Object arg);

int getOrder();
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import com.rebuild.core.metadata.MetadataHelper;
import com.rebuild.core.privileges.UserService;
import com.rebuild.core.service.approval.ApprovalHelper;
import com.rebuild.core.support.general.ProtocolFilterParser;
import com.rebuild.core.support.general.RecordBuilder;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.io.FileUtils;
Expand Down Expand Up @@ -88,10 +89,11 @@ protected List<Map<String, Object>> buildData() {
} else if (varName.startsWith(DETAIL_PREFIX)) {
refName = DETAIL_PREFIX;
} else {
// 在客户中导出订单(下列 AccountId 为订单中引用客户的引用字段)
// .AccountId.SalesOrder.SalesOrderName
String[] split = varName.substring(1).split("\\.");
if (split.length < 2) throw new ReportsException("Bad REF (Miss .detail prefix?) : " + varName);

String refName2 = split[0] + split[1];
refName = varName.substring(0, refName2.length() + 2 /* dots */);
}
Expand Down Expand Up @@ -169,8 +171,12 @@ protected List<Map<String, Object>> buildData() {
String sortField = templateExtractor33.getSortField(refName);
querySql += " order by " + StringUtils.defaultIfBlank(sortField, "createdOn asc");

String relatedExpr = split[1] + "." + split[0];
String where = new ProtocolFilterParser(null).parseRelated(relatedExpr, recordId);
querySql = querySql.replace("%s = ?", where);

querySql = String.format(querySql, StringUtils.join(e.getValue(), ","),
ref2Entity.getPrimaryField().getName(), ref2Entity.getName(), split[0]);
ref2Entity.getPrimaryField().getName(), ref2Entity.getName());
}

log.info("SQL of template : {}", querySql);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ protected void merge(Sheet sheet, Cell cell, Head head, Integer relativeRowIndex
int colIndex = cell.getColumnIndex();
sheet = cell.getSheet();
Row prevRow = sheet.getRow(rowIndex - 1);
if (prevRow == null) return;
Cell prevCell = prevRow.getCell(colIndex);
List<CellRangeAddress> craList = sheet.getMergedRegions();
CellStyle cs = cell.getCellStyle();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,9 @@ public int delete(ID recordId) {
"select commentId from FeedsComment where feedsId = ?")
.setParameter(1, recordId)
.array();
FeedsCommentService fcs = Application.getBean(FeedsCommentService.class);
for (Object[] c : comments) {
Application.getBean(FeedsCommentService.class).delete((ID) c[0]);
fcs.delete((ID) c[0]);
}

// 只有动态本身可以恢复
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,9 @@
@Slf4j
public class AttachmentAwareObserver extends OperatingObserver {

public AttachmentAwareObserver() {
super();
@Override
public int getOrder() {
return 1;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.BooleanUtils;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang3.ArrayUtils;
import org.springframework.stereotype.Service;
import org.springframework.util.Assert;

Expand All @@ -63,7 +62,6 @@
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Observer;
import java.util.Set;
import java.util.TreeMap;

Expand All @@ -79,26 +77,17 @@
* @since 11/06/2019
*/
@Slf4j
@Service
@Service("rbGeneralEntityService")
public class GeneralEntityService extends ObservableService implements EntityService {

// 有明细
public static final String HAS_DETAILS = "$DETAILS$";

protected GeneralEntityService(PersistManagerFactory aPMFactory) {
super(aPMFactory);
}

@Override
protected Observer[] getOrderObservers() {
Observer[] obs = new Observer[] {
// 触发器
new RobotTriggerObserver(),
// 通知
new NotificationObserver(),
};
obs = ArrayUtils.addAll(obs, super.getOrderObservers());
return obs;
addObserver(new NotificationObserver());
addObserver(new RobotTriggerObserver());
}

@Override
Expand Down Expand Up @@ -375,7 +364,6 @@ record = QueryHelper.getMainIdByDetail(record);
}

if (countObservers() > 0 && assignBefore != null) {
setChanged();
notifyObservers(OperatingContext.create(UserContextHolder.getUser(), BizzPermission.ASSIGN, assignBefore, assignAfter));
}
return affected;
Expand Down Expand Up @@ -454,7 +442,6 @@ record = QueryHelper.getMainIdByDetail(record);
}

if (countObservers() > 0 && shareChange) {
setChanged();
notifyObservers(OperatingContext.create(currentUser, BizzPermission.SHARE, null, sharedAfter));
}
return affected;
Expand All @@ -476,7 +463,6 @@ public int unshare(ID record, ID accessId) {
delegateService.delete(accessId);

if (countObservers() > 0) {
setChanged();
notifyObservers(OperatingContext.create(currentUser, InternalPermission.UNSHARE, unsharedBefore, null));
}
return 1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
import com.rebuild.core.metadata.EntityHelper;
import com.rebuild.core.privileges.bizz.InternalPermission;
import com.rebuild.core.service.BaseService;
import com.rebuild.core.service.SafeObservable;
import com.rebuild.core.service.SafeObserver;
import com.rebuild.core.service.ServiceSpec;
import com.rebuild.core.service.files.AttachmentAwareObserver;
import com.rebuild.core.service.general.recyclebin.RecycleBinCleanerJob;
Expand All @@ -24,9 +26,6 @@
import lombok.extern.slf4j.Slf4j;
import org.springframework.util.Assert;

import java.util.Observable;
import java.util.Observer;

/**
* 可注入观察者的服务
*
Expand All @@ -35,7 +34,7 @@
* @since 12/28/2018
*/
@Slf4j
public abstract class ObservableService extends Observable implements ServiceSpec {
public abstract class ObservableService extends SafeObservable implements ServiceSpec {

final protected ServiceSpec delegateService;

Expand All @@ -45,21 +44,14 @@ public abstract class ObservableService extends Observable implements ServiceSpe
protected ObservableService(PersistManagerFactory aPMFactory) {
this.delegateService = new BaseService(aPMFactory);

for (Observer o : getOrderObservers()) {
log.info("Add observer : {} for [ {} ] ", o, getEntityCode());
addObserver(o);
}
addObserver(new AttachmentAwareObserver());
addObserver(new RevisionHistoryObserver());
}

/**
* @return
*/
protected Observer[] getOrderObservers() {
// 默认监听者
return new Observer[] {
new RevisionHistoryObserver(), // 2
new AttachmentAwareObserver(), // 1
};
@Override
public void addObserver(SafeObserver o) {
log.info("Add observer : {} for [ {} ] ", o, getEntityCode());
super.addObserver(o);
}

@Override
Expand All @@ -72,7 +64,6 @@ public Record create(Record record) {
record = delegateService.create(record);

if (countObservers() > 0) {
setChanged();
notifyObservers(OperatingContext.create(UserContextHolder.getUser(), BizzPermission.CREATE, null, record));
}
return record;
Expand All @@ -85,7 +76,6 @@ public Record update(Record record) {
record = delegateService.update(record);

if (countObservers() > 0) {
setChanged();
notifyObservers(OperatingContext.create(UserContextHolder.getUser(), BizzPermission.UPDATE, before, record));
}
return record;
Expand All @@ -102,14 +92,12 @@ public int delete(ID recordId) {
deleted = recordSnap(deleted, true);

// 删除前触发,做一些状态保持
setChanged();
notifyObservers(OperatingContext.create(currentUser, InternalPermission.DELETE_BEFORE, deleted, deleted));
}

int affected = delegateService.delete(recordId);

if (countObservers() > 0) {
setChanged();
notifyObservers(OperatingContext.create(currentUser, BizzPermission.DELETE, deleted, null));
}
return affected;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,10 @@
import cn.devezhao.bizz.privileges.impl.BizzPermission;
import cn.devezhao.commons.ThreadPool;
import com.rebuild.core.privileges.bizz.InternalPermission;
import com.rebuild.core.service.SafeObservable;
import com.rebuild.core.service.SafeObserver;
import lombok.extern.slf4j.Slf4j;

import java.util.Observable;
import java.util.Observer;

/**
* 记录操作观察者。子类复写需要关注的操作即可,**注意实现必须是无状态的**
*
Expand All @@ -23,14 +22,14 @@
* @since 10/31/2018
*/
@Slf4j
public abstract class OperatingObserver implements Observer {
public abstract class OperatingObserver implements SafeObserver {

protected OperatingObserver() {
super();
}

@Override
public void update(final Observable o, final Object arg) {
public void update(final SafeObservable o, final Object arg) {
final OperatingContext ctx = (OperatingContext) arg;
if (isAsync()) {
ThreadPool.exec(() -> {
Expand Down
Loading

0 comments on commit 8649f81

Please sign in to comment.