Opened 10 years ago

Closed 9 years ago

#914 closed defect (fixed)

Refactor petascope ExceptionCodes into Exceptions for WCS-T

Reported by: Vlad Merticariu Owned by: Bang Pham Huu
Priority: major Milestone: 9.2
Component: petascope Version: development
Keywords: Cc: Dimitar Misev
Complexity: Medium

Description

The exceptions thrown by WCS-T insert are using dedicated ExceptionCodes and the general WCSException.

The ones thrown in the update operations are separate classes, sucblassed from WCSTException. This allows catching them by type (instead of catching all WCSExceptions and then do a type check), as well as easy customization and parameterization of the exception messages.

The task is to go through the WCST* ExceptionCodes, and create, for each of them, a subclass of WCSTException, following the model used, for example, in the UpdateCoverageHandler.

Attachments (1)

src_2015_02_10.tar.gz (1.3 MB ) - added by Bang Pham Huu 9 years ago.
Add new subclass of WCST Exception and changed in all Project

Download all attachments as: .zip

Change History (15)

comment:1 by Dimitar Misev, 9 years ago

Milestone: 9.2

comment:2 by Vlad Merticariu, 9 years ago

Owner: changed from Vlad Merticariu to Bang Pham Huu
Status: newassigned

comment:3 by Bang Pham Huu, 9 years ago

Cc: Dimitar Misev added

comment:4 by Bang Pham Huu, 9 years ago

Hi Vlad,

Thanks for your guiding. Now, I've ready to go with this task (but it is not easy start from the time I open Petascope Project with NetBean 8.0.2). Did I do wrong? Because I need to fix some problem then it could compiled.

  1. missing the package "petascope.org and petascope.rasj", copy from "/home/rasdaman/java/src/" to "$RMANHOME/applications/petascope/src/main/java/"
  1. Could not find the package when import "com.google.protobuf.*" then download the ".jar" file http://mvnrepository.com/artifact/com.google.protobuf/protobuf-java/2.6.1 and import to 'Jar library'.
  1. Error with or.gzeromq.ZMQ; Download the ".jar" file http://mvnrepository.com/artifact/org.zeromq/jzmq/3.1.0 and import to 'Jar library'.
  1. Interestingly I could not see the 'Interface of Petascope' (HTML in iframe), I deployed using GlassFish with NetBean. The error is
HTTP Status 404 - Not Found

type Status report

messageNot Found

descriptionThe requested resource is not available.

Please note that this is not because the 'path' to 'servlet' is not existed. In fact, it is true path because when I debug, it jump to the class 'PetascopeInterface.java' and method 'init()' as I expected.

However, it ended with jump to

"  Subject.java" in javax.security.auth;

        return java.security.AccessController.doPrivileged
                                        (action,
                                        createContext(subject, currentAcc));

and I stucked in there without how to fix this, to show the Interface instead of 404 error.

But if I tried with some WCS query (no need Inteface) http://localhost:46899/petascope/ows?service=WCS&version=2.0.1&request=GetCapabilities it still returns the result.

Tomorrow, I will try to make a sample as you recommended with some WCS-T exception first, and because you are busy so I will need Alex's help.

Thanks,

comment:5 by Bang Pham Huu, 9 years ago

Ok, Vlad, I think I could get your idea (well, you wrote a very concise in the ticket description but your instruction with me is clear).

Here is my report:

  1. I've created all the subclass prefix WCST* in ExceptionCode.java and also the content inside, for example:
package petascope.exceptions.wcst;

import petascope.exceptions.ExceptionCode;

/**
 *
 * @author <a href="mailto:merticariu@rasdaman.com">Vlad Merticariu</a>
 */
public class WCSTAxisLabelMismatchException extends WCSTException {

    public WCSTAxisLabelMismatchException(String axisName) {
        super(ExceptionCode.InconsistentChange, EXCEPTION_TEXT.replace("$axisName", axisName));
    }

    private final static String EXCEPTION_TEXT = "Axis label $axisName from the input coverage was not found in the target coverage.";

}

  1. Now, I've to reread your task description many times, to find what do you mean in "UpdateCoverageHandler.java", so, I could think that you meant in here you used with Petascope Exception or WCS Exception in methods instead of throw "WCSTException"
throws PetascopeException

so you need to change if the method throw "ExceptionCode with WCSTException" then it should throws "WCSTException" not the general "PetascopeException or WCSException".
For example, this should be change to class "WCSTInvalidXML".

