package ext.publishing;
/*
1. Placera under
D:\ptc\Windchill\src\ext\publishing\CustomScheduleJobs.java
2. Kompilera med (eller motsvarande)
C:\j2sdk1_4\bin\javac -d d:\ptc\windchill\codebase D:\ptc\Windchill\src\ext\publishing\CustomScheduleJobs.java

3. Lägg in i site.xconf
<Property name="schedulejobs19" overridable="true" targetFile="codebase/wvs.properties" value="removeAllDefaultDerivedImages"/>
<Property name="removeAllDefaultDerivedImages.class" overridable="true" targetFile="codebase/wvs.properties" value="ext.publishing.CustomScheduleJobs"/>
<Property name="removeAllDefaultDerivedImages.description" overridable="true" targetFile="codebase/wvs.properties" value="removeAllDefaultDerivedImages"/>
<Property name="removeAllDefaultDerivedImages.method" overridable="true" targetFile="codebase/wvs.properties" value="removeAllDefaultDerivedImages"/>
<Property name="removeAllDefaultDerivedImages.enableOnContainers" overridable="true" targetFile="codebase/wvs.properties" value="false"/>

4. Propagera site.xconf
5. Starta PDMLink
6. Skapa schedule job under site-fliken
*/

import com.ptc.wvs.server.util.PublishUtils;
import wt.viewmarkup.DerivedImage;

import wt.fc.Persistable;
import wt.fc.PersistenceHelper;
import wt.fc.PersistenceServerHelper;
import wt.fc.QueryResult;
import wt.fc.ObjectVector;
import wt.fc.ObjectVectorIfc;
import wt.vc.VersionControlHelper;
import wt.query.QuerySpec;
import wt.query.SearchCondition;
import wt.epm.*;
import wt.epm.EPMDocument;
import wt.epm.EPMAuthoringAppType;
import wt.representation.Representation;
import wt.inf.container.*;
import wt.vc.config.ConfigHelper;
import wt.vc.config.LifeCycleConfigSpec;
import wt.lifecycle.State;
import wt.epm.EPMDocConfigSpec;


    
 public class CustomScheduleJobs
{   

   
   

    //Used to remove all viewables
   public static QueryResult removeAllDefaultDerivedImages()
    {
        Object obj = null;
        QueryResult queryresult = null;
        try
        {
            QuerySpec queryspec = new QuerySpec(wt.viewmarkup.DerivedImage.class);
            SearchCondition searchcondition = new SearchCondition(wt.viewmarkup.DerivedImage.class, "defaultRepresentation", "TRUE");
            SearchCondition searchcondition1 = new SearchCondition(wt.viewmarkup.DerivedImage.class, "derivedFromReference.key.id", "<>", 0L);
            queryspec.appendWhere(searchcondition);
            queryspec.appendAnd();
            queryspec.appendWhere(searchcondition1);
            queryresult = PersistenceHelper.manager.find(queryspec);
            
                ObjectVector objectvector = new ObjectVector();
                do
                {
                    if(!queryresult.hasMoreElements())
                        break;
                    DerivedImage derivedimage = (DerivedImage)queryresult.nextElement();
                    //wt.representation.Representable representable = RepresentationHelper.service.getRepresentable(derivedimage);
                    //com.ptc.wvs.server.ui.RepHelper.deleteRepresentation(derivedimage);
		     wt.viewmarkup.ViewMarkUpHelper.service.deleteDerivedImage(derivedimage,true);
                    //objectvector.addElement(derivedimage);
                  
                } while(true);
                queryresult = new QueryResult(objectvector);
            
        }
        catch(Exception exception)
        {
            exception.printStackTrace();
        }
        return queryresult;
    }
   
   
    
  }
  