Skip to content

Commit

Permalink
First draft of import framework (#958)
Browse files Browse the repository at this point in the history
Signed-off-by: Erle Czar Mantos <[email protected]>
  • Loading branch information
erlemantos authored and aedelmann committed Jun 13, 2018
1 parent 37b0693 commit 6236635
Show file tree
Hide file tree
Showing 23 changed files with 728 additions and 49 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
*/
public class ModelInfo extends AbstractModel {

protected String extendedType;
protected String author;
protected Date creationDate;
protected boolean hasImage = false;
Expand All @@ -38,6 +39,17 @@ public ModelInfo(ModelId modelId,ModelType modelType) {
super(modelId,modelType);
}

public ModelInfo(ModelId modelId, String type) {
setId(modelId);
if (ModelType.containsType(type)) {
setType(ModelType.valueOf(type));
this.extendedType = null;
} else {
setType(ModelType.Extended);
this.extendedType = type;
}
}

public ModelInfo() {
}

Expand Down Expand Up @@ -88,10 +100,18 @@ public String getState() {
public void setState(String state) {
this.state = state;
}

public String getExtendedType() {
return extendedType;
}

public void setExtendedType(String extendedType) {
this.extendedType = extendedType;
}

@Override
public String toString() {
return "ModelResource [id=" + id + ", modelType=" + type + "]";
return "ModelInfo [ id =" + id + ", type=" + type + "extendedType=" + extendedType + "]";
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ public enum ModelType {
Functionblock(".fbmodel"),
InformationModel(".infomodel"),
Datatype(".type"),
Mapping(".mapping");
Mapping(".mapping"),
Extended("");

private String extension;

Expand All @@ -44,7 +45,16 @@ public static ModelType fromFileName(String fileName) {
} else if (type.equals(ModelType.Mapping.getExtension())) {
return ModelType.Mapping;
} else {
throw new IllegalArgumentException(fileName);
return ModelType.Extended;
}
}

public static boolean containsType(String type) {
for (ModelType mType : ModelType.values()) {
if (mType.name().equals(type)) {
return true;
}
}
return false;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
/**
* Copyright (c) 2015-2016 Bosch Software Innovations GmbH and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* and Eclipse Distribution License v1.0 which accompany this distribution.
*
* The Eclipse Public License is available at
* http://www.eclipse.org/legal/epl-v10.html
* The Eclipse Distribution License is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
*
* Contributors:
* Bosch Software Innovations GmbH - Please refer to git log
*/
package org.eclipse.vorto.repository.api.upload;

public class StagingResult {
private String importer;
private boolean valid;
private String errorMessage;
private String stagingId;
private Object stagingDetails;

public static StagingResult success(String importer, String stagingId, Object stagingDetails) {
StagingResult result = new StagingResult();

result.setImporter(importer);
result.setStagingId(stagingId);
result.setValid(true);
result.setStagingDetails(stagingDetails);

return result;
}

public static StagingResult fail(String importer, String errorMessage, Object stagingDetails) {
StagingResult result = new StagingResult();

result.setImporter(importer);
result.setValid(false);
result.setErrorMessage(errorMessage);
result.setStagingDetails(stagingDetails);

return result;
}

private StagingResult() {

}

public String getImporter() {
return importer;
}

public void setImporter(String importer) {
this.importer = importer;
}

public boolean isValid() {
return valid;
}

public void setValid(boolean valid) {
this.valid = valid;
}

public String getErrorMessage() {
return errorMessage;
}

public void setErrorMessage(String errorMessage) {
this.errorMessage = errorMessage;
}

public String getStagingId() {
return stagingId;
}

public void setStagingId(String stagingId) {
this.stagingId = stagingId;
}

public Object getStagingDetails() {
return stagingDetails;
}

public void setStagingDetails(Object stagingDetails) {
this.stagingDetails = stagingDetails;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public class UploadModelResponse {
private String message = null;
private Boolean isSuccess = null;
private List<UploadModelResult> obj = new ArrayList<UploadModelResult>();
private List<StagingResult> result = new ArrayList<StagingResult>();

/*
* Dummy constructor needed by ResponseEntity for JSON parsing of http response
Expand All @@ -38,6 +39,14 @@ public UploadModelResponse(String message, Boolean isSuccess, List<UploadModelRe
this.isSuccess = isSuccess;
this.obj = obj;
}

public static UploadModelResponse newInstance(String message, Boolean isSuccess, List<StagingResult> result) {
UploadModelResponse response = new UploadModelResponse();
response.message = message;
response.isSuccess = isSuccess;
response.result = result;
return response;
}

/**
* Status message returned from server about request.
Expand Down Expand Up @@ -74,6 +83,14 @@ public List<UploadModelResult> getObj() {
public void setObj(List<UploadModelResult> obj) {
this.obj = obj;
}

public List<StagingResult> getResult() {
return result;
}

public void setResult(List<StagingResult> result) {
this.result = result;
}

@Override
public String toString() {
Expand Down
2 changes: 1 addition & 1 deletion repository-java-client/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<version>${project.version}</version>
</dependency>

<dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpmime</artifactId>
<version>4.5.5</version>
Expand Down
7 changes: 7 additions & 0 deletions repository/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,13 @@
<artifactId>javax.interceptor-api</artifactId>
<version>1.2</version>
</dependency>

<dependency>
<groupId>org.subethamail</groupId>
<artifactId>subethasmtp</artifactId>
<version>3.1.7</version>
<scope>test</scope>
</dependency>

<!-- Swagger -->
<dependency>
Expand Down
2 changes: 1 addition & 1 deletion repository/repository-generators/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<version>0.10.0-SNAPSHOT</version>
</parent>

<artifactId>repository-generator-gateway</artifactId>
<artifactId>repository-generators</artifactId>
<packaging>jar</packaging>

<name>Repository Generator Gateway</name>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,16 @@ public interface IModelRepository {
* @return model that was been checked in
*/
ModelInfo checkin(String handleId, IUserContext userContext);

/**
* Saves the model to the repo
*
* @param modelId the id of the model
* @param content the content
* @param fileName the filename of the model
* @param userContext the user
*/
void save(ModelId modelId, byte[] content, String fileName, IUserContext userContext);

/**
* Removes a model image for the given model id
Expand Down Expand Up @@ -108,6 +118,15 @@ public interface IModelRepository {
* @return
*/
ModelInfo updateMeta(ModelInfo model);

/**
* Updates the state of the model
*
* @param modelId the model Id
* @param state the state of the model
* @return
*/
ModelId updateState(ModelId modelId, String state);


public enum ContentType {
Expand Down
Loading

0 comments on commit 6236635

Please sign in to comment.