diff --git a/.gitignore b/.gitignore index 73feca5..fc975f4 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,5 @@ target/ .project .settings/ bin/ + +.checkstyle diff --git a/2016-03-02 Capabilities Selection Extension 1.1c.pdf b/2016-03-02 Capabilities Selection Extension 1.1c.pdf new file mode 100644 index 0000000..56f347b Binary files /dev/null and b/2016-03-02 Capabilities Selection Extension 1.1c.pdf differ diff --git a/src/main/java/edu/kit/scc/CdmiRestController.java b/src/main/java/edu/kit/scc/CdmiRestController.java index c27471d..43ea254 100644 --- a/src/main/java/edu/kit/scc/CdmiRestController.java +++ b/src/main/java/edu/kit/scc/CdmiRestController.java @@ -100,10 +100,10 @@ public class CdmiRestController { @Value("${oidc.clientsecret}") private String clientSecret; - @PostConstruct /** * Init method to check and initialize the server. */ + @PostConstruct public void init() { log.debug("INIT"); Container rootContainer = containerDaoImpl.findByPath("/"); @@ -414,9 +414,7 @@ public ResponseEntity putCdmiObject(@RequestHeader("Authorization") String au return new ResponseEntity(container.toJson().toString(), responseHeaders, HttpStatus.CREATED); } - } - // create dataobject - else if (contentType.equals(MediaTypes.DATA_OBJECT)) { + } else if (contentType.equals(MediaTypes.DATA_OBJECT)) { JSONObject json = new JSONObject(body); DataObject dataObject = dataObjectDaoImpl.createByPath(requestPath, new DataObject(json)); if (dataObject != null) { @@ -424,9 +422,7 @@ else if (contentType.equals(MediaTypes.DATA_OBJECT)) { return new ResponseEntity(dataObject.toJson().toString(), responseHeaders, HttpStatus.CREATED); } - } - // create domain - else if (contentType.equals(MediaTypes.ACCOUNT)) { + } else if (contentType.equals(MediaTypes.ACCOUNT)) { JSONObject json = new JSONObject(body); CdmiObject domain = null; if (requestedFields == null) { @@ -547,11 +543,9 @@ private JSONObject getRequestedJson(JSONObject object, String[] requestedFields) } else if (field.startsWith("value:")) { String range = field.split("value:")[1]; String[] rangeSplit = range.split("-"); - requestedJson - .put("value", - new String(Arrays.copyOfRange(object.getString("value").getBytes(), - Integer.valueOf(rangeSplit[0].trim()), - Integer.valueOf(rangeSplit[1].trim())))); + requestedJson.put("value", + new String(Arrays.copyOfRange(object.getString("value").getBytes(), + Integer.valueOf(rangeSplit[0].trim()), Integer.valueOf(rangeSplit[1].trim())))); } else { throw new BadRequestException("Bad prefix"); } @@ -606,7 +600,7 @@ public boolean verifyAuthorization(String authorizationHeader) { } } catch (Exception ex) { log.error("ERROR {}", ex.toString()); - //ex.printStackTrace(); + // ex.printStackTrace(); } return false; } diff --git a/src/main/java/edu/kit/scc/Utils.java b/src/main/java/edu/kit/scc/Utils.java index dfb2dc3..c46533a 100644 --- a/src/main/java/edu/kit/scc/Utils.java +++ b/src/main/java/edu/kit/scc/Utils.java @@ -12,17 +12,10 @@ public final class Utils { /************************************************************************* - * Compilation: javac CRC16.java Execution: java CRC16 s - * - * Reads in a string s as a command-line argument, and prints out its 16-bit Cyclic Redundancy - * Check (CRC16). Uses a lookup table. - * - * Reference: http://www.gelato.unsw.edu.au/lxr/source/lib/crc16.c - * - * % java CRC16 123456789 CRC16 = bb3d - * - * Uses irreducible polynomial: 1 + x^2 + x^15 + x^16 - * + * Compilation: javac CRC16.java Execution: java CRC16 s Reads in a string s as a command-line + * argument, and prints out its 16-bit Cyclic Redundancy Check (CRC16). Uses a lookup table. + * Reference: http://www.gelato.unsw.edu.au/lxr/source/lib/crc16.c % java CRC16 123456789 CRC16 = + * bb3d Uses irreducible polynomial: 1 + x^2 + x^15 + x^16 *************************************************************************/ /* * Copyright © 2000–2011, Robert Sedgewick and Kevin Wayne. diff --git a/src/main/java/edu/kit/scc/http/CustomSslContext.java b/src/main/java/edu/kit/scc/http/CustomSslContext.java index 3a83191..067d931 100644 --- a/src/main/java/edu/kit/scc/http/CustomSslContext.java +++ b/src/main/java/edu/kit/scc/http/CustomSslContext.java @@ -113,7 +113,7 @@ public void checkServerTrusted(X509Certificate[] chain, String authType) @Override public void checkClientTrusted(X509Certificate[] chain, String authType) throws CertificateException {} - }}, null); + } }, null); } catch (NoSuchAlgorithmException e) { // TODO Auto-generated catch block e.printStackTrace(); diff --git a/src/main/java/org/snia/cdmiserver/dao/AccountDao.java b/src/main/java/org/snia/cdmiserver/dao/AccountDao.java index b6bc552..83e7165 100644 --- a/src/main/java/org/snia/cdmiserver/dao/AccountDao.java +++ b/src/main/java/org/snia/cdmiserver/dao/AccountDao.java @@ -1,33 +1,31 @@ /* - * Copyright (c) 2010, Sun Microsystems, Inc. - * Copyright (c) 2010, The Storage Networking Industry Association. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * - * Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * Neither the name of The Storage Networking Industry Association (SNIA) nor - * the names of its contributors may be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF - * THE POSSIBILITY OF SUCH DAMAGE. + * Copyright (c) 2010, Sun Microsystems, Inc. Copyright (c) 2010, The Storage Networking Industry + * Association. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted + * provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this list of conditions + * and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, this list of conditions + * and the following disclaimer in the documentation and/or other materials provided with the + * distribution. + * + * Neither the name of The Storage Networking Industry Association (SNIA) nor the names of its + * contributors may be used to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY + * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ + package org.snia.cdmiserver.dao; import org.snia.cdmiserver.model.Account; @@ -39,11 +37,11 @@ */ public interface AccountDao { - /** - *

- * Find and return an {@link Account} by object id, if any; otherwise, return null. - *

- */ - public Account findByObjectId(String objectId); + /** + *

+ * Find and return an {@link Account} by object id, if any; otherwise, return null. + *

+ */ + public Account findByObjectId(String objectId); } diff --git a/src/main/java/org/snia/cdmiserver/dao/CapabilityDao.java b/src/main/java/org/snia/cdmiserver/dao/CapabilityDao.java index 09ad7c0..7d98f49 100644 --- a/src/main/java/org/snia/cdmiserver/dao/CapabilityDao.java +++ b/src/main/java/org/snia/cdmiserver/dao/CapabilityDao.java @@ -1,33 +1,31 @@ /* - * Copyright (c) 2010, Sun Microsystems, Inc. - * Copyright (c) 2010, The Storage Networking Industry Association. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * - * Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * Neither the name of The Storage Networking Industry Association (SNIA) nor - * the names of its contributors may be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF - * THE POSSIBILITY OF SUCH DAMAGE. + * Copyright (c) 2010, Sun Microsystems, Inc. Copyright (c) 2010, The Storage Networking Industry + * Association. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted + * provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this list of conditions + * and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, this list of conditions + * and the following disclaimer in the documentation and/or other materials provided with the + * distribution. + * + * Neither the name of The Storage Networking Industry Association (SNIA) nor the names of its + * contributors may be used to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY + * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ + package org.snia.cdmiserver.dao; import org.snia.cdmiserver.model.Capability; @@ -39,21 +37,19 @@ */ public interface CapabilityDao { - /** - *

- * Find and return a {@link Capability} by object id, if any; otherwise, return - * null. - *

- */ - public Capability findByObjectId(String objectId); + /** + *

+ * Find and return a {@link Capability} by object id, if any; otherwise, return null. + *

+ */ + public Capability findByObjectId(String objectId); - /** - *

- * Find and return a {@link Capability} by path, if any; otherwise, return null. - *

- * - * @param path - * Path to the requested {@link Capability} - */ - public Capability findByPath(String path); + /** + *

+ * Find and return a {@link Capability} by path, if any; otherwise, return null. + *

+ * + * @param path Path to the requested {@link Capability} + */ + public Capability findByPath(String path); } diff --git a/src/main/java/org/snia/cdmiserver/dao/CdmiObjectDao.java b/src/main/java/org/snia/cdmiserver/dao/CdmiObjectDao.java index 0ebbe1a..ff4a57d 100644 --- a/src/main/java/org/snia/cdmiserver/dao/CdmiObjectDao.java +++ b/src/main/java/org/snia/cdmiserver/dao/CdmiObjectDao.java @@ -1,15 +1,24 @@ +/* + * Copyright 2016 Karlsruhe Institute of Technology (KIT) + * + * 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 + */ + package org.snia.cdmiserver.dao; import org.snia.cdmiserver.model.CdmiObject; public interface CdmiObjectDao { - public CdmiObject createCdmiObject(CdmiObject cdmiObject); + public CdmiObject createCdmiObject(CdmiObject cdmiObject); - public CdmiObject getCdmiObject(String objectId); + public CdmiObject getCdmiObject(String objectId); - public CdmiObject updateCdmiObject(CdmiObject cdmiObject); + public CdmiObject updateCdmiObject(CdmiObject cdmiObject); - public CdmiObject deleteCdmiObject(String objectId); + public CdmiObject deleteCdmiObject(String objectId); } diff --git a/src/main/java/org/snia/cdmiserver/dao/ContainerDao.java b/src/main/java/org/snia/cdmiserver/dao/ContainerDao.java index 443aa66..63f38c3 100644 --- a/src/main/java/org/snia/cdmiserver/dao/ContainerDao.java +++ b/src/main/java/org/snia/cdmiserver/dao/ContainerDao.java @@ -1,33 +1,31 @@ /* - * Copyright (c) 2010, Sun Microsystems, Inc. - * Copyright (c) 2010, The Storage Networking Industry Association. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * - * Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * Neither the name of The Storage Networking Industry Association (SNIA) nor - * the names of its contributors may be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF - * THE POSSIBILITY OF SUCH DAMAGE. + * Copyright (c) 2010, Sun Microsystems, Inc. Copyright (c) 2010, The Storage Networking Industry + * Association. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted + * provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this list of conditions + * and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, this list of conditions + * and the following disclaimer in the documentation and/or other materials provided with the + * distribution. + * + * Neither the name of The Storage Networking Industry Association (SNIA) nor the names of its + * contributors may be used to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY + * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ + package org.snia.cdmiserver.dao; import org.snia.cdmiserver.exception.ConflictException; @@ -42,68 +40,54 @@ */ public interface ContainerDao { - /** - *

- * Create a container at the specified path. All intermediate containers - * must already exist. - *

- * - * @param path - * Path to the new {@link Container} - * - * @exception ConflictException - * if a container or data object at the specified path - * already exists - * @exception IllegalArgumentException - * if an intermediate container does not exist - */ - public CdmiObject createByPath(String path, Container containerRequest); + /** + *

+ * Create a container at the specified path. All intermediate containers must already exist. + *

+ * + * @param path Path to the new {@link Container} + * + * @exception ConflictException if a container or data object at the specified path already exists + * @exception IllegalArgumentException if an intermediate container does not exist + */ + public CdmiObject createByPath(String path, Container containerRequest); - /** - *

- * Delete the container at the specified path. - *

- * - * @param path - * Path to the requested {@link Container} - * - * @exception NotFoundException - * if the specified path does not identify a valid resource - * @exception IllegalArgumentException - * if the specified path identifies a data object instead of - * a container - */ - public void deleteByPath(String path); + /** + *

+ * Delete the container at the specified path. + *

+ * + * @param path Path to the requested {@link Container} + * + * @exception NotFoundException if the specified path does not identify a valid resource + * @exception IllegalArgumentException if the specified path identifies a data object instead of a + * container + */ + public void deleteByPath(String path); - /** - *

- * Find and return a {@link Container} by object id, if any; otherwise, - * return null . - *

- * - * @param objectId - * Object ID of the requested {@link Container} - */ - public CdmiObject findByObjectId(String objectId); + /** + *

+ * Find and return a {@link Container} by object id, if any; otherwise, return null . + *

+ * + * @param objectId Object ID of the requested {@link Container} + */ + public CdmiObject findByObjectId(String objectId); - /** - *

- * Find and return a {@link Container} by path, if any; otherwise, return - * null. - *

- * - * @param path - * Path to the requested {@link Container} - * - * @exception NotFoundException - * if the specified path does not identify a valid resource - * @exception IllegalArgumentException - * if the specified path identifies a data object instead of - * a container - */ - public CdmiObject findByPath(String path); + /** + *

+ * Find and return a {@link Container} by path, if any; otherwise, return null. + *

+ * + * @param path Path to the requested {@link Container} + * + * @exception NotFoundException if the specified path does not identify a valid resource + * @exception IllegalArgumentException if the specified path identifies a data object instead of a + * container + */ + public CdmiObject findByPath(String path); - // - public boolean isContainer(String path); - // + // + public boolean isContainer(String path); + // } diff --git a/src/main/java/org/snia/cdmiserver/dao/DataObjectDao.java b/src/main/java/org/snia/cdmiserver/dao/DataObjectDao.java index cef0bf1..c45817b 100644 --- a/src/main/java/org/snia/cdmiserver/dao/DataObjectDao.java +++ b/src/main/java/org/snia/cdmiserver/dao/DataObjectDao.java @@ -1,33 +1,31 @@ /* - * Copyright (c) 2010, Sun Microsystems, Inc. - * Copyright (c) 2010, The Storage Networking Industry Association. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * - * Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * Neither the name of The Storage Networking Industry Association (SNIA) nor - * the names of its contributors may be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF - * THE POSSIBILITY OF SUCH DAMAGE. + * Copyright (c) 2010, Sun Microsystems, Inc. Copyright (c) 2010, The Storage Networking Industry + * Association. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted + * provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this list of conditions + * and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, this list of conditions + * and the following disclaimer in the documentation and/or other materials provided with the + * distribution. + * + * Neither the name of The Storage Networking Industry Association (SNIA) nor the names of its + * contributors may be used to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY + * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ + package org.snia.cdmiserver.dao; import org.snia.cdmiserver.model.DataObject; @@ -39,59 +37,51 @@ */ public interface DataObjectDao { - /** - *

- * Create a data object at the specified path. All intermediate containers must already exist. - *

- * - * @param path - * Path to the new {@link DataObject} - * - * @exception ConflictException - * if a container or data object at the specified path already exists - * @exception IllegalArgumentException - * if an intermediate container does not exist - */ - public DataObject createByPath(String path, DataObject dObj) throws Exception; + /** + *

+ * Create a data object at the specified path. All intermediate containers must already exist. + *

+ * + * @param path Path to the new {@link DataObject} + * + * @exception IllegalArgumentException if an intermediate container does not exist + */ + public DataObject createByPath(String path, DataObject dataObj) throws Exception; - public DataObject createNonCDMIByPath(String path, String contentType, DataObject dObj) throws Exception; + public DataObject createNonCcdmiByPath(String path, String contentType, DataObject dataObj) + throws Exception; - public DataObject createById(String objectId, DataObject dObj); + public DataObject createById(String objectId, DataObject dataObj); - /** - *

- * Delete the data object at the specified path. - *

- * - * @param path - * Path to the requested {@link DataObject} - * - * @exception NotFoundException - * if the specified path does not identify a valid resource - * @exception IllegalArgumentException - * if the specified path identifies a container instead of a data object - */ - public void deleteByPath(String path); + /** + *

+ * Delete the data object at the specified path. + *

+ * + * @param path Path to the requested {@link DataObject} + * + * @exception NotFoundException if the specified path does not identify a valid resource + * @exception IllegalArgumentException if the specified path identifies a container instead of a + * data object + */ + public void deleteByPath(String path); - /** - *

- * Find and return a {@link DataObject} by object id, if any; otherwise, return - * null. - *

- * - * @param objectId - * Object ID of the requested {@link DataObject} - */ - public DataObject findByObjectId(String objectId); + /** + *

+ * Find and return a {@link DataObject} by object id, if any; otherwise, return null. + *

+ * + * @param objectId Object ID of the requested {@link DataObject} + */ + public DataObject findByObjectId(String objectId); - /** - *

- * Find and return a {@link DataObject} by path, if any; otherwise, return null. - *

- * - * @param path - * Path to the requested {@link DataObject} - */ - public DataObject findByPath(String path); + /** + *

+ * Find and return a {@link DataObject} by path, if any; otherwise, return null. + *

+ * + * @param path Path to the requested {@link DataObject} + */ + public DataObject findByPath(String path); } diff --git a/src/main/java/org/snia/cdmiserver/dao/DomainDao.java b/src/main/java/org/snia/cdmiserver/dao/DomainDao.java index c7fa6ee..5805c67 100644 --- a/src/main/java/org/snia/cdmiserver/dao/DomainDao.java +++ b/src/main/java/org/snia/cdmiserver/dao/DomainDao.java @@ -26,7 +26,7 @@ public interface DomainDao { * @exception ConflictException if a Domain or data object at the specified path already exists * @exception IllegalArgumentException if an intermediate Domain does not exist */ - public CdmiObject createByPath(String path, Domain DomainRequest); + public CdmiObject createByPath(String path, Domain domainRequest); /** *

diff --git a/src/main/java/org/snia/cdmiserver/dao/QueueDao.java b/src/main/java/org/snia/cdmiserver/dao/QueueDao.java index 3846c0b..22242c7 100644 --- a/src/main/java/org/snia/cdmiserver/dao/QueueDao.java +++ b/src/main/java/org/snia/cdmiserver/dao/QueueDao.java @@ -1,33 +1,31 @@ /* - * Copyright (c) 2010, Sun Microsystems, Inc. - * Copyright (c) 2010, The Storage Networking Industry Association. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * - * Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * Neither the name of The Storage Networking Industry Association (SNIA) nor - * the names of its contributors may be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF - * THE POSSIBILITY OF SUCH DAMAGE. + * Copyright (c) 2010, Sun Microsystems, Inc. Copyright (c) 2010, The Storage Networking Industry + * Association. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted + * provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this list of conditions + * and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, this list of conditions + * and the following disclaimer in the documentation and/or other materials provided with the + * distribution. + * + * Neither the name of The Storage Networking Industry Association (SNIA) nor the names of its + * contributors may be used to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY + * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ + package org.snia.cdmiserver.dao; import org.snia.cdmiserver.model.Queue; @@ -39,11 +37,11 @@ */ public interface QueueDao { - /** - *

- * Find and return a {@link Queue} by object id, if any; otherwise, return null. - *

- */ - public Queue findByObjectId(String objectId); + /** + *

+ * Find and return a {@link Queue} by object id, if any; otherwise, return null. + *

+ */ + public Queue findByObjectId(String objectId); } diff --git a/src/main/java/org/snia/cdmiserver/dao/filesystem/CapabilityDaoImpl.java b/src/main/java/org/snia/cdmiserver/dao/filesystem/CapabilityDaoImpl.java index d4c0d36..a53226a 100644 --- a/src/main/java/org/snia/cdmiserver/dao/filesystem/CapabilityDaoImpl.java +++ b/src/main/java/org/snia/cdmiserver/dao/filesystem/CapabilityDaoImpl.java @@ -60,7 +60,7 @@ public class CapabilityDaoImpl implements CapabilityDao { // -------------------------------------------------------------- Properties @Value("${cdmi.data.rootObjectId}") - private String ROOTobjectID; + private String rootObjectId; private JSONObject json; private JSONObject system; @@ -87,7 +87,7 @@ private void readProperties() { InputStream in = null; try { in = applicationConfiguration.getInputStream(); - byte bt[] = new byte[(int) applicationConfiguration.contentLength()]; + byte[] bt = new byte[(int) applicationConfiguration.contentLength()]; in.read(bt); properties = new String(bt); @@ -160,8 +160,9 @@ public Capability findByPath(String path) { if (object != null) { try { path = path.split("/cdmi_capabilities/" + request + "/")[1]; - if (path.equals("")) + if (path.equals("")) { throw new IndexOutOfBoundsException(); + } capability.setParentURI("cdmi_capabilities/" + request); rekursivGetCapability(capability, path, object); } catch (IndexOutOfBoundsException e) { @@ -173,14 +174,16 @@ public Capability findByPath(String path) { Iterator keys = object.keys(); while (keys.hasNext()) { String child = (String) keys.next(); - if (object.get(child) instanceof JSONObject) + if (object.get(child) instanceof JSONObject) { capability.getChildren().add(child); - else + } else { capability.getCapabilities().put(child, String.valueOf(object.get(child))); + } } - if (!capability.getChildren().isEmpty()) + if (!capability.getChildren().isEmpty()) { capability .setChildrenrange("0-" + String.valueOf(capability.getChildren().size() - 1)); + } } } } @@ -199,7 +202,7 @@ public Capability findByPath(String path) { capability.setObjectID(getIdByUri("cdmi_capabilities")); capability.setObjectName("cdmi_capabilities"); capability.setParentURI("/"); - capability.setParentID(ROOTobjectID); + capability.setParentID(rootObjectId); } capability.setObjectType(MediaTypes.CAPABILITY); return (capability); @@ -208,8 +211,9 @@ public Capability findByPath(String path) { private Capability rekursivGetCapability(Capability capability, String path, JSONObject object) { Boolean end = false; - if (path.endsWith("/")) + if (path.endsWith("/")) { path = path.substring(0, path.length() - 1); + } String[] pathSplit = path.split("/", 2); String pathPart = pathSplit[0]; try { @@ -224,13 +228,15 @@ private Capability rekursivGetCapability(Capability capability, String path, JSO Iterator keys = newObject.keys(); while (keys.hasNext()) { String cap = (String) keys.next(); - if (newObject.get(cap) instanceof JSONObject) + if (newObject.get(cap) instanceof JSONObject) { capability.getChildren().add(cap); - else + } else { capability.getCapabilities().put(cap, String.valueOf(newObject.get(cap))); + } } - if (!capability.getChildren().isEmpty()) + if (!capability.getChildren().isEmpty()) { capability.setChildrenrange("0-" + String.valueOf(capability.getChildren().size() - 1)); + } String parentUri = capability.getParentURI(); capability.setParentID(getIdByUri(parentUri)); capability.setObjectName(pathPart); @@ -250,12 +256,14 @@ private Capability rekursivGetCapability(Capability capability, String path, JSO private String getIdByUri(String uri) { LOG.trace("InCapabilities.getIdByUri URI is {}", uri); String searchkey = uri.replace("/", "."); - if (searchkey.endsWith(".")) + if (searchkey.endsWith(".")) { searchkey = searchkey + "ObjectId"; - else + } else { searchkey = searchkey + ".ObjectId"; - if (searchkey.startsWith(".")) + } + if (searchkey.startsWith(".")) { searchkey = searchkey.substring(1, searchkey.length()); + } int position = properties.toLowerCase().indexOf(searchkey.toLowerCase()); if (position != -1) { int startindex = position + searchkey.length() + 1; diff --git a/src/main/java/org/snia/cdmiserver/dao/filesystem/CdmiObjectDaoImpl.java b/src/main/java/org/snia/cdmiserver/dao/filesystem/CdmiObjectDaoImpl.java index d83347e..4f8b1bd 100644 --- a/src/main/java/org/snia/cdmiserver/dao/filesystem/CdmiObjectDaoImpl.java +++ b/src/main/java/org/snia/cdmiserver/dao/filesystem/CdmiObjectDaoImpl.java @@ -31,7 +31,7 @@ @Component public class CdmiObjectDaoImpl implements CdmiObjectDao { - private final static Logger log = LoggerFactory.getLogger(CdmiObjectDaoImpl.class); + private static final Logger log = LoggerFactory.getLogger(CdmiObjectDaoImpl.class); @Value("${cdmi.data.rootObjectId}") private String rootObjectId; @@ -45,14 +45,22 @@ public class CdmiObjectDaoImpl implements CdmiObjectDao { @Value("${cdmi.data.baseDirectory}") private String baseDirectoryName; + /** + * Creates a new CDMI object with the given object id at the given path. + * + * @param objectId the object's id + * @param path the file system path + * @return the created {@link CdmiObject} + */ public CdmiObject createCdmiObject(CdmiObject objectId, String path) { try { - Path p = Paths.get(path.trim()); + Path sanitizedPath = Paths.get(path.trim()); Path newPath; try { - newPath = Paths.get(p.getParent().toString(), objectIdPrefix + p.getFileName().toString()); + newPath = Paths.get(sanitizedPath.getParent().toString(), + objectIdPrefix + sanitizedPath.getFileName().toString()); } catch (NullPointerException e) { - newPath = Paths.get(objectIdPrefix + p.getFileName().toString()); + newPath = Paths.get(objectIdPrefix + sanitizedPath.getFileName().toString()); } Files.write(newPath, objectId.toJson().toString().getBytes(), StandardOpenOption.WRITE, StandardOpenOption.CREATE_NEW); @@ -93,14 +101,22 @@ public CdmiObject createCdmiObject(CdmiObject objectId) { return objectId; } + /** + * Updates the given CDMI object. + * + * @param objectId the object's id + * @param path the object's file system path + * @return the updated {@link CdmiObject} + */ public CdmiObject updateCdmiObject(CdmiObject objectId, String path) { try { - Path p = Paths.get(path.trim()); + Path sanitizedPath = Paths.get(path.trim()); Path newPath; try { - newPath = Paths.get(p.getParent().toString(), objectIdPrefix + p.getFileName().toString()); + newPath = Paths.get(sanitizedPath.getParent().toString(), + objectIdPrefix + sanitizedPath.getFileName().toString()); } catch (NullPointerException e) { - newPath = Paths.get(objectIdPrefix + p.getFileName().toString()); + newPath = Paths.get(objectIdPrefix + sanitizedPath.getFileName().toString()); } Files.write(newPath, objectId.toJson().toString().getBytes(), StandardOpenOption.WRITE, StandardOpenOption.TRUNCATE_EXISTING); @@ -136,15 +152,22 @@ public CdmiObject updateCdmiObject(CdmiObject objectId) { return objectId; } + /** + * Deletes a CdmiObject by path. + * + * @param path the file system path to the CDMI object + * @return the deleted {@link CdmiObject} + */ public CdmiObject deleteCdmiObjectByPath(String path) { CdmiObject object = getCdmiObjectByPath(path); if (object != null) { - Path p = Paths.get(path.trim()); + Path sanitizedPath = Paths.get(path.trim()); Path newPath; try { - newPath = Paths.get(p.getParent().toString(), objectIdPrefix + p.getFileName().toString()); + newPath = Paths.get(sanitizedPath.getParent().toString(), + objectIdPrefix + sanitizedPath.getFileName().toString()); } catch (NullPointerException e) { - newPath = Paths.get(objectIdPrefix + p.getFileName().toString()); + newPath = Paths.get(objectIdPrefix + sanitizedPath.getFileName().toString()); } try { boolean deleted = Files.deleteIfExists(newPath); @@ -171,14 +194,21 @@ public CdmiObject deleteCdmiObject(String objectId) { return object; } + /** + * Gets a CDMI object by path. + * + * @param path the object's file system path + * @return the {@link CdmiObject} + */ public CdmiObject getCdmiObjectByPath(String path) { CdmiObject object = null; - Path p = Paths.get(path.trim().replaceAll("/$", "")); + Path sanitizedPath = Paths.get(path.trim().replaceAll("/$", "")); Path newPath; try { - newPath = Paths.get(p.getParent().toString(), objectIdPrefix + p.getFileName().toString()); + newPath = Paths.get(sanitizedPath.getParent().toString(), + objectIdPrefix + sanitizedPath.getFileName().toString()); } catch (NullPointerException e) { - newPath = Paths.get(objectIdPrefix + p.getFileName().toString()); + newPath = Paths.get(objectIdPrefix + sanitizedPath.getFileName().toString()); } try { log.debug("path is {}", newPath); @@ -187,12 +217,13 @@ public CdmiObject getCdmiObjectByPath(String path) { String objectType = json.optString("objectType"); if (objectType != null) { - if (objectType.equals(MediaTypes.CONTAINER)) + if (objectType.equals(MediaTypes.CONTAINER)) { return new Container(json); - else if (objectType.equals(MediaTypes.DATA_OBJECT)) + } else if (objectType.equals(MediaTypes.DATA_OBJECT)) { return new DataObject(json); - else if (objectType.equals(MediaTypes.ACCOUNT)) + } else if (objectType.equals(MediaTypes.ACCOUNT)) { return new Domain(json); + } } object = new CdmiObject(json); log.debug("get objectId from file {}", object.toString()); @@ -215,10 +246,11 @@ public CdmiObject getCdmiObject(String objectId) { String objectType = json.optString("objectType"); if (objectType != null) { - if (objectType.equals(MediaTypes.CONTAINER)) + if (objectType.equals(MediaTypes.CONTAINER)) { return new Container(json); - else if (objectType.equals(MediaTypes.DATA_OBJECT)) + } else if (objectType.equals(MediaTypes.DATA_OBJECT)) { return new DataObject(json); + } } object = new CdmiObject(json); log.debug("get objectId from file {}", object.toString()); diff --git a/src/main/java/org/snia/cdmiserver/dao/filesystem/ContainerDaoImpl.java b/src/main/java/org/snia/cdmiserver/dao/filesystem/ContainerDaoImpl.java index 161e9b6..e0525b7 100644 --- a/src/main/java/org/snia/cdmiserver/dao/filesystem/ContainerDaoImpl.java +++ b/src/main/java/org/snia/cdmiserver/dao/filesystem/ContainerDaoImpl.java @@ -92,6 +92,11 @@ public class ContainerDaoImpl implements ContainerDao { @Autowired private DomainDaoImpl domainDaoImpl; + /** + * Creates the root container for CDMI containers and data objects. + * + * @return the {@link CdmiObject} for the root container + */ public CdmiObject createRootContainer() { LOG.debug("create RootContainer {}", baseDirectoryName.trim()); @@ -125,9 +130,9 @@ public CdmiObject createRootContainer() { cdmiObjectDaoImpl.createCdmiObject(container); - if (cdmiObjectDaoImpl.createCdmiObject(container, directory.toString()) == null) + if (cdmiObjectDaoImpl.createCdmiObject(container, directory.toString()) == null) { cdmiObjectDaoImpl.updateCdmiObject(container, directory.toString()); - + } return container; } } @@ -144,6 +149,11 @@ public CdmiObject createRootContainer() { } + /** + * Creates the root container for CDMI object id meta-data files. + * + * @return the {@link Path} of the object id container + */ public Path createRootIdContainer() { try { @@ -167,8 +177,9 @@ public CdmiObject createByPath(String path, Container containerRequest) { } else if (containerRequest.getMove() != null) { return move(containerRequest, containerRequest.getMove(), path); } else { - if (path.contains("?")) + if (path.contains("?")) { path = path.split(Pattern.quote("?"))[0]; + } Container container = (Container) cdmiObjectDaoImpl.createCdmiObject(new Container()); if (container != null) { @@ -189,20 +200,22 @@ public CdmiObject createByPath(String path, Container containerRequest) { container.setCapabilitiesURI(capabilitiesUri + "/container/default"); if (containerRequest.getDomainURI() != null) { String domain = containerRequest.getDomainURI(); - if (domainDaoImpl.findByPath(domain) != null) + if (domainDaoImpl.findByPath(domain) != null) { container.setDomainURI(domain); - else + } else { throw new BadRequestException("The specified domainURI doesn't exist"); - } else + } + } else { container.setDomainURI(((Container) parentObject).getDomainURI()); + } container.setMetadata(containerRequest.getMetadata()); container.setCompletionStatus("Complete"); cdmiObjectDaoImpl.updateCdmiObject(container); - if (cdmiObjectDaoImpl.createCdmiObject(container, directory.toString()) == null) + if (cdmiObjectDaoImpl.createCdmiObject(container, directory.toString()) == null) { cdmiObjectDaoImpl.updateCdmiObject(container, directory.toString()); - + } addChild(containerPath.getFileName().toString(), containerPath.getParent().toString()); return container; @@ -308,8 +321,9 @@ private void removeChild(String childname, String parentPath) { private void addChild(String childname, String parentPath) { Container parentContainer = (Container) cdmiObjectDaoImpl.getCdmiObjectByPath(parentPath); List children = parentContainer.getChildren(); - if (children == null) + if (children == null) { children = new ArrayList(); + } children.add(childname); parentContainer.setChildren(children); parentContainer.setChildrenrange("0-" + String.valueOf(children.size() - 1)); @@ -319,8 +333,8 @@ private void addChild(String childname, String parentPath) { /** - * copies a Container with all or without any subcontainers to a new created or existing container - * at the specified path + * Copies a Container with all or without any subcontainers to a new created or existing container + * at the specified path. * * @param containerRequest the {@link Container} * @param path the {@link String} @@ -330,9 +344,10 @@ private CdmiObject copy(Container containerRequest, String path) { // getting requested Fields String[] requestedFields = null; String sourcePath = containerRequest.getCopy().trim(); - if (path.contains("?") && sourcePath.contains("?")) + if (path.contains("?") && sourcePath.contains("?")) { throw new BadRequestException( - "The destination container object URI and the copy source object URI both specify fields"); + "The destination container object URI and the copy source object URI specify fields"); + } if (sourcePath.contains("?")) { requestedFields = sourcePath.split(Pattern.quote("?"))[1].split(";"); sourcePath = sourcePath.split(Pattern.quote("?"))[0]; @@ -381,8 +396,9 @@ private CdmiObject copy(Container containerRequest, String path) { container.setDomainURI(oldContainer.getDomainURI()); FileUtils.copyDirectory(source.toFile(), target.toFile()); cdmiObjectDaoImpl.updateCdmiObject(container); - if (cdmiObjectDaoImpl.createCdmiObject(container, target.toString()) == null) + if (cdmiObjectDaoImpl.createCdmiObject(container, target.toString()) == null) { cdmiObjectDaoImpl.updateCdmiObject(container, target.toString()); + } editCopiedIdsRecursivly(container, Paths.get(path)); return container; } else { @@ -393,9 +409,9 @@ private CdmiObject copy(Container containerRequest, String path) { container.setChildrenrange(""); } // copy children - if (copyChildren) + if (copyChildren) { FileUtils.copyDirectory(source.toFile(), target.toFile()); - + } Container parentObject = (Container) cdmiObjectDaoImpl.getCdmiObjectByPath(target.getParent().toString()); LOG.debug("parent object {}", parentObject.toString()); @@ -404,8 +420,9 @@ private CdmiObject copy(Container containerRequest, String path) { container.setParentURI(Paths.get(path).getParent().toString()); container.setParentID(parentObject.getObjectId()); container.setObjectType(MediaTypes.CONTAINER); - if (!update) + if (!update) { container.setCapabilitiesURI(oldContainer.getCapabilitiesURI()); + } if (requestedFields == null) { container.setDomainURI(parentObject.getDomainURI()); container.setMetadata(oldContainer.getMetadata()); @@ -427,11 +444,13 @@ private CdmiObject copy(Container containerRequest, String path) { if (field.startsWith("metadata:")) { String subfield = field.split(":")[1]; Map metadata = container.getMetadata(); - if (metadata == null) + if (metadata == null) { metadata = new HashMap(); + } Map oldMetadata = oldContainer.getMetadata(); - if (oldMetadata == null) + if (oldMetadata == null) { oldMetadata = new HashMap(); + } metadata.put(subfield, oldMetadata.get(subfield)); container.setMetadata(metadata); LOG.trace("setting metadata field"); @@ -439,18 +458,21 @@ private CdmiObject copy(Container containerRequest, String path) { } } } - if (containerRequest.getMetadata() != null && !containerRequest.getMetadata().isEmpty()) + if (containerRequest.getMetadata() != null && !containerRequest.getMetadata().isEmpty()) { container.setMetadata(containerRequest.getMetadata()); - if (containerRequest.getDomainURI() != null && !containerRequest.getDomainURI().isEmpty()) + } + if (containerRequest.getDomainURI() != null && !containerRequest.getDomainURI().isEmpty()) { container.setDomainURI(containerRequest.getDomainURI()); + } // update metadata-files cdmiObjectDaoImpl.updateCdmiObject(container); - if (cdmiObjectDaoImpl.createCdmiObject(container, target.toString()) == null) + if (cdmiObjectDaoImpl.createCdmiObject(container, target.toString()) == null) { cdmiObjectDaoImpl.updateCdmiObject(container, target.toString()); - + } // add child to parent - if (!update) + if (!update) { addChild(container.getObjectName(), target.getParent().toString()); + } // add children if (copyChildren) { List children = oldContainer.getChildren(); @@ -464,8 +486,9 @@ private CdmiObject copy(Container containerRequest, String path) { } try { // update ids and URIs of children - if (copyChildren) + if (copyChildren) { editCopiedIdsRecursivly((Container) findByPath(path), Paths.get(path)); + } } catch (Exception e) { e.printStackTrace(); FileUtils.deleteDirectory(target.toFile()); @@ -516,16 +539,18 @@ private void editCopiedIdsRecursivly(Container container, Path path) { cdmiObjectDaoImpl.updateCdmiObject(newContainer); if (cdmiObjectDaoImpl.createCdmiObject(newContainer, - Paths.get(baseDirectoryName, newpath.toString()).toString()) == null) + Paths.get(baseDirectoryName, newpath.toString()).toString()) == null) { cdmiObjectDaoImpl.updateCdmiObject(newContainer, Paths.get(baseDirectoryName, newpath.toString()).toString()); + } editCopiedIdsRecursivly(child, newpath); } } } } - } else + } else { LOG.trace("PATH {} has no children", path); + } } private void deleteRecursivly(Container container, Path path) { @@ -569,16 +594,17 @@ private Container move(Container containerRequest, String moveFrom, String moveT container.setParentID(parentObject.getObjectId()); container.setDomainURI(parentObject.getDomainURI()); - if (containerRequest.getMetadata() != null && !containerRequest.getMetadata().isEmpty()) + if (containerRequest.getMetadata() != null && !containerRequest.getMetadata().isEmpty()) { container.setMetadata(containerRequest.getMetadata()); - if (containerRequest.getDomainURI() != null && !containerRequest.getDomainURI().isEmpty()) + } + if (containerRequest.getDomainURI() != null && !containerRequest.getDomainURI().isEmpty()) { container.setDomainURI(containerRequest.getDomainURI()); - + } cdmiObjectDaoImpl.updateCdmiObject(container); - if (cdmiObjectDaoImpl.createCdmiObject(container, target.toString()) == null) + if (cdmiObjectDaoImpl.createCdmiObject(container, target.toString()) == null) { cdmiObjectDaoImpl.updateCdmiObject(container, target.toString()); - + } Container newContainer = (Container) findByPath(moveTo); if (newContainer != null) { cdmiObjectDaoImpl.deleteCdmiObjectByPath(source.toString()); diff --git a/src/main/java/org/snia/cdmiserver/dao/filesystem/DataObjectDaoImpl.java b/src/main/java/org/snia/cdmiserver/dao/filesystem/DataObjectDaoImpl.java index 6712249..513f743 100644 --- a/src/main/java/org/snia/cdmiserver/dao/filesystem/DataObjectDaoImpl.java +++ b/src/main/java/org/snia/cdmiserver/dao/filesystem/DataObjectDaoImpl.java @@ -91,8 +91,9 @@ public DataObject createByPath(String path, DataObject dataObjectRequest) { } else if (dataObjectRequest.getMove() != null) { return move(dataObjectRequest, dataObjectRequest.getMove(), path); } else { - if (path.contains("?")) + if (path.contains("?")) { path = path.split(Pattern.quote("?"))[0]; + } DataObject dataObject = (DataObject) cdmiObjectDaoImpl.createCdmiObject(new DataObject()); if (dataObject != null) { @@ -105,11 +106,11 @@ public DataObject createByPath(String path, DataObject dataObjectRequest) { DataObject copiedObject = findByPath(copyFrom); dataObject = createByPath(path, copiedObject); } else { - if (dataObjectRequest.getValue() == null) + if (dataObjectRequest.getValue() == null) { file = Files.createFile(objectPath); - else + } else { file = Files.write(objectPath, dataObjectRequest.getValue().getBytes()); - + } LOG.debug("created file {}", file.toString()); CdmiObject parentObject = @@ -123,12 +124,14 @@ public DataObject createByPath(String path, DataObject dataObjectRequest) { dataObject.setCapabilitiesURI(capabilitiesUri + "/dataobject/default"); if (dataObjectRequest.getDomainURI() != null) { String domain = dataObjectRequest.getDomainURI(); - if (domainDaoImpl.findByPath(domain) != null) + if (domainDaoImpl.findByPath(domain) != null) { dataObject.setDomainURI(domain); - else + } else { throw new BadRequestException("The specified domainURI doesn't exist"); - } else + } + } else { dataObject.setDomainURI(((Container) parentObject).getDomainURI()); + } dataObject.setMetadata(dataObjectRequest.getMetadata()); // optional @@ -139,9 +142,9 @@ public DataObject createByPath(String path, DataObject dataObjectRequest) { cdmiObjectDaoImpl.updateCdmiObject(dataObject); - if (cdmiObjectDaoImpl.createCdmiObject(dataObject, file.toString()) == null) + if (cdmiObjectDaoImpl.createCdmiObject(dataObject, file.toString()) == null) { cdmiObjectDaoImpl.updateCdmiObject(dataObject, file.toString()); - + } addChild(file.getFileName().toString(), objectPath.getParent().toString()); } return dataObject; @@ -171,13 +174,13 @@ public DataObject createByPath(String path, DataObject dataObjectRequest) { } @Override - public DataObject createNonCDMIByPath(String path, String contentType, DataObject dObj) + public DataObject createNonCcdmiByPath(String path, String contentType, DataObject dataObj) throws Exception { throw new UnsupportedOperationException("DataObjectDaoImpl.createNonCDMIByPath()"); } @Override - public DataObject createById(String objectId, DataObject dObj) { + public DataObject createById(String objectId, DataObject dataObj) { throw new UnsupportedOperationException("DataObjectDaoImpl.createById()"); } @@ -265,8 +268,9 @@ private void removeChild(String childname, String parentPath) { private void addChild(String childname, String parentPath) { Container parentContainer = (Container) cdmiObjectDaoImpl.getCdmiObjectByPath(parentPath); List children = parentContainer.getChildren(); - if (children == null) + if (children == null) { children = new ArrayList(); + } children.add(childname); parentContainer.setChildren(children); parentContainer.setChildrenrange("0-" + String.valueOf(children.size() - 1)); @@ -291,16 +295,18 @@ private DataObject move(DataObject dataobjectRequest, String moveFrom, String mo dataObject.setParentID(parentObject.getObjectId()); dataObject.setDomainURI(parentObject.getDomainURI()); - if (dataobjectRequest.getMetadata() != null && !dataobjectRequest.getMetadata().isEmpty()) + if (dataobjectRequest.getMetadata() != null && !dataobjectRequest.getMetadata().isEmpty()) { dataObject.setMetadata(dataobjectRequest.getMetadata()); - if (dataobjectRequest.getDomainURI() != null && !dataobjectRequest.getDomainURI().isEmpty()) + } + if (dataobjectRequest.getDomainURI() != null + && !dataobjectRequest.getDomainURI().isEmpty()) { dataObject.setDomainURI(dataobjectRequest.getDomainURI()); - + } cdmiObjectDaoImpl.updateCdmiObject(dataObject); - if (cdmiObjectDaoImpl.createCdmiObject(dataObject, target.toString()) == null) + if (cdmiObjectDaoImpl.createCdmiObject(dataObject, target.toString()) == null) { cdmiObjectDaoImpl.updateCdmiObject(dataObject, target.toString()); - + } DataObject newDataObject = (DataObject) findByPath(moveTo); if (newDataObject != null) { cdmiObjectDaoImpl.deleteCdmiObjectByPath(source.toString()); @@ -328,9 +334,10 @@ private CdmiObject copy(DataObject dataobjectRequest, String path) { // getting requested Fields String[] requestedFields = null; String sourcePath = dataobjectRequest.getCopy().trim(); - if (path.contains("?") && sourcePath.contains("?")) + if (path.contains("?") && sourcePath.contains("?")) { throw new BadRequestException( - "The destination dataObject URI and the copy source object URI both specify fields"); + "The destination dataObject URI and the copy source object URI specify fields"); + } if (sourcePath.contains("?")) { requestedFields = sourcePath.split(Pattern.quote("?"))[1].split(";"); sourcePath = sourcePath.split(Pattern.quote("?"))[0]; @@ -355,9 +362,6 @@ private CdmiObject copy(DataObject dataobjectRequest, String path) { update = false; } - Container parentObject = - (Container) cdmiObjectDaoImpl.getCdmiObjectByPath(target.getParent().toString()); - if (requestedFields == null) { Files.copy(source, target, StandardCopyOption.REPLACE_EXISTING); object.setDomainURI(sourceObject.getDomainURI()); @@ -385,11 +389,13 @@ private CdmiObject copy(DataObject dataobjectRequest, String path) { if (field.startsWith("metadata:")) { String subfield = field.split(":")[1]; Map metadata = object.getMetadata(); - if (metadata == null) + if (metadata == null) { metadata = new HashMap(); + } Map oldMetadata = sourceObject.getMetadata(); - if (oldMetadata == null) + if (oldMetadata == null) { oldMetadata = new HashMap(); + } metadata.put(subfield, oldMetadata.get(subfield)); object.setMetadata(metadata); } @@ -397,6 +403,10 @@ private CdmiObject copy(DataObject dataobjectRequest, String path) { } } + + Container parentObject = + (Container) cdmiObjectDaoImpl.getCdmiObjectByPath(target.getParent().toString()); + object.setCapabilitiesURI(sourceObject.getCapabilitiesURI()); object.setCompletionStatus(sourceObject.getCompletionStatus()); object.setObjectName(target.getFileName().toString()); @@ -404,25 +414,27 @@ private CdmiObject copy(DataObject dataobjectRequest, String path) { object.setParentID(parentObject.getObjectID()); object.setObjectType(MediaTypes.DATA_OBJECT); - if (!Files.exists(target)) - Files.write(target, "".getBytes(), StandardOpenOption.CREATE_NEW); - - if (dataobjectRequest.getMetadata() != null && !dataobjectRequest.getMetadata().isEmpty()) + if (!Files.exists(target)) { + Files.write(target, "".getBytes(), StandardOpenOption.CREATE_NEW); + } + if (dataobjectRequest.getMetadata() != null && !dataobjectRequest.getMetadata().isEmpty()) { object.setMetadata(dataobjectRequest.getMetadata()); - if (dataobjectRequest.getDomainURI() != null && !dataobjectRequest.getDomainURI().isEmpty()) + } + if (dataobjectRequest.getDomainURI() != null && !dataobjectRequest.getDomainURI().isEmpty()) { object.setDomainURI(dataobjectRequest.getDomainURI()); - if (dataobjectRequest.getMimetype() != null && !dataobjectRequest.getMimetype().isEmpty()) + } + if (dataobjectRequest.getMimetype() != null && !dataobjectRequest.getMimetype().isEmpty()) { object.setMimetype(dataobjectRequest.getMimetype()); - + } // update metadata-files cdmiObjectDaoImpl.updateCdmiObject(object); - if (cdmiObjectDaoImpl.createCdmiObject(object, target.toString()) == null) + if (cdmiObjectDaoImpl.createCdmiObject(object, target.toString()) == null) { cdmiObjectDaoImpl.updateCdmiObject(object, target.toString()); - + } // add child to parent - if (!update) + if (!update) { addChild(object.getObjectName(), target.getParent().toString()); - + } return findByPath(path); } catch (ClassCastException e) { e.printStackTrace(); diff --git a/src/main/java/org/snia/cdmiserver/resource/PathResource.java b/src/main/java/org/snia/cdmiserver/resource/PathResource.java index fb63445..615ee5e 100644 --- a/src/main/java/org/snia/cdmiserver/resource/PathResource.java +++ b/src/main/java/org/snia/cdmiserver/resource/PathResource.java @@ -446,7 +446,7 @@ public Response putDataObject(@PathParam("path") String path, @HeaderParam("Cont dObj.setValue(new String(bytes)); } LOG.trace("Calling createNonCDMIByPath"); - dObj = dataObjectDao.createNonCDMIByPath(path, contentType, dObj); + dObj = dataObjectDao.createNonCcdmiByPath(path, contentType, dObj); // return representation // String respStr = dObj.toJson(); // return Response.ok(respStr).header(