Skip to content

Commit 90fe7f2

Browse files
committed
Merge branch 'feat-commands' of https://github.com/CSC207-2022F-UofT/mcpm into feat-commands
2 parents 23c0b85 + 60ed54d commit 90fe7f2

File tree

6 files changed

+781
-6
lines changed

6 files changed

+781
-6
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package org.hydev.mcpm.client.database;
2+
3+
import org.hydev.mcpm.client.database.boundary.CheckForUpdatesBoundary;
4+
import org.hydev.mcpm.client.models.PluginYml;
5+
6+
import java.util.List;
7+
8+
/**
9+
* Interface for listing all plugins
10+
*
11+
* @author Kevin (https://github.com/kchprog)
12+
* @since 2022-11-20
13+
*/
14+
public interface ListAllBoundary {
15+
16+
/**
17+
* listAllInteractor interacts with the LocalPluginTracker to get the list of
18+
* plugins, according to a specified
19+
* parameter
20+
*
21+
* @param parameter The parameter for the ListAll use case. 'All' denotes a
22+
* request to list all manually
23+
* installed plugins, 'manual' denotes a request to list all
24+
* manually installed plugins, and 'outdated' denotes
25+
* a request to list all manually installed plugins that are
26+
* outdated.
27+
*/
28+
List<PluginYml> listAll(String parameter, CheckForUpdatesBoundary checkForUpdatesBoundary);
29+
}
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
package org.hydev.mcpm.client.database;
2+
3+
import org.apache.commons.lang3.NotImplementedException;
4+
import org.hydev.mcpm.client.database.boundary.CheckForUpdatesBoundary;
5+
import org.hydev.mcpm.client.database.inputs.CheckForUpdatesInput;
6+
import org.hydev.mcpm.client.database.inputs.CheckForUpdatesResult;
7+
import org.hydev.mcpm.client.database.model.PluginVersionState;
8+
import org.hydev.mcpm.client.models.PluginYml;
9+
import org.hydev.mcpm.client.models.PluginTrackerModel;
10+
import org.hydev.mcpm.client.database.model.PluginVersionId;
11+
import org.hydev.mcpm.client.database.model.PluginModelId;
12+
import org.hydev.mcpm.client.models.PluginModel;
13+
14+
import java.util.List;
15+
import java.util.ArrayList;
16+
import java.util.Collection;
17+
import java.util.OptionalLong;
18+
19+
/**
20+
* Implementation to the ListAll functionality
21+
*
22+
* @author Kevin (https://github.com/kchprog)
23+
* @since 2022-11-20
24+
*/
25+
public class ListAllInteractor implements ListAllBoundary {
26+
SuperLocalPluginTracker localPluginTracker = new SuperLocalPluginTracker();
27+
28+
/**
29+
* listAllInteractor interacts with the LocalPluginTracker to get the list of
30+
* plugins, according to a specified
31+
* parameter
32+
*
33+
* @param parameter The parameter for the ListAll use case. 'All' denotes a
34+
* request to list all manually
35+
* installed plugins, 'manual' denotes a request to list all
36+
* manually installed plugins, and 'outdated' denotes
37+
* a request to list all manually installed plugins that are
38+
* outdated.
39+
*/
40+
public List<PluginYml> listAll(String parameter, CheckForUpdatesBoundary checkForUpdatesBoundary) {
41+
var installed = localPluginTracker.listInstalled();
42+
switch (parameter) {
43+
case "all":
44+
return installed;
45+
46+
case "manual":
47+
var local = localPluginTracker.listManuallyInstalled();
48+
return installed.stream().filter(it -> local.contains(it.name())).toList();
49+
50+
case "outdated":
51+
/*
52+
* ArrayList<PluginVersionState> temp = new ArrayList<>();
53+
* ArrayList<PluginTrackerModel> installedModels =
54+
* localPluginTracker.listInstalledAsModels();
55+
*
56+
* for (PluginTrackerModel installedModel : installedModels) {
57+
* PluginVersionId pluginVersionId = new PluginVersionId(
58+
* OptionalLong.of(Long.parseLong(installedModel.getVersionId())), null);
59+
*
60+
* PluginModelId pluginModelId = new PluginModelId(
61+
* OptionalLong.of(Long.parseLong(installedModel.getPluginId())),
62+
* installedModel.getName(),
63+
* null);
64+
*
65+
* temp.add(new PluginVersionState(pluginModelId, pluginVersionId));
66+
* }
67+
*
68+
* CheckForUpdatesInput input = new CheckForUpdatesInput(temp, false);
69+
*
70+
* // Read the list of installedModels and create a CheckForUpdatesInput object
71+
* // with state equal
72+
* // to the list of PluginTrackerModels's version
73+
*
74+
* CheckForUpdatesResult rawResult = checkForUpdatesBoundary.updates(input);
75+
*
76+
* if (rawResult.state() == CheckForUpdatesResult.State.SUCCESS) {
77+
* Collection<PluginModel> result = rawResult.updatable().values();
78+
*
79+
* // get the ids of the plugins that are outdated from result
80+
* ArrayList<String> outdated = new ArrayList<>();
81+
* for (PluginModel pluginModel : result) {
82+
* outdated.add(pluginModel.id() + "");
83+
* }
84+
*
85+
* // filter the installed plugins by the outdated ids
86+
*
87+
* }
88+
* // Need to associate the IDs of the outdated plugins with the installed
89+
* plugin YML files, and return all matches
90+
*/
91+
throw new NotImplementedException("Not implemented yet");
92+
93+
default:
94+
return null;
95+
}
96+
}
97+
}

0 commit comments

Comments
 (0)