Skip to content

Commit f637565

Browse files
committed
Merge collective geometries into cohort and store in transition (still unhandled at commit)
1 parent 748d7e5 commit f637565

5 files changed

Lines changed: 897 additions & 138 deletions

File tree

klab.core.api/src/main/java/org/integratedmodelling/klab/api/data/RepositoryState.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,16 @@ public enum Operation {
7070
FETCH_COMMIT_AND_PUSH,
7171
/** Fetch remote changes and merge them if no conflicts arise */
7272
FETCH_AND_MERGE,
73+
/** Commit current local changes without contacting the remote repository */
74+
SAVE_CHANGES,
75+
/** Push committed local changes to the remote repository */
76+
PUBLISH_CHANGES,
7377
/** Switch to another branch (possibly new) after locally committing any pending changes */
7478
COMMIT_AND_SWITCH,
7579
/** Hard reset head deleting all uncommitted changes */
7680
HARD_RESET,
81+
/** Friendlier alias for HARD_RESET */
82+
DISCARD_LOCAL_CHANGES,
7783

7884
MERGE_CHANGES_FROM;
7985

@@ -82,8 +88,11 @@ public String description() {
8288
case FETCH_COMMIT_AND_PUSH ->
8389
"Fetch remote changes, merge if no conflicts, commit and push";
8490
case FETCH_AND_MERGE -> "Fetch remote changes, merge if no conflicts";
91+
case SAVE_CHANGES -> "Save current local changes";
92+
case PUBLISH_CHANGES -> "Publish committed changes";
8593
case COMMIT_AND_SWITCH -> "Commit changes and switch to another branch";
8694
case HARD_RESET -> "Hard reset, deleting all uncommitted changes";
95+
case DISCARD_LOCAL_CHANGES -> "Discard local uncommitted changes";
8796
case MERGE_CHANGES_FROM -> "Merge changes from another branch";
8897
};
8998
}

klab.core.api/src/main/java/org/integratedmodelling/klab/api/knowledge/organization/ProjectStorage.java

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public static ResourceType forExtension(String extension) {
4747
case "kwv" -> ONTOLOGY;
4848
case "kim" -> MODEL_NAMESPACE;
4949
case "obs" -> STRATEGY;
50-
case "kactor" -> BEHAVIOR;
50+
case "kactor", "kactors" -> BEHAVIOR;
5151
default -> null;
5252
};
5353
}
@@ -57,7 +57,7 @@ public String getFileExtension() {
5757
case ONTOLOGY -> "kwv";
5858
case MODEL_NAMESPACE -> "kim";
5959
case STRATEGY -> "obs";
60-
case BEHAVIOR, TESTCASE, SCRIPT -> "kactor";
60+
case BEHAVIOR, TESTCASE, SCRIPT, APPLICATION -> "kactors";
6161
default ->
6262
throw new KlabUnimplementedException("file extension for document of class " + this);
6363
};
@@ -142,23 +142,32 @@ static Pair<ResourceType, String> getDocumentData(String relativeFilePath, Strin
142142
ResourceType type = null;
143143
String urn = null;
144144

145+
if (relativeFilePath == null || !relativeFilePath.contains(".")) {
146+
return null;
147+
}
148+
145149
var extension = relativeFilePath.substring(relativeFilePath.lastIndexOf(".") + 1);
146150
var path = relativeFilePath.substring(0, relativeFilePath.lastIndexOf("."));
151+
boolean behaviorExtension = "kactor".equals(extension) || "kactors".equals(extension);
147152

148153
if ("json".equals(extension)) {
149154
// TODO manifest, docs, resource.
150155
if (relativeFilePath.startsWith("resources" + separator)) {
151-
throw new KlabUnimplementedException("KAAAAAAAAKKKKKKKKKKKKKKKKKKK");
156+
return null;
152157
}
153158
} else {
154159
if (relativeFilePath.startsWith("src" + separator)) {
155160
type = ResourceType.forExtension(extension);
156161
urn = path.substring("src".length() + 1).replace(separator, ".");
157-
} else if (relativeFilePath.startsWith("scripts" + separator)) {
158-
throw new KlabUnimplementedException("POOOOOO");
159-
} else if (relativeFilePath.startsWith("tests" + separator)) {
160-
throw new KlabUnimplementedException("PAAAAAAA");
161-
} else if (relativeFilePath.startsWith("apps" + separator) && "apps".equals(extension)) {
162+
} else if (relativeFilePath.startsWith("scripts" + separator) && behaviorExtension) {
163+
type = ResourceType.SCRIPT;
164+
urn = path.substring("scripts".length() + 1);
165+
} else if ((relativeFilePath.startsWith("tests" + separator)
166+
|| relativeFilePath.startsWith("testcases" + separator))
167+
&& behaviorExtension) {
168+
type = ResourceType.TESTCASE;
169+
urn = path.substring(relativeFilePath.indexOf(separator) + separator.length());
170+
} else if (relativeFilePath.startsWith("apps" + separator) && behaviorExtension) {
162171
type = ResourceType.APPLICATION;
163172
urn = path.substring("apps".length() + 1);
164173
} else if (relativeFilePath.startsWith("strategies" + separator) && "obs".equals(extension)) {
@@ -191,7 +200,7 @@ static String getRelativeFilePath(String urn, ResourceType type) {
191200
static String getRelativeFilePath(String urn, ResourceType type, String separator) {
192201
return switch (type) {
193202
case SCRIPT -> "scripts" + separator + urn + "." + type.getFileExtension();
194-
case TESTCASE -> "tests" + separator + urn + "." + type.getFileExtension();
203+
case TESTCASE -> "testcases" + separator + urn + "." + type.getFileExtension();
195204
case APPLICATION -> "apps" + separator + urn + "." + type.getFileExtension();
196205
case ONTOLOGY, MODEL_NAMESPACE, BEHAVIOR ->
197206
"src" + separator + urn.replace('.', separator.charAt(0)) + "." + type.getFileExtension();

klab.core.services/src/main/java/org/integratedmodelling/klab/resources/FileProjectStorage.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -233,17 +233,17 @@ public RepositoryState getRepositoryState() {
233233

234234
public String getDocumentUrn(ResourceType type, URL url) {
235235

236-
File file = new File(url.getFile());
237-
if (file.exists()) {
236+
try {
237+
File file = Path.of(url.toURI()).toFile();
238238
/*
239239
relative path
240240
*/
241241
var relativePath = rootFolder.toPath().relativize(file.toPath());
242242
var data = ProjectStorage.getDocumentData(relativePath.toString(), File.separator);
243243
return data != null && data.getFirst() == type ? data.getSecond() : null;
244+
} catch (Exception e) {
245+
throw new KlabIOException(e);
244246
}
245-
246-
return null;
247247
}
248248

249249
/**
@@ -261,7 +261,7 @@ public URL getDocumentUrl(String path, String separator) {
261261
+ (path.startsWith(separator) ? path.substring(separator.length()) : path)
262262
.replace(separator, File.separator));
263263
try {
264-
return file.exists() ? file.toURI().toURL() : null;
264+
return file.toURI().toURL();
265265
} catch (MalformedURLException e) {
266266
}
267267
return null;

0 commit comments

Comments
 (0)