| 1 | |
package com.ctrip.apollo.adminservice.controller; |
| 2 | |
|
| 3 | |
import org.springframework.beans.factory.annotation.Autowired; |
| 4 | |
import org.springframework.security.core.userdetails.UserDetails; |
| 5 | |
import org.springframework.web.bind.annotation.PathVariable; |
| 6 | |
import org.springframework.web.bind.annotation.RequestBody; |
| 7 | |
import org.springframework.web.bind.annotation.RequestMapping; |
| 8 | |
import org.springframework.web.bind.annotation.RequestMethod; |
| 9 | |
import org.springframework.web.bind.annotation.RestController; |
| 10 | |
|
| 11 | |
import com.ctrip.apollo.biz.entity.AppNamespace; |
| 12 | |
import com.ctrip.apollo.biz.service.AppNamespaceService; |
| 13 | |
import com.ctrip.apollo.common.auth.ActiveUser; |
| 14 | |
import com.ctrip.apollo.common.utils.BeanUtils; |
| 15 | |
import com.ctrip.apollo.core.dto.AppNamespaceDTO; |
| 16 | |
|
| 17 | |
import java.util.List; |
| 18 | |
|
| 19 | |
@RestController |
| 20 | 1 | public class AppNamespaceController { |
| 21 | |
|
| 22 | |
@Autowired |
| 23 | |
private AppNamespaceService appNamespaceService; |
| 24 | |
|
| 25 | |
@RequestMapping("/apps/{appId}/appnamespace/{appnamespace}/unique") |
| 26 | |
public boolean isAppNamespaceUnique(@PathVariable("appId") String appId, |
| 27 | |
@PathVariable("appnamespace") String appnamespace) { |
| 28 | 0 | return appNamespaceService.isAppNamespaceNameUnique(appId, appnamespace); |
| 29 | |
} |
| 30 | |
|
| 31 | |
@RequestMapping("/appnamespaces/public") |
| 32 | |
public List<AppNamespaceDTO> findPublicAppNamespaces(){ |
| 33 | 0 | List<AppNamespace> appNamespaces = appNamespaceService.findPublicAppNamespaces(); |
| 34 | 0 | return BeanUtils.batchTransform(AppNamespaceDTO.class, appNamespaces); |
| 35 | |
} |
| 36 | |
|
| 37 | |
@RequestMapping(value = "/apps/{appId}/appnamespaces", method = RequestMethod.POST) |
| 38 | |
public AppNamespaceDTO createOrUpdate( @RequestBody AppNamespaceDTO appNamespace, @ActiveUser UserDetails user){ |
| 39 | |
|
| 40 | 0 | AppNamespace entity = BeanUtils.transfrom(AppNamespace.class, appNamespace); |
| 41 | 0 | AppNamespace managedEntity = appNamespaceService.findOne(entity.getAppId(), entity.getName()); |
| 42 | |
|
| 43 | 0 | String userName = user.getUsername(); |
| 44 | 0 | if (managedEntity != null){ |
| 45 | 0 | managedEntity.setDataChangeLastModifiedBy(userName); |
| 46 | 0 | BeanUtils.copyEntityProperties(entity, managedEntity); |
| 47 | 0 | entity = appNamespaceService.update(managedEntity); |
| 48 | |
}else { |
| 49 | 0 | entity.setDataChangeLastModifiedBy(userName); |
| 50 | 0 | entity.setDataChangeCreatedBy(userName); |
| 51 | 0 | entity = appNamespaceService.createAppNamespace(entity, userName); |
| 52 | |
} |
| 53 | |
|
| 54 | 0 | return BeanUtils.transfrom(AppNamespaceDTO.class, entity); |
| 55 | |
|
| 56 | |
} |
| 57 | |
|
| 58 | |
} |