Skip to content

Commit

Permalink
FileSubmodelElement Endpoints (#93)
Browse files Browse the repository at this point in the history
* first parts to implement file upload feature

* Add partial implementation of getFile for in-memory backend

Signed-off-by: Zai Müller-Zhang <[email protected]>

* Implements File support for Submodelrepository MongoDB

Signed-off-by: Mohammad Ghazanfar Ali Danish <[email protected]>

* Add In-Memory backend und unit Test.
Add Rest API for file upload
Created unit test for file upload

Signed-off-by: Zai Müller-Zhang <[email protected]>

* Add new Exception for mqtt
Add json file for test

Signed-off-by: Zai Müller-Zhang <[email protected]>

* Fixes the File upload issue with HTTP

Signed-off-by: Mohammad Ghazanfar Ali Danish <[email protected]>

* Add new Exception for mqtt
Add json file for test

Signed-off-by: Zai Müller-Zhang <[email protected]>

* Add http unit test for get- set- delete files

Signed-off-by: Zai Müller-Zhang <[email protected]>
Co-authored-by: Danish, Mohammad Ghazanfar Ali<[email protected]>

* In SubmodelRepositoryApiHTTPController, Change Http status code to "precondition failed" if the submodel element is not a file sme.
In InMemorySubmodelRepository, delete unused exception.
Refactor Http Test

* move unit tests for file upload and download to SubmodelRepositorySubmodelHTTPTestSuite

Signed-off-by: Zai Müller-Zhang <[email protected]>

* Change expected value of the assertion for the setFileValue unit test.

Signed-off-by: Zai Müller-Zhang <[email protected]>

* Adjust assertion in unit test getDefaultSubmodelRepositoryName()

Signed-off-by: Zai Müller-Zhang <[email protected]>

* Add new cosntructor in MongoDBSubmodelRepositoryFactory which uses the default repository name

Signed-off-by: Zai Müller-Zhang <[email protected]>

* Put the private mathod after the unit tests.

Signed-off-by: Zai Müller-Zhang <[email protected]>

* Delete unnecessary exception throw

Signed-off-by: Zai Müller-Zhang <[email protected]>

* add @autowire=false to the constructor

Signed-off-by: Zai Müller-Zhang <[email protected]>

* Handles correct closing of input streams

- Minor refactoring

Signed-off-by: Mohammad Ghazanfar Ali Danish <[email protected]>

* Refactors code

Signed-off-by: Mohammad Ghazanfar Ali Danish <[email protected]>

---------

Signed-off-by: Zai Müller-Zhang <[email protected]>
Signed-off-by: Mohammad Ghazanfar Ali Danish <[email protected]>
Co-authored-by: Zai Müller-Zhang <[email protected]>
Co-authored-by: Mohammad Ghazanfar Ali Danish <[email protected]>
  • Loading branch information
3 people authored Oct 10, 2023
1 parent 0187f43 commit 07fa3d7
Show file tree
Hide file tree
Showing 32 changed files with 1,335 additions and 235 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*******************************************************************************
* Copyright (C) 2023 the Eclipse BaSyx Authors
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* SPDX-License-Identifier: MIT
******************************************************************************/

package org.eclipse.digitaltwin.basyx.core.exceptions;

/**
* Indicates that the requested submodel element is not a File SubmodelElement
*
* @author danish
*
*/
@SuppressWarnings("serial")
public class ElementNotAFileException extends RuntimeException {
public ElementNotAFileException() {
}

public ElementNotAFileException(String elementId) {
super(getMsg(elementId));
}

private static String getMsg(String elementId) {
return "SubmodelElement with Id " + elementId + " is not a File";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*******************************************************************************
* Copyright (C) 2023 the Eclipse BaSyx Authors
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* SPDX-License-Identifier: MIT
******************************************************************************/

package org.eclipse.digitaltwin.basyx.core.exceptions;

/**
* This exception is used for features where certain functionalities are not implemented yet.
*
* @author zhangzai
*
*/
@SuppressWarnings("serial")
public class FeatureNotImplementedException extends RuntimeException {

public FeatureNotImplementedException() {
super();
}

public FeatureNotImplementedException(String featureName) {
super(getMessage(featureName));
}

private static String getMessage(String featureName) {
return "Feature " + featureName + " is not implemented yet";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*******************************************************************************
* Copyright (C) 2023 the Eclipse BaSyx Authors
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* SPDX-License-Identifier: MIT
******************************************************************************/

package org.eclipse.digitaltwin.basyx.core.exceptions;

/**
* Indicates that the requested file does not exist
*
* @author danish
*
*/
@SuppressWarnings("serial")
public class FileDoesNotExistException extends RuntimeException {
public FileDoesNotExistException() {
}

public FileDoesNotExistException(String elementId) {
super(getMsg(elementId));
}

private static String getMsg(String elementId) {
return "Requested File inside File SubmodelElement with ID : " + elementId + " does not exist";
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*******************************************************************************
* Copyright (C) 2023 the Eclipse BaSyx Authors
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* SPDX-License-Identifier: MIT
******************************************************************************/

package org.eclipse.digitaltwin.basyx.core.exceptions;

/**
* Indicates that the provided file could not be handled
*
* @author zhangzai
*
*/
@SuppressWarnings("serial")
public class FileHandlingException extends RuntimeException {

public FileHandlingException() {
super();
}

public FileHandlingException(String fileName) {
super(getMessage(fileName));
}

private static String getMessage(String fileName) {
return "Exception occurred while handling the file: " + fileName;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,13 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.apache.tika</groupId>
<artifactId>tika-core</artifactId>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
</dependency>
</dependencies>
</project>
Loading

0 comments on commit 07fa3d7

Please sign in to comment.