|
@@ -1,8 +1,10 @@
|
|
|
package com.uas.sso.sso.backend.service.impl;
|
|
package com.uas.sso.sso.backend.service.impl;
|
|
|
|
|
|
|
|
import com.alibaba.druid.support.json.JSONUtils;
|
|
import com.alibaba.druid.support.json.JSONUtils;
|
|
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
import com.uas.sso.dao.AppDao;
|
|
import com.uas.sso.dao.AppDao;
|
|
|
import com.uas.sso.entity.App;
|
|
import com.uas.sso.entity.App;
|
|
|
|
|
+import com.uas.sso.sso.backend.exceptions.ValidationFailedException;
|
|
|
import com.uas.sso.sso.backend.service.AppService;
|
|
import com.uas.sso.sso.backend.service.AppService;
|
|
|
import java.util.Collections;
|
|
import java.util.Collections;
|
|
|
import java.util.List;
|
|
import java.util.List;
|
|
@@ -11,6 +13,7 @@ import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
import org.springframework.util.Assert;
|
|
import org.springframework.util.Assert;
|
|
|
import org.springframework.util.CollectionUtils;
|
|
import org.springframework.util.CollectionUtils;
|
|
|
|
|
+import org.springframework.util.StringUtils;
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* An implementations of {@code AppService}.
|
|
* An implementations of {@code AppService}.
|
|
@@ -40,12 +43,63 @@ public class AppServiceImpl implements AppService {
|
|
|
@Override
|
|
@Override
|
|
|
@Transactional(rollbackFor = RuntimeException.class)
|
|
@Transactional(rollbackFor = RuntimeException.class)
|
|
|
public void addAppInfo(App app) {
|
|
public void addAppInfo(App app) {
|
|
|
- System.out.println(JSONUtils.toJSONString(app));
|
|
|
|
|
|
|
+ if (app == null) {
|
|
|
|
|
+ throw new ValidationFailedException("应用信息不能为空");
|
|
|
|
|
+ } else if (StringUtils.isEmpty(app.getUid()) || StringUtils.isEmpty(app.getDescription())) {
|
|
|
|
|
+ throw new ValidationFailedException("应用uid或介绍信息不能为空");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ App existOne = appDao.findOne(app.getUid());
|
|
|
|
|
+ if (existOne != null) {
|
|
|
|
|
+ throw new ValidationFailedException(String.format("应用uid %s 已经被使用", app.getUid()));
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // If app is controlled by other app, check this app whether exist and handler app info
|
|
|
|
|
+ if (!StringUtils.isEmpty(app.getUserControl())) {
|
|
|
|
|
+ existOne = appDao.findOne(app.getUserControl());
|
|
|
|
|
+ if (existOne == null) {
|
|
|
|
|
+ throw new ValidationFailedException(
|
|
|
|
|
+ String.format("级联应用uid %s 不存在", app.getUserControl()));
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ appDao.save(app);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
@Transactional(rollbackFor = RuntimeException.class)
|
|
@Transactional(rollbackFor = RuntimeException.class)
|
|
|
public void updateApp(App app) {
|
|
public void updateApp(App app) {
|
|
|
- System.out.println(JSONUtils.toJSONString(app));
|
|
|
|
|
|
|
+ if (app == null) {
|
|
|
|
|
+ throw new ValidationFailedException("应用信息不能为空");
|
|
|
|
|
+ } else if (StringUtils.isEmpty(app.getUid()) || StringUtils.isEmpty(app.getDescription())) {
|
|
|
|
|
+ throw new ValidationFailedException("应用uid或介绍信息不能为空");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ App existOne = appDao.findOne(app.getUid());
|
|
|
|
|
+ if (existOne == null) {
|
|
|
|
|
+ throw new ValidationFailedException(String.format("应用uid %s 不存在", app.getUid()));
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // If app is controlled by other app, check this app whether exist and handler app info
|
|
|
|
|
+ if (!StringUtils.isEmpty(app.getUserControl())) {
|
|
|
|
|
+ App controlOne = appDao.findOne(app.getUserControl());
|
|
|
|
|
+ if (controlOne == null) {
|
|
|
|
|
+ throw new ValidationFailedException(
|
|
|
|
|
+ String.format("级联应用uid %s 不存在", app.getUserControl()));
|
|
|
|
|
+ }
|
|
|
|
|
+ existOne.setUserControl(app.getUserControl());
|
|
|
|
|
+ }
|
|
|
|
|
+ existOne = app;
|
|
|
|
|
+
|
|
|
|
|
+ appDao.save(existOne);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void deleteApp(String uid) {
|
|
|
|
|
+ if (StringUtils.isEmpty(uid)) {
|
|
|
|
|
+ throw new ValidationFailedException("应用uid不能为空");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ appDao.delete(uid);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|