<commit_before>package de.zib.gndms.dspace.slice.service.globus.resource;

import org.globus.wsrf.InvalidResourceKeyException;
import org.globus.wsrf.NoSuchResourceException;
import org.globus.wsrf.ResourceException;
import org.globus.wsrf.ResourceKey;
import org.jetbrains.annotations.NotNull;
import org.apache.axis.types.URI;
import de.zib.gndms.model.dspace.Slice;
import de.zib.gndms.infra.wsrf.ReloadablePersistentResource;
import de.zib.gndms.infra.model.GridEntityModelHandler;
import de.zib.gndms.infra.model.GridResourceModelHandler;
import de.zib.gndms.dspace.common.DSpaceTools;

import java.rmi.RemoteException;


/** 
 * The implementation of this SliceResource type.
 * 
 * @created by Introduce Toolkit version 1.2
 * 
 */
public class SliceResource extends SliceResourceBase
        implements ReloadablePersistentResource<Slice, ExtSliceResourceHome> {


    private ExtSliceResourceHome resourceHome;
    private GridEntityModelHandler<Slice, ExtSliceResourceHome, SliceResource> mH;

    @NotNull
    public Slice loadModelById( @NotNull String id ) throws ResourceException {
        return mH.loadModelById( null, id );
    }

    public void loadViaModelId( @NotNull String id ) throws ResourceException {
        loadFromModel(loadModelById( id ) );
    }

    public void loadFromModel( @NotNull Slice model ) throws ResourceException {

        // todo uncomment after xsd change of slice kind uri
   //     super.setSliceKind( model.getKind( ).getURI( ) );

        try {
            super.setSliceLocation( new URI( model.getOwner().getMetaSubspace().getScopedName().getNameScope() ) );
        } catch ( URI.MalformedURIException e ) {
            throw new ResourceException( "Following exception occured: " + e.getMessage( ) );
        }

        super.setTerminationTime( model.getTerminationTime() );
        super.setTotalStorageSize( DSpaceTools.buildSizeT( model.getTotalStorageSize( ) ) );
    }

    @NotNull
    public ExtSliceResourceHome getResourceHome() {
        if( resourceHome == null )
            throw new IllegalStateException( "now slice resource home set" );
        return resourceHome;
    }

    public void setResourceHome( @NotNull ExtSliceResourceHome resourceHomeParam ) {
        if (resourceHome == null) {
			mH = new GridResourceModelHandler<Slice, ExtSliceResourceHome, SliceResource>
				  (Slice.class, resourceHomeParam);
			resourceHome = resourceHomeParam;
		}
		else
			throw new IllegalStateException("resourceHome already set");
    }

    public void load( ResourceKey resourceKey ) throws ResourceException, NoSuchResourceException, InvalidResourceKeyException {
        //To change body of implemented methods use File | Settings | File Templates.
    }

    public void store() throws ResourceException {
        //To change body of implemented methods use File | Settings | File Templates.
    }

    public String getID( ) {
        return (String) getID( );
    }

}
<commit_msg>pre co<commit_after>package de.zib.gndms.dspace.slice.service.globus.resource;

import org.globus.wsrf.InvalidResourceKeyException;
import org.globus.wsrf.NoSuchResourceException;
import org.globus.wsrf.ResourceException;
import org.globus.wsrf.ResourceKey;
import org.jetbrains.annotations.NotNull;
import org.apache.axis.types.URI;
import de.zib.gndms.model.dspace.Slice;
import de.zib.gndms.model.dspace.Subspace;
import de.zib.gndms.infra.wsrf.ReloadablePersistentResource;
import de.zib.gndms.infra.model.GridEntityModelHandler;
import de.zib.gndms.infra.model.GridResourceModelHandler;
import de.zib.gndms.infra.system.GNDMSystem;
import de.zib.gndms.dspace.common.DSpaceTools;
import de.zib.gndms.dspace.subspace.service.globus.resource.ExtSubspaceResourceHome;
import de.zib.gndms.dspace.subspace.stubs.types.SubspaceReference;

