1 实例明细url显示 2 增加了logo图片可以编辑
1 实例明细url显示
是在iop中写死的配置
2 增加了logo图片可以编辑
仿照 admin里 服务工厂-服务定义中的内容
(1)在edit.html中增加logo图片字样及调用选择图片,以及logo.html
<div class="form-group form-required"> <label class="control-label col-sm-3">logo图片:</label> <div class="col-sm-7"> <input type="text" class="form-control" name="logo_url" value="{{serviceDef.logo_url}}" readonly style="cursor:pointer;"> </div> </div>
(2)在detail.js中增加 self.logoChoose($dialog); 以及logoChoose函数(在group.js中静姐写过)
3 前端和后端密钥支持删除
(1)前端在secretKey.js中添加:首先增加按钮,写deleteSecretKey函数(前后端密钥一样)
(2)self.ajax.delete("/dev/v1.0/secretKey-list/delete/"+id,function(err,data) 通过这个借口,链接到后台 cloud-api-service中。
controller层:
dao层:修改,ApiClientDefineDao,,增加了ApiClientDefineEntityDao.java ,增加了getListByClientId
/** * */ package com.inspur.cloud.api.dao; import com.inspur.cloud.api.entity.ApiClientDefine; import com.inspur.cloud.api.entity.ApiClientDefineEntity; import com.inspur.cloud.api.entity.ApiServiceEntity; import com.inspur.cloud.resource.ResourceRelationUtils; import org.springframework.util.StringUtils; import org.springside.modules.orm.hibernate.HibernateDao; import java.util.Date; /** * * @author cww<br> * @version 1.0 * 2015-6-3 10:52:49<br> */ public class ApiClientDefineEntityDao<T extends ApiClientDefine> extends HibernateDao<T, String> { /** * The t parameter must be a Resource object. * <p></p> */ public void save(T t) { this.save(t, StringUtils.isEmpty(t.getId())); } /** * The t parameter must be a Resource object. * <p></p> */ public void save(T t, boolean isCreate) { //create a resource Date time = new Date(); t.setUpdatedAt(time); if(isCreate) { if(t.getCreatedAt() == null) { t.setCreatedAt(time); } t.setIsDeleted(Boolean.FALSE); } super.save(t); } // private void setProperty() public void delete(String id) { //check the resource has referenced by any other resource ResourceRelationUtils.checkResourceDelete(id); T t = this.get(id); Date time = new Date(); t.setUpdatedAt(time); t.setDeletedAt(time); t.setIsDeleted(Boolean.TRUE); this.save(t); } /* (non-Javadoc) * @see org.springside.modules.orm.hibernate.SimpleHibernateDao#delete(java.lang.Object) */ @Override public void delete(ApiClientDefine entity) { this.delete(entity.getId()); } }
entiyt 层:ApiClientDefine和ApiClientDefineEntity ,仿照静姐delete,增加了ApiClientDefineEntity(extends IdEntity)
package com.inspur.cloud.api.entity; import java.io.Serializable; import java.util.Date; import javax.persistence.Entity; import javax.persistence.Id; import javax.persistence.Table; import org.hibernate.annotations.Type; import com.fasterxml.jackson.annotation.JsonProperty; import com.wordnik.swagger.annotations.ApiModelProperty; @Entity @Table(name="Api_client_define") public class ApiClientDefine extends ApiClientDefineEntity{ private static final long serialVersionUID = 1L; @JsonProperty("CLIENT_KEY") private String clientKey; @JsonProperty("CLIENT_SECRET") private String clientSecret; @JsonProperty("DESCRIPTION") private String description; @JsonProperty("CLIENT_TYPE") private String clientType; @JsonProperty("OWNER") private String owner; @JsonProperty("IN_USE") private Boolean inUse; @ApiModelProperty(hidden=true) @JsonProperty("IS_DELETED") private Boolean isDeleted; @ApiModelProperty(hidden=true) @JsonProperty("CREATED_AT") private Date createdAt; @ApiModelProperty(hidden=true) @JsonProperty("UPDATED_AT") private Date updatedAt; @ApiModelProperty(hidden=true) @JsonProperty("DELETED_AT") private Date deletedAt; public String getClientKey() { return clientKey; } public void setClientKey(String clientKey) { this.clientKey = clientKey; } public String getClientSecret() { return clientSecret; } public void setClientSecret(String clientSecret) { this.clientSecret = clientSecret; } public String getDescription() { return description; } public void setDescription(String description) { this.description = description; } public String getClientType() { return clientType; } public void setClientType(String clientType) { this.clientType = clientType; } public String getOwner() { return owner; } public void setOwner(String owner) { this.owner = owner; } @Type(type="com.inspur.cloudframework.hibernate.type.CharacterBooleanType") public Boolean getInUse() { return inUse; } public void setInUse(Boolean inUse) { this.inUse = inUse; } public Date getDeletedAt() { return deletedAt; } public void setDeletedAt(Date deletedAt) { this.deletedAt = deletedAt; } public Date getUpdatedAt() { return updatedAt; } public void setUpdatedAt(Date updatedAt) { this.updatedAt = updatedAt; } @JsonProperty(value="CREATED_AT") public Date getCreatedAt() { return createdAt; } public void setCreatedAt(Date createdAt) { this.createdAt = createdAt; } @Type(type="com.inspur.cloudframework.hibernate.type.CharacterBooleanType") public Boolean getIsDeleted() { return isDeleted; } public void setIsDeleted(Boolean isDeleted) { this.isDeleted = isDeleted; } }
/** * */ package com.inspur.cloud.api.entity; import com.fasterxml.jackson.annotation.JsonProperty; import com.inspur.cloud.entity.IdEntity; import com.wordnik.swagger.annotations.ApiModelProperty; import org.hibernate.annotations.Type; import javax.persistence.MappedSuperclass; import java.util.Date; /** * * @author tang<br> * @version 1.0 * Aug 27, 2015 4:40:48 PM<br> */ @MappedSuperclass public class ApiClientDefineEntity extends IdEntity{ /** * */ private static final long serialVersionUID = 4654645545548886144L; /** * */ //private static final long serialVersionUID = -2312615559760803050L; /*@ApiModelProperty(hidden=true) @JsonProperty("IS_DELETED") private Boolean isDeleted; @ApiModelProperty(hidden=true) @JsonProperty("CREATED_AT") private Date createdAt; @ApiModelProperty(hidden=true) @JsonProperty("UPDATED_AT") private Date updatedAt; @ApiModelProperty(hidden=true) @JsonProperty("DELETED_AT") private Date deletedAt; *//** * @return the deletedAt *//* public Date getDeletedAt() { return deletedAt; } *//** * @param deletedAt the deletedAt to set *//* public void setDeletedAt(Date deletedAt) { this.deletedAt = deletedAt; } *//** * @return the updatedAt *//* public Date getUpdatedAt() { return updatedAt; } *//** * @param updatedAt the updatedAt to set *//* public void setUpdatedAt(Date updatedAt) { this.updatedAt = updatedAt; } *//** * @return the createdAt *//* @JsonProperty(value="created_at") public Date getCreatedAt() { return createdAt; } *//** * @param createdAt the createdAt to set *//* public void setCreatedAt(Date createdAt) { this.createdAt = createdAt; } *//** * @return the isDeleted *//* @Type(type="com.inspur.cloudframework.hibernate.type.CharacterBooleanType") public Boolean getIsDeleted() { return isDeleted; } *//** * @param isDeleted the isDeleted to set *//* public void setIsDeleted(Boolean isDeleted) { this.isDeleted = isDeleted; } */ }
service层:ApiClientDefineServiceImpl
package com.inspur.cloud.api.service; import java.util.ArrayList; import java.util.Date; import java.util.HashMap; import java.util.List; import java.util.Map; import javax.annotation.Resource; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.redis.core.RedisTemplate; import org.springframework.data.redis.serializer.RedisSerializer; import org.springframework.data.redis.serializer.StringRedisSerializer; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import org.springside.modules.orm.Page; import com.inspur.cloud.am.dao.UserDao; import com.inspur.cloud.api.common.GuidGenerator; import com.inspur.cloud.api.dao.ApiClientDefineDao; import com.inspur.cloud.api.dao.ApiClientSvcInstRelaDao; import com.inspur.cloud.api.dao.ApiServiceVersionDao; import com.inspur.cloud.api.entity.ApiClientDefine; import com.inspur.cloud.api.entity.ApiClientSvcInstRela; import com.inspur.cloud.api.entity.ApiSvcVersion; import com.inspur.cloud.api.utils.RedisCachePrefix; @Service @Transactional public class ApiClientDefineServiceImpl implements ApiClientDefineService { @Autowired private ApiClientDefineDao apiClientDefineDao; @Autowired private ApiClientSvcInstRelaDao apiClientSvcInstRelaDao; @Autowired private ApiServiceVersionDao apiSvcVersionDao; @Resource(name="apiRedisTemplate") private RedisTemplate<String,String> redisTemplate; @Autowired private UserDao userDao; //获取当前用户下的所有密钥对(前端密钥) public Page<ApiClientDefine> getApiClientDefineList(Page<ApiClientDefine> page,String description,String userId){ Map<String,Object> map = new HashMap<String,Object>(); map.put("OWNER", userId); if(description!=null&&description.trim()!=""){ map.put("DESCRIPTION", description); } map.put("IS_DELETED", false); Page<ApiClientDefine> apiClientDefinePage = apiClientDefineDao.getList(page, map); return apiClientDefinePage; } //编辑 public void editSecretKey(String id,String name){ ApiClientDefine apiClientDefine = apiClientDefineDao.get(id); apiClientDefine.setDescription(name); apiClientDefine.setUpdatedAt(new Date()); apiClientDefineDao.save(apiClientDefine); } //新增 public void addSecretKey(String userId,String desc,String clientType){ ApiClientDefine api = new ApiClientDefine(); // String id = GuidGenerator.generate(); String clientKey = GuidGenerator.generate(); String clientSecret = GuidGenerator.generate(); // api.setId(id); api.setClientKey(clientKey); api.setClientSecret(clientSecret); api.setClientType(clientType); api.setDescription(desc); api.setInUse(Boolean.TRUE); api.setOwner(userId); apiClientDefineDao.save(api); // User user = this.userDao.get(userId); if("SVC".equals(clientType)){ String redisValue = clientSecret+":"+api.getId(); // String redisValue = clientSecret+":"+id+":"+userId+":"+user.getLoginName(); RedisSerializer stringSerializer = new StringRedisSerializer(); redisTemplate.setKeySerializer(stringSerializer); redisTemplate.setValueSerializer(stringSerializer); redisTemplate.opsForValue().set(RedisCachePrefix.getBckKey(clientKey), redisValue); } } //停用启用 public void stopSecretKey(String id){ ApiClientDefine apiClientDefine = apiClientDefineDao.findById(id); Boolean inUse = apiClientDefine.getInUse(); if(inUse != null){ if(inUse.equals(Boolean.TRUE)){ apiClientDefine.setInUse(Boolean.FALSE); }else if(inUse.equals(Boolean.FALSE)){ apiClientDefine.setInUse(Boolean.TRUE); } } apiClientDefineDao.save(apiClientDefine); } // 删除 public void deleteSecretKey(String id) { ApiClientDefine apiClientDefine = apiClientDefineDao.findById(id); Boolean inUse = apiClientDefine.getInUse(); if (inUse != null) { if (inUse.equals(Boolean.TRUE)) { apiClientDefine.setInUse(Boolean.FALSE); } else if (inUse.equals(Boolean.FALSE)) { apiClientDefine.setInUse(Boolean.TRUE); } } Map<String, Object> map = new HashMap<String, Object>(); map.put("CLIENT_ID", id); List<ApiClientSvcInstRela> apiClientSvcInstRelaList = apiClientSvcInstRelaDao.getList(map); Map<String, Object> map1 = new HashMap<String, Object>(); map1.put("svc_client_id", id); List<ApiSvcVersion> apiSvcVersionList = apiSvcVersionDao.getListByClientId(map1); // 根据 CLIENT_ID判断【 前端秘钥】是否使用 if (null == apiClientSvcInstRelaList || apiClientSvcInstRelaList.size() == 0) { // 根据 CLIENT_ID判断【 后端秘钥】是否使用 if (null == apiSvcVersionList || apiSvcVersionList.size() == 0) { apiClientDefineDao.delete(apiClientDefine); } else { ArrayList<String> arrayList = new ArrayList<>(); for (ApiSvcVersion apiVer : apiSvcVersionList) { arrayList.add(apiVer.getDisplayName()); } for (ApiSvcVersion apiVer : apiSvcVersionList) { throw new RuntimeException("该密钥已被版本" + arrayList + "使用!请解绑后再尝试删除。"); } } } else { throw new RuntimeException("该密钥已绑定服务实例,请执行解绑操作后再尝试删除!"); } } //重置密钥对 public void resetSecretKey(String id){ ApiClientDefine apiClientDefine = apiClientDefineDao.findById(id); String clientType = apiClientDefine.getClientType(); String clientSecret = GuidGenerator.generate(); String clientKey = apiClientDefine.getClientKey(); RedisSerializer stringSerializer = new StringRedisSerializer(); redisTemplate.setKeySerializer(stringSerializer); redisTemplate.setValueSerializer(stringSerializer); if("DEV".equals(clientType)){ Map<String,Object> map = new HashMap<String,Object>(); map.put("CLIENT_ID", id); String ownerId = apiClientDefine.getOwner(); String ownerName = this.userDao.get(ownerId).getLoginName(); List<ApiClientSvcInstRela> apiClientSvcInstRelaList = apiClientSvcInstRelaDao.getList(map); if(apiClientSvcInstRelaList != null &&apiClientSvcInstRelaList.size()>0){ for (ApiClientSvcInstRela apiClientSvcInstRela : apiClientSvcInstRelaList) { String versionId = apiClientSvcInstRela.getVersionId(); String redisValue = redisTemplate.opsForValue().get(RedisCachePrefix.getFrtKey(clientKey, versionId)); String[] split = redisValue.split(":"); redisValue =clientSecret+":"+split[1]+":"+split[2]+":"+ownerId+":"+ownerName; redisTemplate.opsForValue().set(RedisCachePrefix.getFrtKey(clientKey, versionId), redisValue); } } }else if("SVC".equals(clientType)){ String redisKey = clientKey; String redisValue = clientSecret+":"+id; // String redisValue = clientSecret+":"+id+":"+ownerId+":"+ownerName; redisTemplate.opsForValue().set(RedisCachePrefix.getBckKey(redisKey),redisValue); } apiClientDefine.setClientSecret(clientSecret); //apiClientDefine.setCreatedAt(new Date()); apiClientDefine.setUpdatedAt(new Date()); apiClientDefineDao.save(apiClientDefine); } @Override public List<ApiClientDefine> getAllSecretKeys(String vdcId){ Map<String,Object> params = new HashMap<String,Object>(); params.put("owner",vdcId); List<ApiClientDefine> apiClientDefines=apiClientDefineDao.getapiClientDefine(params); return apiClientDefines; } //获取当前用户下的所有密钥对(后端密钥) public Page<ApiClientDefine> getBackEndApiClientDefineList(Page<ApiClientDefine> page,String desc,String vdcId){ Map<String,Object> map = new HashMap<String,Object>(); map.put("CLIENT_TYPE", "SVC"); map.put("OWNER", vdcId); map.put("IS_DELETED", false); if(desc!=null&&desc.trim()!=""){ map.put("DESCRIPTION", desc); } Page<ApiClientDefine> apiClientDefinePage = apiClientDefineDao.getList(page, map); return apiClientDefinePage; } }
未完待续……