Skip to content

Commit

Permalink
portal can edit config
Browse files Browse the repository at this point in the history
  • Loading branch information
lepdou committed Apr 13, 2016
1 parent 719d67d commit 7b596e0
Show file tree
Hide file tree
Showing 33 changed files with 493 additions and 755 deletions.
Expand Up @@ -3,6 +3,7 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
Expand All @@ -18,8 +19,9 @@ public class ItemSetController {
private ItemSetService itemSetService;

@RequestMapping(path = "/apps/{appId}/clusters/{clusterName}/namespaces/{namespaceName}/itemset", method = RequestMethod.POST)
public ResponseEntity<Void> create(@RequestBody ItemChangeSets changeSet) {
itemSetService.updateSet(changeSet);
public ResponseEntity<Void> create(@PathVariable String appId, @PathVariable String clusterName,
@PathVariable String namespaceName, @RequestBody ItemChangeSets changeSet) {
itemSetService.updateSet(appId, clusterName, namespaceName, changeSet);
return ResponseEntity.status(HttpStatus.OK).build();
}
}
Expand Up @@ -47,12 +47,15 @@ public List<ReleaseDTO> find(@PathVariable("appId") String appId,

@RequestMapping("/apps/{appId}/clusters/{clusterName}/namespaces/{namespaceName}/releases/latest")
public ReleaseDTO getLatest(@PathVariable("appId") String appId,
@PathVariable("clusterName") String clusterName,
@PathVariable("namespaceName") String namespaceName) {
@PathVariable("clusterName") String clusterName,
@PathVariable("namespaceName") String namespaceName) {
Release release = configService.findRelease(appId, clusterName, namespaceName);
if (release == null) throw new NotFoundException(
String.format("latest release not found for %s %s %s", appId, clusterName, namespaceName));
return BeanUtils.transfrom(ReleaseDTO.class, release);
if (release == null) {
throw new NotFoundException(
String.format("latest release not found for %s %s %s", appId, clusterName, namespaceName));
} else {
return BeanUtils.transfrom(ReleaseDTO.class, release);
}
}

@RequestMapping(path = "/apps/{appId}/clusters/{clusterName}/namespaces/{namespaceName}/releases", method = RequestMethod.POST)
Expand Down
Expand Up @@ -97,4 +97,5 @@ private void preUpdate() {
private void preRemove() {
this.dataChangeLastModifiedTime = new Date();
}

}
10 changes: 10 additions & 0 deletions apollo-biz/src/main/java/com/ctrip/apollo/biz/entity/Item.java
Expand Up @@ -23,6 +23,9 @@ public class Item extends BaseEntity {
@Column
private String comment;

@Column
private int lineNum;

public String getComment() {
return comment;
}
Expand Down Expand Up @@ -55,4 +58,11 @@ public void setValue(String value) {
this.value = value;
}

public int getLineNum() {
return lineNum;
}

public void setLineNum(int lineNum) {
this.lineNum = lineNum;
}
}
Expand Up @@ -10,6 +10,6 @@ public interface ItemRepository extends PagingAndSortingRepository<Item, Long> {

List<Item> findByNamespaceIdIsIn(List<Long> namespaceIds);

List<Item> findByNamespaceId(Long namespaceId);
List<Item> findByNamespaceIdOrderByLineNumAsc(Long namespaceId);

}
Expand Up @@ -17,5 +17,5 @@ Release findFirstByAppIdAndClusterNameAndNamespaceNameOrderByIdDesc(@Param("appI
@Param("namespaceName") String namespaceName);

List<Release> findByAppIdAndClusterNameAndNamespaceName(String appId, String clusterName,
String namespaceName);
String namespaceName);
}
Expand Up @@ -4,32 +4,50 @@
import org.springframework.stereotype.Service;

import com.ctrip.apollo.biz.entity.Item;
import com.ctrip.apollo.biz.entity.Namespace;
import com.ctrip.apollo.biz.repository.ItemRepository;
import com.ctrip.apollo.biz.repository.NamespaceRepository;
import com.ctrip.apollo.biz.utils.BeanUtils;
import com.ctrip.apollo.core.dto.ItemChangeSets;
import com.ctrip.apollo.core.dto.ItemDTO;

import java.util.Date;

@Service
public class ItemSetService {

@Autowired
private ItemRepository itemRepository;
@Autowired
private NamespaceRepository namespaceRepository;

public void updateSet(ItemChangeSets changeSet) {
public void updateSet(String appId, String clusterName, String namespaceName, ItemChangeSets changeSet) {
Namespace namespace = namespaceRepository.findByAppIdAndClusterNameAndNamespaceName(appId, clusterName, namespaceName);

String modifyBy = changeSet.getModifyBy();
for (ItemDTO item : changeSet.getCreateItems()) {
Item entity = BeanUtils.transfrom(Item.class, item);

entity.setNamespaceId(namespace.getId());
entity.setDataChangeCreatedBy(modifyBy);
entity.setDataChangeCreatedTime(new Date());
entity.setDataChangeLastModifiedBy(modifyBy);
itemRepository.save(entity);
}

for (ItemDTO item : changeSet.getUpdateItems()) {
Item entity = BeanUtils.transfrom(Item.class, item);
Item managedItem = itemRepository.findOne(entity.getId());
BeanUtils.copyEntityProperties(entity, managedItem);
if (managedItem != null){
BeanUtils.copyEntityProperties(entity, managedItem, "id", "namespaceId", "key", "dataChangeCreatedBy", "dataChangeCreatedTime");
managedItem.setDataChangeLastModifiedBy(modifyBy);
}
itemRepository.save(managedItem);
}

for (ItemDTO item : changeSet.getDeletedItems()) {
Item entity = BeanUtils.transfrom(Item.class, item);
entity.setDataChangeLastModifiedBy(modifyBy);
itemRepository.delete(entity.getId());
}
}
Expand Down
Expand Up @@ -46,7 +46,7 @@ public Release buildRelease(String name, String comment, String appId, String cl
throw new NotFoundException(String.format("Could not find namespace for %s %s %s", appId,
clusterName, namespaceName));
}
List<Item> items = itemRepository.findByNamespaceId(namespace.getId());
List<Item> items = itemRepository.findByNamespaceIdOrderByLineNumAsc(namespace.getId());
Map<String, String> configurations = new HashMap<String, String>();
for (Item item : items) {
configurations.put(item.getKey(), item.getValue());
Expand Down
Expand Up @@ -65,7 +65,7 @@ public List<Item> findItems(String appId, String clusterName, String namespaceNa
}

public List<Item> findItems(Long namespaceId) {
List<Item> items = itemRepository.findByNamespaceId(namespaceId);
List<Item> items = itemRepository.findByNamespaceIdOrderByLineNumAsc(namespaceId);
if (items == null) {
return Collections.EMPTY_LIST;
}
Expand Down
Expand Up @@ -214,7 +214,7 @@ public static List toPropertyList(String key, List list) {
* @param source
* @param target
*/
public static void copyEntityProperties(Object source, Object target) {
org.springframework.beans.BeanUtils.copyProperties(source, target, "id");
public static void copyEntityProperties(Object source, Object target, String... ignoreProperties) {
org.springframework.beans.BeanUtils.copyProperties(source, target, ignoreProperties);
}
}
Expand Up @@ -9,28 +9,19 @@
public class ItemChangeSets {

private String modifyBy;
private List<ItemDTO> createItems;
private List<ItemDTO> updateItems;
private List<ItemDTO> deletedItems;
private List<ItemDTO> createItems = new LinkedList<>();
private List<ItemDTO> updateItems = new LinkedList<>();
private List<ItemDTO> deletedItems = new LinkedList<>();

public void addCreatedItem(ItemDTO item) {
if (createItems == null) {
createItems = new LinkedList<>();
}
createItems.add(item);
}

public void addupdateItem(ItemDTO item) {
if (updateItems == null) {
updateItems = new LinkedList<>();
}
public void addUpdateItem(ItemDTO item) {
updateItems.add(item);
}

public void addDeletedItem(ItemDTO item) {
if (deletedItems == null) {
deletedItems = new LinkedList<>();
}
deletedItems.add(item);
}

Expand Down
14 changes: 13 additions & 1 deletion apollo-core/src/main/java/com/ctrip/apollo/core/dto/ItemDTO.java
Expand Up @@ -2,7 +2,7 @@

import java.util.Date;

public class ItemDTO {
public class ItemDTO{

private long id;

Expand All @@ -14,6 +14,8 @@ public class ItemDTO {

private String comment;

private int lineNum;

private String dataChangeLastModifiedBy;

private Date dataChangeLastModifiedTime;
Expand Down Expand Up @@ -67,6 +69,14 @@ public void setValue(String value) {
this.value = value;
}

public int getLineNum() {
return lineNum;
}

public void setLineNum(int lineNum) {
this.lineNum = lineNum;
}

public String getDataChangeLastModifiedBy() {
return dataChangeLastModifiedBy;
}
Expand All @@ -91,8 +101,10 @@ public String toString() {
", key='" + key + '\'' +
", value='" + value + '\'' +
", comment='" + comment + '\'' +
", lineNum=" + lineNum +
", dataChangeLastModifiedBy='" + dataChangeLastModifiedBy + '\'' +
", dataChangeLastModifiedTime=" + dataChangeLastModifiedTime +
'}';
}

}

This file was deleted.

0 comments on commit 7b596e0

Please sign in to comment.