parent
7f52271ee5
commit
f6792b225a
@ -1,44 +0,0 @@ |
||||
/* |
||||
* Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria)
|
||||
* |
||||
* Licensed 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 com.arialyy.aria.core.download.wrapper; |
||||
|
||||
import com.arialyy.aria.core.download.DGTaskWrapper; |
||||
import com.arialyy.aria.core.download.DTaskWrapper; |
||||
import com.arialyy.aria.orm.AbsWrapper; |
||||
import com.arialyy.aria.orm.annotation.Many; |
||||
import com.arialyy.aria.orm.annotation.One; |
||||
import com.arialyy.aria.orm.annotation.Wrapper; |
||||
import java.util.List; |
||||
|
||||
/** |
||||
* Created by laoyuyu on 2018/4/11. |
||||
* 任务组任务实体和任务组任务实体的子任务实体对应关系 |
||||
*/ |
||||
@Wrapper |
||||
public class DGSTEWrapper extends AbsWrapper { |
||||
|
||||
@One |
||||
public DGTaskWrapper dgTaskEntity; |
||||
|
||||
@Many(parentColumn = "key", entityColumn = "groupName") |
||||
public List<DTaskWrapper> subTaskEntity; |
||||
|
||||
@Override protected void handleConvert() { |
||||
if (subTaskEntity != null && !subTaskEntity.isEmpty()) { |
||||
dgTaskEntity.setSubTaskWrapper(subTaskEntity); |
||||
} |
||||
} |
||||
} |
@ -1,65 +0,0 @@ |
||||
/* |
||||
* Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria)
|
||||
* |
||||
* Licensed 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 com.arialyy.aria.core.download.wrapper; |
||||
|
||||
import com.arialyy.aria.core.download.DGTaskWrapper; |
||||
import com.arialyy.aria.core.download.DownloadGroupEntity; |
||||
import com.arialyy.aria.core.download.DTaskWrapper; |
||||
import com.arialyy.aria.core.inf.AbsTaskWrapper; |
||||
import com.arialyy.aria.orm.AbsWrapper; |
||||
import com.arialyy.aria.orm.DbEntity; |
||||
import com.arialyy.aria.orm.annotation.Many; |
||||
import com.arialyy.aria.orm.annotation.One; |
||||
import com.arialyy.aria.orm.annotation.Wrapper; |
||||
import com.arialyy.aria.util.CommonUtil; |
||||
import java.util.ArrayList; |
||||
import java.util.List; |
||||
|
||||
/** |
||||
* Created by laoyuyu on 2018/3/30. |
||||
* 任务组实体和任务组任务实体的关系 |
||||
*/ |
||||
@Wrapper |
||||
public class DGTEWrapper extends AbsWrapper { |
||||
|
||||
@One |
||||
public DownloadGroupEntity entity; |
||||
|
||||
@Many(parentColumn = "groupName", entityColumn = "key") |
||||
private List<DGTaskWrapper> taskEntitys; |
||||
|
||||
public DGTaskWrapper taskEntity; |
||||
|
||||
@Override protected void handleConvert() { |
||||
taskEntity = (taskEntitys == null || taskEntitys.isEmpty()) ? null : taskEntitys.get(0); |
||||
if (taskEntity != null) { |
||||
taskEntity.setEntity(entity); |
||||
List<DTEWrapper> subWrappers = |
||||
DbEntity.findRelationData(DTEWrapper.class, "DTaskWrapper.groupName=?", |
||||
taskEntity.getKey()); |
||||
if (subWrappers != null && !subWrappers.isEmpty()) { |
||||
List<DTaskWrapper> temp = new ArrayList<>(); |
||||
for (DTEWrapper dw : subWrappers) { |
||||
if (dw.taskEntity.getRequestType() == AbsTaskWrapper.D_FTP) { |
||||
dw.taskEntity.asFtp().setUrlEntity(CommonUtil.getFtpUrlInfo(dw.taskEntity.getUrl())); |
||||
} |
||||
temp.add(dw.taskEntity); |
||||
} |
||||
taskEntity.setSubTaskWrapper(temp); |
||||
} |
||||
} |
||||
} |
||||
} |
@ -1,46 +0,0 @@ |
||||
/* |
||||
* Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria)
|
||||
* |
||||
* Licensed 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 com.arialyy.aria.core.download.wrapper; |
||||
|
||||
import com.arialyy.aria.core.download.DownloadEntity; |
||||
import com.arialyy.aria.core.download.DTaskWrapper; |
||||
import com.arialyy.aria.orm.AbsWrapper; |
||||
import com.arialyy.aria.orm.annotation.Many; |
||||
import com.arialyy.aria.orm.annotation.One; |
||||
import com.arialyy.aria.orm.annotation.Wrapper; |
||||
import java.util.List; |
||||
|
||||
/** |
||||
* Created by laoyuyu on 2018/3/30. |
||||
*/ |
||||
@Wrapper |
||||
public class DTEWrapper extends AbsWrapper { |
||||
|
||||
@One |
||||
public DownloadEntity entity; |
||||
|
||||
@Many(parentColumn = "downloadPath", entityColumn = "key") |
||||
private List<DTaskWrapper> taskEntitys = null; |
||||
|
||||
public DTaskWrapper taskEntity; |
||||
|
||||
@Override public void handleConvert() { |
||||
taskEntity = (taskEntitys == null || taskEntitys.isEmpty()) ? null : taskEntitys.get(0); |
||||
if (taskEntity != null) { |
||||
taskEntity.setEntity(entity); |
||||
} |
||||
} |
||||
} |
@ -1,168 +0,0 @@ |
||||
/* |
||||
* Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria)
|
||||
* |
||||
* Licensed 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 com.arialyy.aria.core.manager; |
||||
|
||||
import com.arialyy.aria.core.download.DGTaskWrapper; |
||||
import com.arialyy.aria.core.download.DTaskWrapper; |
||||
import com.arialyy.aria.core.download.DownloadEntity; |
||||
import com.arialyy.aria.core.download.DownloadGroupEntity; |
||||
import com.arialyy.aria.core.download.wrapper.DGEWrapper; |
||||
import com.arialyy.aria.core.download.wrapper.DGTEWrapper; |
||||
import com.arialyy.aria.orm.DbEntity; |
||||
import com.arialyy.aria.util.CommonUtil; |
||||
import java.io.File; |
||||
import java.util.ArrayList; |
||||
import java.util.List; |
||||
|
||||
/** |
||||
* Created by Aria.Lao on 2017/11/1. |
||||
* 任务实体工厂 |
||||
*/ |
||||
class DGTEFactory implements IGTEFactory<DownloadGroupEntity, DGTaskWrapper> { |
||||
private static final String TAG = "DTEFactory"; |
||||
private static volatile DGTEFactory INSTANCE = null; |
||||
|
||||
private DGTEFactory() { |
||||
} |
||||
|
||||
public static DGTEFactory getInstance() { |
||||
if (INSTANCE == null) { |
||||
synchronized (DGTEFactory.class) { |
||||
INSTANCE = new DGTEFactory(); |
||||
} |
||||
} |
||||
return INSTANCE; |
||||
} |
||||
|
||||
@Override public DGTaskWrapper getGTE(String groupName, List<String> urls) { |
||||
DownloadGroupEntity entity = createDGroupEntity(groupName, urls); |
||||
List<DGTEWrapper> wrapper = |
||||
DbEntity.findRelationData(DGTEWrapper.class, "DGTaskWrapper.key=?", |
||||
entity.getGroupName()); |
||||
DGTaskWrapper gte; |
||||
|
||||
if (wrapper != null && !wrapper.isEmpty()) { |
||||
gte = wrapper.get(0).taskEntity; |
||||
if (gte == null) { |
||||
// 创建新的任务组任务实体
|
||||
gte = new DGTaskWrapper(); |
||||
} |
||||
} else { |
||||
gte = new DGTaskWrapper(); |
||||
} |
||||
gte.setSubTaskWrapper(createDGSubTaskEntity(entity)); |
||||
gte.setKey(entity.getGroupName()); |
||||
gte.setEntity(entity); |
||||
|
||||
return gte; |
||||
} |
||||
|
||||
@Override public DGTaskWrapper getFTE(String ftpUrl) { |
||||
List<DGTEWrapper> wrapper = |
||||
DbEntity.findRelationData(DGTEWrapper.class, "DGTaskWrapper.key=?", |
||||
ftpUrl); |
||||
DGTaskWrapper fte; |
||||
|
||||
if (wrapper != null && !wrapper.isEmpty()) { |
||||
fte = wrapper.get(0).taskEntity; |
||||
if (fte == null) { |
||||
fte = new DGTaskWrapper(); |
||||
DownloadGroupEntity dge = new DownloadGroupEntity(); |
||||
dge.setGroupName(ftpUrl); |
||||
fte.setEntity(dge); |
||||
} else if (fte.getEntity() == null) { |
||||
DownloadGroupEntity dge = new DownloadGroupEntity(); |
||||
dge.setGroupName(ftpUrl); |
||||
fte.setEntity(dge); |
||||
} |
||||
} else { |
||||
fte = new DGTaskWrapper(); |
||||
DownloadGroupEntity dge = new DownloadGroupEntity(); |
||||
dge.setGroupName(ftpUrl); |
||||
fte.setEntity(dge); |
||||
} |
||||
fte.setKey(ftpUrl); |
||||
fte.asFtp().setUrlEntity(CommonUtil.getFtpUrlInfo(ftpUrl)); |
||||
|
||||
if (fte.getEntity().getSubEntities() == null) { |
||||
fte.getEntity().setSubEntities(new ArrayList<DownloadEntity>()); |
||||
} |
||||
if (fte.getSubTaskWrapper() == null) { |
||||
fte.setSubTaskWrapper(new ArrayList<DTaskWrapper>()); |
||||
} |
||||
return fte; |
||||
} |
||||
|
||||
/** |
||||
* 创建任务组子任务的任务实体 |
||||
*/ |
||||
private List<DTaskWrapper> createDGSubTaskEntity(DownloadGroupEntity dge) { |
||||
List<DTaskWrapper> list = new ArrayList<>(); |
||||
for (DownloadEntity entity : dge.getSubEntities()) { |
||||
DTaskWrapper taskEntity = new DTaskWrapper(); |
||||
taskEntity.setEntity(entity); |
||||
taskEntity.setKey(entity.getDownloadPath()); |
||||
taskEntity.setGroupName(dge.getKey()); |
||||
taskEntity.setGroupTask(true); |
||||
taskEntity.setUrl(entity.getUrl()); |
||||
list.add(taskEntity); |
||||
} |
||||
return list; |
||||
} |
||||
|
||||
/** |
||||
* 查询任务组实体,如果数据库不存在该实体,则新创建一个新的任务组实体 |
||||
*/ |
||||
private DownloadGroupEntity createDGroupEntity(String groupName, List<String> urls) { |
||||
List<DGEWrapper> wrapper = |
||||
DbEntity.findRelationData(DGEWrapper.class, "DownloadGroupEntity.groupName=?", |
||||
groupName); |
||||
|
||||
DownloadGroupEntity groupEntity; |
||||
if (wrapper != null && !wrapper.isEmpty()) { |
||||
groupEntity = wrapper.get(0).groupEntity; |
||||
if (groupEntity == null) { |
||||
groupEntity = new DownloadGroupEntity(); |
||||
groupEntity.setSubEntities(createSubTask(groupName, urls)); |
||||
} |
||||
} else { |
||||
groupEntity = new DownloadGroupEntity(); |
||||
groupEntity.setSubEntities(createSubTask(groupName, urls)); |
||||
} |
||||
groupEntity.setGroupName(groupName); |
||||
groupEntity.setUrls(urls); |
||||
return groupEntity; |
||||
} |
||||
|
||||
/** |
||||
* 创建子任务 |
||||
*/ |
||||
private List<DownloadEntity> createSubTask(String groupName, List<String> urls) { |
||||
List<DownloadEntity> list = new ArrayList<>(); |
||||
for (int i = 0, len = urls.size(); i < len; i++) { |
||||
String url = urls.get(i); |
||||
DownloadEntity entity = new DownloadEntity(); |
||||
entity.setUrl(url); |
||||
entity.setDownloadPath(groupName + "_" + i); |
||||
int lastIndex = url.lastIndexOf(File.separator); |
||||
entity.setFileName(url.substring(lastIndex + 1, url.length())); |
||||
entity.setGroupName(groupName); |
||||
entity.setGroupChild(true); |
||||
list.add(entity); |
||||
} |
||||
return list; |
||||
} |
||||
} |
@ -0,0 +1,90 @@ |
||||
/* |
||||
* Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria)
|
||||
* |
||||
* Licensed 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 com.arialyy.aria.core.manager; |
||||
|
||||
import com.arialyy.aria.core.download.DGTaskWrapper; |
||||
import com.arialyy.aria.core.download.DTaskWrapper; |
||||
import com.arialyy.aria.core.download.DownloadEntity; |
||||
import com.arialyy.aria.core.download.DownloadGroupEntity; |
||||
import com.arialyy.aria.core.download.DGEntityWrapper; |
||||
import com.arialyy.aria.orm.DbEntity; |
||||
import com.arialyy.aria.util.CommonUtil; |
||||
import com.arialyy.aria.util.DbDataHelper; |
||||
import java.io.File; |
||||
import java.util.ArrayList; |
||||
import java.util.List; |
||||
|
||||
/** |
||||
* Created by Aria.Lao on 2017/11/1. 组合任务wrapper |
||||
*/ |
||||
class DGTaskWrapperFactory implements IGTEFactory<DownloadGroupEntity, DGTaskWrapper> { |
||||
private static final String TAG = "DTaskWrapperFactory"; |
||||
private static volatile DGTaskWrapperFactory INSTANCE = null; |
||||
|
||||
private DGTaskWrapperFactory() { |
||||
} |
||||
|
||||
public static DGTaskWrapperFactory getInstance() { |
||||
if (INSTANCE == null) { |
||||
synchronized (DGTaskWrapperFactory.class) { |
||||
INSTANCE = new DGTaskWrapperFactory(); |
||||
} |
||||
} |
||||
return INSTANCE; |
||||
} |
||||
|
||||
@Override public DGTaskWrapper getGTE(String groupName, List<String> urls) { |
||||
DownloadGroupEntity entity = DbDataHelper.getHttpDGEntity(groupName, urls); |
||||
DGTaskWrapper wrapper = new DGTaskWrapper(entity); |
||||
wrapper.setSubTaskWrapper(createDGSubTaskWrapper(entity)); |
||||
wrapper.setKey(entity.getGroupName()); |
||||
return wrapper; |
||||
} |
||||
|
||||
@Override public DGTaskWrapper getFTE(String ftpUrl) { |
||||
DownloadGroupEntity entity = DbDataHelper.getFtpDGEntity(ftpUrl); |
||||
DGTaskWrapper fte = new DGTaskWrapper(entity); |
||||
|
||||
fte.setKey(ftpUrl); |
||||
fte.asFtp().setUrlEntity(CommonUtil.getFtpUrlInfo(ftpUrl)); |
||||
|
||||
if (fte.getEntity().getSubEntities() == null) { |
||||
fte.getEntity().setSubEntities(new ArrayList<DownloadEntity>()); |
||||
} |
||||
if (fte.getSubTaskWrapper() == null) { |
||||
fte.setSubTaskWrapper(new ArrayList<DTaskWrapper>()); |
||||
} |
||||
return fte; |
||||
} |
||||
|
||||
/** |
||||
* 创建任务组子任务的任务实体 |
||||
*/ |
||||
private List<DTaskWrapper> createDGSubTaskWrapper(DownloadGroupEntity dge) { |
||||
List<DTaskWrapper> list = new ArrayList<>(); |
||||
for (DownloadEntity entity : dge.getSubEntities()) { |
||||
DTaskWrapper taskEntity = new DTaskWrapper(entity); |
||||
taskEntity.setKey(entity.getDownloadPath()); |
||||
taskEntity.setGroupName(dge.getKey()); |
||||
taskEntity.setGroupTask(true); |
||||
taskEntity.setUrl(entity.getUrl()); |
||||
list.add(taskEntity); |
||||
} |
||||
return list; |
||||
} |
||||
|
||||
|
||||
} |
@ -1,47 +0,0 @@ |
||||
/* |
||||
* Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria)
|
||||
* |
||||
* Licensed 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 com.arialyy.aria.core.upload.wrapper; |
||||
|
||||
import com.arialyy.aria.core.upload.UTaskWrapper; |
||||
import com.arialyy.aria.core.upload.UploadEntity; |
||||
import com.arialyy.aria.orm.AbsWrapper; |
||||
import com.arialyy.aria.orm.annotation.Many; |
||||
import com.arialyy.aria.orm.annotation.One; |
||||
import com.arialyy.aria.orm.annotation.Wrapper; |
||||
import java.util.List; |
||||
|
||||
/** |
||||
* Created by laoyuyu on 2018/3/30. |
||||
*/ |
||||
@Wrapper |
||||
public class UTEWrapper extends AbsWrapper { |
||||
|
||||
@One |
||||
public UploadEntity entity; |
||||
|
||||
@Many(parentColumn = "filePath", entityColumn = "key") |
||||
private List<UTaskWrapper> taskEntitys = null; |
||||
|
||||
public UTaskWrapper taskEntity; |
||||
|
||||
@Override public void handleConvert() { |
||||
//taskEntity.entity = (tEntity == null || tEntity.isEmpty()) ? null : tEntity.get(0);
|
||||
taskEntity = (taskEntitys == null || taskEntitys.isEmpty()) ? null : taskEntitys.get(0); |
||||
if (taskEntity != null) { |
||||
taskEntity.setEntity(entity); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,115 @@ |
||||
/* |
||||
* Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria)
|
||||
* |
||||
* Licensed 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 com.arialyy.aria.util; |
||||
|
||||
import com.arialyy.aria.core.common.RecordWrapper; |
||||
import com.arialyy.aria.core.common.TaskRecord; |
||||
import com.arialyy.aria.core.download.DGEntityWrapper; |
||||
import com.arialyy.aria.core.download.DownloadEntity; |
||||
import com.arialyy.aria.core.download.DownloadGroupEntity; |
||||
import com.arialyy.aria.orm.DbEntity; |
||||
import java.io.File; |
||||
import java.util.ArrayList; |
||||
import java.util.List; |
||||
|
||||
/** |
||||
* 数据库帮助类 |
||||
*/ |
||||
public class DbDataHelper { |
||||
|
||||
/** |
||||
* 获取任务记录 |
||||
* |
||||
* @param filePath 文件地址 |
||||
* @return 没有记录返回null,有记录则返回任务记录 |
||||
*/ |
||||
public static TaskRecord getTaskRecord(String filePath) { |
||||
List<RecordWrapper> records = |
||||
DbEntity.findRelationData(RecordWrapper.class, "TaskRecord.filePath=?", filePath); |
||||
if (records == null || records.size() == 0) { |
||||
return null; |
||||
} |
||||
return records.get(0).taskRecord; |
||||
} |
||||
|
||||
/** |
||||
* 获取组合任务实体 如果数据库不存在该实体,则新创建一个新的任务组实体 |
||||
* |
||||
* @param groupName 组合任务名称 |
||||
* @param urls 子任务url列表 |
||||
*/ |
||||
public static DownloadGroupEntity getHttpDGEntity(String groupName, List<String> urls) { |
||||
List<DGEntityWrapper> wrapper = |
||||
DbEntity.findRelationData(DGEntityWrapper.class, "DownloadGroupEntity.groupName=?", |
||||
groupName); |
||||
|
||||
DownloadGroupEntity groupEntity; |
||||
if (wrapper != null && !wrapper.isEmpty()) { |
||||
groupEntity = wrapper.get(0).groupEntity; |
||||
if (groupEntity == null) { |
||||
groupEntity = new DownloadGroupEntity(); |
||||
groupEntity.setSubEntities(createHttpSubTask(groupName, urls)); |
||||
} |
||||
} else { |
||||
groupEntity = new DownloadGroupEntity(); |
||||
groupEntity.setSubEntities(createHttpSubTask(groupName, urls)); |
||||
} |
||||
groupEntity.setGroupName(groupName); |
||||
groupEntity.setUrls(urls); |
||||
return groupEntity; |
||||
} |
||||
|
||||
/** |
||||
* 创建HTTP子任务实体 |
||||
*/ |
||||
private static List<DownloadEntity> createHttpSubTask(String groupName, List<String> urls) { |
||||
List<DownloadEntity> list = new ArrayList<>(); |
||||
for (int i = 0, len = urls.size(); i < len; i++) { |
||||
String url = urls.get(i); |
||||
DownloadEntity entity = new DownloadEntity(); |
||||
entity.setUrl(url); |
||||
entity.setDownloadPath(groupName + "_" + i); |
||||
int lastIndex = url.lastIndexOf(File.separator); |
||||
entity.setFileName(url.substring(lastIndex + 1)); |
||||
entity.setGroupName(groupName); |
||||
entity.setGroupChild(true); |
||||
list.add(entity); |
||||
} |
||||
return list; |
||||
} |
||||
|
||||
/** |
||||
* 通过Ftp下载地址获取组合任务实体 |
||||
* |
||||
* @param ftpUrl ftp下载地址 |
||||
*/ |
||||
public static DownloadGroupEntity getFtpDGEntity(String ftpUrl) { |
||||
List<DGEntityWrapper> wrapper = |
||||
DbEntity.findRelationData(DGEntityWrapper.class, "DownloadGroupEntity.groupName=?", |
||||
ftpUrl); |
||||
DownloadGroupEntity groupEntity; |
||||
if (wrapper != null && !wrapper.isEmpty()) { |
||||
groupEntity = wrapper.get(0).groupEntity; |
||||
if (groupEntity == null) { |
||||
groupEntity = new DownloadGroupEntity(); |
||||
} |
||||
} else { |
||||
groupEntity = new DownloadGroupEntity(); |
||||
} |
||||
groupEntity.setGroupName(ftpUrl); |
||||
return groupEntity; |
||||
} |
||||
} |
@ -1,42 +0,0 @@ |
||||
/* |
||||
* Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria)
|
||||
* |
||||
* Licensed 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 com.arialyy.aria.util; |
||||
|
||||
import com.arialyy.aria.core.common.RecordWrapper; |
||||
import com.arialyy.aria.core.common.TaskRecord; |
||||
import com.arialyy.aria.orm.DbEntity; |
||||
import java.util.List; |
||||
|
||||
/** |
||||
* 数据库帮助类 |
||||
*/ |
||||
public class DbHelper { |
||||
|
||||
/** |
||||
* 获取任务记录 |
||||
* |
||||
* @param filePath 文件地址 |
||||
* @return 没有记录返回null,有记录则返回任务记录 |
||||
*/ |
||||
public static TaskRecord getTaskRecord(String filePath) { |
||||
List<RecordWrapper> records = |
||||
DbEntity.findRelationData(RecordWrapper.class, "TaskRecord.filePath=?", filePath); |
||||
if (records == null || records.size() == 0) { |
||||
return null; |
||||
} |
||||
return records.get(0).taskRecord; |
||||
} |
||||
} |
Loading…
Reference in new issue