import java.rmi.RemoteException;


/** 
 * The implementation of this SliceResource type.
 * 
 * @created by Introduce Toolkit version 1.2
 * 
 */
public class SliceResource extends SliceResourceBase
        implements ReloadablePersistentResource<Slice, ExtSliceResourceHome> {


    private ExtSliceResourceHome resourceHome;
    private GridEntityModelHandler<Slice, ExtSliceResourceHome, SliceResource> mH;


    // override generated setter method to pass changes on the resource directly to the model
    public void setTotalStorageSize(types.StorageSizeT totalStorageSize ) throws ResourceException {
        Slice sl = loadModelById( getID( ) );
        sl.setTotalStorageSize( DSpaceTools.buildSize( totalStorageSize ) );
        mH.mergeModel( null, sl );
    }

    public void setSliceKind(javax.xml.namespace.QName sliceKind ) throws ResourceException {
    }

    public void setSliceLocation(org.apache.axis.types.URI sliceLocation ) throws ResourceException {
    }

    public void setSubspaceReference(de.zib.gndms.dspace.subspace.stubs.types.SubspaceReference subspaceReference ) throws ResourceException {
    }

    @NotNull
    public Slice loadModelById( @NotNull String id ) throws ResourceException {
        return mH.loadModelById( null, id );
    }

    public void loadViaModelId( @NotNull String id ) throws ResourceException {
        loadFromModel(loadModelById( id ) );
    }

    public void loadFromModel( @NotNull Slice model ) throws ResourceException {

        // todo uncomment after xsd change of slice kind uri
   //     super.setSliceKind( model.getKind( ).getURI( ) );

        try {
            super.setSliceLocation( new URI( model.getOwner().getMetaSubspace().getScopedName().getNameScope() ) );
        } catch ( URI.MalformedURIException e ) {
            throw new ResourceException( "Following exception occured: " + e.getMessage( ) );
        }

        super.setTerminationTime( model.getTerminationTime() );
        super.setTotalStorageSize( DSpaceTools.buildSizeT( model.getTotalStorageSize( ) ) );

        GNDMSystem sys = resourceHome.getSystem( );
        ExtSubspaceResourceHome srh = (ExtSubspaceResourceHome) sys.getHome( Subspace.class );
        SubspaceReference subref;
        try {
            subref = srh.getReferenceForSubspace( model.getOwner( ) );
            super.setSubspaceReference( subref );
        } catch ( Exception e ) {
            throw new ResourceException( "Can't obtain reference for subspace: " + e.getMessage( ) );
        }
    }

    @NotNull
    public ExtSliceResourceHome getResourceHome() {
        if( resourceHome == null )
            throw new IllegalStateException( "now slice resource home set" );
        return resourceHome;
    }

    public void setResourceHome( @NotNull ExtSliceResourceHome resourceHomeParam ) {
        if (resourceHome == null) {
			mH = new GridResourceModelHandler<Slice, ExtSliceResourceHome, SliceResource>
				  (Slice.class, resourceHomeParam);
			resourceHome = resourceHomeParam;
		}
		else
			throw new IllegalStateException("resourceHome already set");
    }

    public void load( ResourceKey resourceKey ) throws ResourceException, NoSuchResourceException, InvalidResourceKeyException {
        //To change body of implemented methods use File | Settings | File Templates.
    }

    public void store() throws ResourceException {
        //To change body of implemented methods use File | Settings | File Templates.
    }

    public String getID( ) {
        return (String) getID( );
    }

}

{'fraction_non_alphanumeric': 0.08657123381049761, 'fraction_numerical': 0.0005453306066803, 'mean_word_length': 3.5821361648969394, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 1}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1923349', 'n_tokens_mistral': 2105, 'n_tokens_neox': 2027, 'n_words': 485}