Skip to content

Commit

Permalink
[10983][refactor] ResourcesController
Browse files Browse the repository at this point in the history
  • Loading branch information
liguotian committed Jul 18, 2022
1 parent d41dac0 commit 79d02ec
Show file tree
Hide file tree
Showing 21 changed files with 1,757 additions and 244 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ public class BaseController {
* @param pageSize page size
* @return check result code
*/
public Result checkPageParams(int pageNo, int pageSize) {
Result result = new Result();
public <T> Result<T> checkPageParams(int pageNo, int pageSize) {
Result<T> result = new Result<>();
Status resultEnum = Status.SUCCESS;
String msg = Status.SUCCESS.getMsg();
if (pageNo <= 0) {
Expand Down Expand Up @@ -198,8 +198,8 @@ public Result success(Object totalList, Integer currentPage,
* @param msg result message
* @return error result code
*/
public Result error(Integer code, String msg) {
Result result = new Result();
public <T> Result<T> error(Integer code, String msg) {
Result<T> result = new Result<>();
result.setCode(code);
result.setMsg(msg);
return result;
Expand Down

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.apache.dolphinscheduler.api.dto.resources;

import org.apache.dolphinscheduler.spi.enums.ResourceType;

import java.io.Serializable;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

/**
* @author lgt
*/
@Data
@ApiModel(value = "CREATE_RESOURCE_NOTES")
public class CreateDirectoryRequest implements Serializable {

private static final long serialVersionUID = 2158023425391177729L;

@ApiModelProperty(name = "type", value = "RESOURCE_TYPE", required = true, example = "FILE")
private ResourceType type;

@ApiModelProperty(name = "name", value = "RESOURCE_NAME", required = true)
private String name;

@ApiModelProperty(name = "description", value = "RESOURCE_DESC")
private String description;

@ApiModelProperty(name = "pid", value = "RESOURCE_PID", required = true, example = "10")
private int pid;

@ApiModelProperty(name = "currentDir", value = "RESOURCE_CURRENT_DIR", required = true, example = "firstDir")
private String currentDir;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.apache.dolphinscheduler.api.dto.resources;

import org.apache.dolphinscheduler.spi.enums.ResourceType;

import java.io.Serializable;

import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

/**
* @author lgt
*/
@Data
public class CreateResourceRequest implements Serializable {

private static final long serialVersionUID = -4751002150934450475L;

@ApiModelProperty(name = "type", value = "RESOURCE_TYPE", notes = "FILE , UDF", required = true, example = "FILE")
private ResourceType type;

@ApiModelProperty(name = "fileName", value = "RESOURCE_NAME", required = true)
private String fileName;

@ApiModelProperty(name = "suffix", value = "SUFFIX", required = true)
private String suffix;

@ApiModelProperty(name = "description", value = "RESOURCE_DESC")
private String description;

@ApiModelProperty(name = "pid", value = "RESOURCE_PID", required = true, example = "10")
private int pid;

@ApiModelProperty(name = "content", value = "CONTENT", required = true)
private String content;

@ApiModelProperty(name = "currentDir", value = "RESOURCE_CURRENT_DIR", required = true, example = "firstDir")
private String currentDir;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.apache.dolphinscheduler.api.dto.resources;

import org.apache.dolphinscheduler.common.enums.UdfType;

import java.io.Serializable;

import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

/**
* @author lgt
*/
@Data
public class CreateUdfRequest implements Serializable {

private static final long serialVersionUID = 808084395565216909L;

@ApiModelProperty(name = "type", value = "UDF_TYPE", required = true, dataType = "UdfType", example = "HIVE,SPARK")
private UdfType type;

@ApiModelProperty(name = "funcName", value = "FUNC_NAME", required = true, dataType = "String", example = "evaluate")
private String funcName;

@ApiModelProperty(name = "className", value = "CLASS_NAME", required = true, dataType = "String", example = "GetLength")
private String className;

@ApiModelProperty(name = "argTypes", value = "ARG_TYPES", dataType = "String", example = "String")
private String argTypes;

@ApiModelProperty(name = "database", value = "DATABASE_NAME", dataType = "String", example = "db")
private String database;

@ApiModelProperty(name = "description", value = "UDF_DESC", dataType = "String", example = "description")
private String description;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.apache.dolphinscheduler.api.dto.resources;

import java.io.Serializable;

import lombok.Data;

/**
* @author lgt
*/
@Data
public class ResourceContent implements Serializable {

private static final long serialVersionUID = 7030124374980790556L;

private String content;

private String alias;

private String fileName;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.apache.dolphinscheduler.api.dto.resources;

import java.io.Serializable;

import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

/**
* @author lgt
*/
@Data
public class UpdateResourceContentRequest implements Serializable {

private static final long serialVersionUID = 915936285961774517L;

@ApiModelProperty(name = "content", value = "CONTENT", required = true, example = "content")
private String content;
}
Original file line number Diff line number Diff line change
Expand Up @@ -512,8 +512,8 @@ public Map<String, Object> getDependentInfo(String projectName, String processDe
public Map<String, Object> getResourcesFileInfo(String programType, String fullName) {
Map<String, Object> result = new HashMap<>();

Result<Object> resources = resourceService.queryResourceByProgramType(dummyAdminUser, ResourceType.FILE, ProgramType.valueOf(programType));
List<ResourceComponent> resourcesComponent = (List<ResourceComponent>) resources.getData();
Result<List<ResourceComponent>> resources = resourceService.queryResourceByProgramType(dummyAdminUser, ResourceType.FILE, ProgramType.valueOf(programType));
List<ResourceComponent> resourcesComponent = resources.getData();
List<ResourceComponent> namedResources = resourcesComponent.stream().filter(s -> fullName.equals(s.getFullName())).collect(Collectors.toList());
if (CollectionUtils.isEmpty(namedResources)) {
String msg = String.format("Can not find valid resource by program type %s and name %s", programType, fullName);
Expand All @@ -536,13 +536,13 @@ public Map<String, Object> getResourcesFileInfo(String programType, String fullN
public Map<String, Object> queryResourcesFileInfo(String userName, String fullName) {
Map<String, Object> result = new HashMap<>();
User user = usersService.queryUser(userName);
Result<Object> resourceResponse = resourceService.queryResource(user, fullName, null, ResourceType.FILE);
Result<Resource> resourceResponse = resourceService.queryResource(user, fullName, null, ResourceType.FILE);
if (resourceResponse.getCode() != Status.SUCCESS.getCode()) {
String msg = String.format("Can not find valid resource by name %s", fullName);
logger.error(msg);
throw new IllegalArgumentException(msg);
}
Resource resource = (Resource) resourceResponse.getData();
Resource resource = resourceResponse.getData();
result.put("id", resource.getId());
result.put("name", resource.getFullName());
return result;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,14 @@ public interface BaseService {
*/
void putMsg(Result<Object> result, Status status, Object... statusParams);

/**
* copy result msg from source to target
*
* @param source source result
* @param target target result
*/
void copyMsg(Result source, Result target);

/**
* check
*
Expand Down
Loading

0 comments on commit 79d02ec

Please sign in to comment.