zhongjiajie commented on code in PR #10823: URL: https://github.com/apache/dolphinscheduler/pull/10823#discussion_r918012901
########## dolphinscheduler-python/pydolphinscheduler/tests/core/test_resource_definition.py: ########## @@ -0,0 +1,38 @@ +# 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. + +"""Test resource definition.""" + +from pydolphinscheduler.core.resource import Resource + + +def test_sql_get_define(): Review Comment: A little typo here ```suggestion def test_resource(): ``` ########## dolphinscheduler-python/pydolphinscheduler/src/pydolphinscheduler/core/process_definition.py: ########## @@ -63,6 +63,9 @@ class ProcessDefinition(Base): thought Web UI after it :func:`submit` or :func:`run`. It will create a new project belongs to ``user`` if it does not exists. And when ``project`` exists but project's create do not belongs to ``user``, will grant `project` to ``user`` automatically. + :param resource_list: Resource files required by the current process definition.You can create and modify Review Comment: ```suggestion :param resource_list: Resource files required by the current process definition. You can create and modify ``` ########## dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ResourcesServiceImpl.java: ########## @@ -1117,6 +1117,72 @@ public Result<Object> onlineCreateResource(User loginUser, ResourceType type, St return result; } + /** + * create or update resource. + * If the folder is not already created, it will be + * + * @param loginUser user who create or update resource + * @param fileFullName The full name of resource.Includes path and suffix. + * @param desc description of resource + * @param content content of resource + * @return create result code + */ + @Override + @Transactional + public Result<Object> onlineCreateOrUpdateResourceWithDir(User loginUser, String fileFullName, String desc, String content) { + if (checkResourceExists(fileFullName, ResourceType.FILE.ordinal())) { + Resource resource = resourcesMapper.queryResource(fileFullName, ResourceType.FILE.ordinal()).get(0); + Result<Object> result = this.updateResourceContent(loginUser, resource.getId(), content); + if (result.getCode() == Status.SUCCESS.getCode()) { + resource.setDescription(desc); + Map<String, Object> resultMap = new HashMap<>(); + for (Map.Entry<Object, Object> entry : new BeanMap(resource).entrySet()) { + if (!Constants.CLASS.equalsIgnoreCase(entry.getKey().toString())) { + resultMap.put(entry.getKey().toString(), entry.getValue()); + } + } + result.setData(resultMap); + } + return result; + } else { + String resourceSuffix = fileFullName.substring(fileFullName.indexOf(".") + 1); + String fileNameWithSuffix = fileFullName.substring(fileFullName.lastIndexOf("/") + 1); + String resourceDir = fileFullName.replace(fileNameWithSuffix, ""); Review Comment: also have `EMPTY_STRING` constants for `""` ########## dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/ResourcesServiceTest.java: ########## @@ -605,6 +605,64 @@ public void testOnlineCreateResource() { } + @Test + public void testOnlineCreateResourceWithDir() { Review Comment: good to see you add test for service 👍 ########## dolphinscheduler-python/pydolphinscheduler/src/pydolphinscheduler/core/process_definition.py: ########## @@ -63,6 +63,9 @@ class ProcessDefinition(Base): thought Web UI after it :func:`submit` or :func:`run`. It will create a new project belongs to ``user`` if it does not exists. And when ``project`` exists but project's create do not belongs to ``user``, will grant `project` to ``user`` automatically. + :param resource_list: Resource files required by the current process definition.You can create and modify Review Comment: Great! thanks for adding this docstring -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