catch (ParsingException e) {
            Logger.getLogger(InsertCoverageHandler.class.getName()).log(Level.SEVERE, null, e);
            throw new PetascopeException(ExceptionCode.WCSTInvalidXML, e.getMessage());
        }

And if not throw "WCST ExceptionCode" then I don't need to change.

private void handleSubsetCoefficients(CoverageMetadata currentCoverageMetadata, List<DimensionSubset> subsets) throws PetascopeException {
        for (DimensionSubset subset : subsets) {
            //check if axis is irregular is irregular
            if (currentCoverageMetadata.getDomainByName(subset.getDimension()).isIrregular()) {
                //update coefficient corresponding to this slice
                DomainElement currentDom = currentCoverageMetadata.getDomainByName(subset.getDimension());
                int axisId;
                try {
                    axisId = meta.getGridAxisId(currentCoverageMetadata.getCoverageId(), currentDom.getOrder());
                } catch (SQLException e) {
                    e.printStackTrace();
                    '''throw new PetascopeException(ExceptionCode.InternalSqlError)''';
                }
                BigDecimal currentCoefficient = computeSubsetCoefficient(currentDom, subset);
                int coefficientOrder = computeCoefficientOrder(currentCoverageMetadata, currentDom, currentCoefficient, (DimensionSlice) subset);
                try {
                    meta.updateAxisCoefficient(axisId, currentCoefficient, coefficientOrder);
                } catch (SQLException e) {
                    e.printStackTrace();
                    throw new '''PetascopeException(ExceptionCode.InternalSqlError)''';
                }
            }
        }
    }

I hope I'm doing it right, although I should try to understand what is the purpose of these exception later. So, next I will basically, search all project and see which code uses 'WCST Exception Code' but using object 'Petascope or WCSException' I will change it with the suitable class of WCSTException (like WCSTInvalidXML).

by Bang Pham Huu, 9 years ago

Attachment: src_2015_02_10.tar.gz added

Add new subclass of WCST Exception and changed in all Project

comment:6 by Bang Pham Huu, 9 years ago

Today, I've fixed all of these exception with "return new WCSException or PetascopeException that has arguments is Exceptions.WCST*). Typically in the file GMLParserUtil.java now will throws WCST* subclass as Vlad's example.

Vlad or Alex when you have time, please download and have a look with the code I've changed.
+ New Classes add in src/main/java/petascope/exceptions/wcst.
+ All other exceptions relating to this ticket were changed.

http://rasdaman.org/attachment/ticket/914/src_2015_02_10.tar.gz

Thanks,

comment:7 by Peter Baumann, 9 years ago

What is the status here - is it complete, does it compile, are there sufficient test cases?

comment:8 by Alex Dumitru, 9 years ago

Please provide a patch instead of the whole tar archive as it is impossible to follow the changes this way.

comment:9 by Bang Pham Huu, 9 years ago

As you request, Alex, I've submitted a patch as Vlad has suggested latest ticket. Please have a look, thanks:

[PATCH] ticket:914 - Refactor petascope ExceptionCodes into Exceptions for WCS-T, not verified - wait Vlad, Alex confirm

comment:10 by Alex Dumitru, 9 years ago

Your changes to the WCST code seem correct, however the patch submitted has many other unrelated changes. Please learn how to properly use git, for example using these tutorials https://www.atlassian.com/git/tutorials/ https://try.github.io/levels/1/challenges/1

In this case you will want to revert your commit, then git add only the files that have a connection to the current ticket (wcst modifications) and then format the patch.

@Peter, please reject the current uploaded patch and wait for a new one.

comment:11 by Bang Pham Huu, 9 years ago

well, actually it is my bad when I think you could also need some jar files, also with some file I've modified but not related to this ticket.

Anyway, thanks for your time and I will have a look with tutorials. You're right when what I can do is I could know how to add file to commit (stag) (also know to reset to last commit or remove file from staged list - reset), and that is all.

I've submitted new patch, please check there are only related files.

comment:12 by Alex Dumitru, 9 years ago

Looks good from my perspective, nice work! Also, please note that the branch to which you submitted is not used anymore, all patches should go into the main branch in the patchmanager.

comment:13 by Bang Pham Huu, 9 years ago

Thanks to Vlad and Alex for your help, comments and time to review. I will close the ticket as it has been accepted.


comment:14 by Bang Pham Huu, 9 years ago

Resolution: fixed
Status: assignedclosed
Note: See TracTickets for help on using tickets.